... | ... | @@ -571,17 +571,23 @@ You should see your robot undocking. |
|
|
|
|
|
## Implement abort/stop/pause/resume
|
|
|
|
|
|
You can use `std_srvs/Empty` to define a service call for `abort`, `stop`, `pause` and `resume`. Those service call need to be defined in your `tst_executor` node, along the `execute_tst` service call. You can call the function `abort`, `stop`, `pause` and `resume` of the `TstML.Executor.Executor`/`TstML::Executor::Executor` class.
|
|
|
You should create services for `abort`, `stop`, `pause` and `resume`. They should be created in a similar way as you created the `execute_tst` service server. We can use `std_srvs/Empty` as a service type for those services.
|
|
|
|
|
|
If you try to call with ```ros2 service call```, you will notice that the call is hanging, and the execution is not aborted, stoped, paused or resumed. This is because, by default, ROS is single threaded and can only handle one request. We need to use a ```MultiThreadedExecutor``` with a reentrant group.
|
|
|
For `abort`, `stop`, `pause` and `resume`, follow those steps:
|
|
|
|
|
|
* Create a callback function, i.e., a new function in your class with a unique name (for instance callback_abort), it should take a `request` and a `response` as argument
|
|
|
* In that callback function you can use `abort`, `stop`, `pause` and `resume` of the `TstML.Executor.Executor`/`TstML::Executor::Executor` class.
|
|
|
* In the constructor of your ROS Node, you can use the `create_service` function to create a new service. Use the `create_service` of `execute_tst` as an example.
|
|
|
|
|
|
You should to call your services with ```ros2 service call```, however you will notice that the call is hanging, and the execution is not aborted, stopped, paused or resumed. This is because, by default, ROS is single threaded and can only handle one request. We need to use a ```MultiThreadedExecutor``` with a reentrant group.
|
|
|
|
|
|
### Python
|
|
|
|
|
|
Modify your main function to look like this, instead of using `rclpy::spin(...)`:
|
|
|
Modify your main function to look like this, instead of using `rclpy::spin(some_node)`:
|
|
|
|
|
|
```python
|
|
|
executor = rclpy.executors.MultiThreadedExecutor()
|
|
|
executor.add_node(tst_executor_node)
|
|
|
executor.add_node(some_node)
|
|
|
executor.spin()
|
|
|
```
|
|
|
|
... | ... | @@ -602,7 +608,7 @@ Note that the ```execute_tst``` call is not reentrant, and should not be added t |
|
|
|
|
|
### C++
|
|
|
|
|
|
Modify your main function to look like this, instead of using `rclcpp::spin(...)`:
|
|
|
Modify your main function to look like this, instead of using `rclcpp::spin(some_node)`:
|
|
|
|
|
|
```c++
|
|
|
rclcpp::executors::MultiThreadedExecutor executor;
|
... | ... | |