.srv` to know the service file structure
#request
int8 a
int8 b
---
#response
int8 sum
---
## Service Server and Clients
- There can be only one service server for a service.
- Multiple server clients can use the same service server.
- Server decides how goals from multiple clients will be handled simultaneously.
---
## ROS 2 Actions
- Used for tasks that
- Longer execution time
- Requires preemption
- Requires regular feedback
- Example. Path planning in navigation
- Actions are implemented as a combination of services and topics
- Action interface has
- Goal: What action to achieve and how to.
- Feedback: Progress towards completing the action
- Preempt: To preempt the action that is being executed
- Result: Outcome of an action
---
## Actions Client and Server
- Action clients send goal and result requests to action servers
- Action servers execute goal and provide feedback and results to action clients
- Feedback uses topics whereas Goal and Result uses services.
---
## ROS 2 Actions
### Data structure for Actions
- Defined by a set of messages: Goal, Result and Feedback.
- ``\*.action` is a file with type and name with fields separated by `---`
# Define a goal of washing all dishes
bool heavy_duty # Spend extra time cleaning
---
# Define the result that will be published after the action execution ends.
uint32 total_dishes_cleaned
---
# Define a feedback message that will be published during action execution.
float32 percent_complete
uint32 number_dishes_cleaned
---
class: center
## Actions vs Services
| Actions |
Services |
| Intended for longer running tasks |
For tasks that terminated quickly |
| Preemptable |
Not preemptable |
| Consists of goal, result and feedback |
Consists of request and response |
| Provides steady feedback |
Provides a single response |
---
## ROS 2 Params
---
## ROS 2 Params - 1
- Used to externally configure the nodes at run-time and during run-time, without having to recompile the code for the node.
- These parameters can be dynamically reconfigured using ROS 2 services.
- **Note**: ROS 2 uses a decentralized parameter system.
def __init__(self):
super().__init__('test_params_rclpy')
self.declare_parameter('my_str')
self.declare_parameter('my_int')
param_str = self.get_parameter('my_str')
param_int = self.get_parameter('my_int')
self.get_logger().info("str: %s, int: %s" % (str(param_str.value), str(param_int.value)))
#### Setting the ROS 2 params in command line.
ros2 run ros2_tutorials test_params_rclpy --ros-args -p my_str:="Hello world" -p my_int:=5
---
## ROS 2 Params - 2
### YAML for ROS 2 params
- Managing parameters when number of params increases becomes complex.
- Adding them in command line is not an option
- **YAML** is more human readable and Great for loading a configuration file at run time
- Each parameter consists of a key and a value, where the key is a string
#### Package architecture
---
## ROS 2 Params - 3
### Loading YAML config to Node
def __init__(self):
super().__init__('your_amazing_node')
self.declare_parameters(
namespace='',
parameters=[
('bool_value', None),
('float_number', None),
('str_text', None)
])
#### From command line
ros2 run pkg_name node_name --ros-args --params-file .~/locate_pkg/config/params.yaml
---
## ROS 2 Params - 4
### From launch file
def generate_launch_description():
ld = LaunchDescription()
config = os.path.join(
get_package_share_directory('ros2_tutorials'),
'config',
'params.yaml'
)
node=Node(
package = 'ros2_tutorials',
name = 'Node_A',
executable = 'test_yaml_params',
parameters = [config]
)
ld.add_action(node)
return ld
---
## ROS 2 Params - 5
### For a Python package, in “setup.py”:
...
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name, 'launch'), glob('launch/*.launch.py')),
(os.path.join('share', package_name, 'config'), glob('config/*.yaml'))
],
...
[References for ROS 2 Params](https://docs.ros.org/en/jazzy/Concepts/Basic/About-Parameters.html)
---
### Why we need Launch files?
---
## Launch files
#### Launch files are used for:
- Describing the configuration of the system and execute as described
- Configuration of the system includes
- Which program to run
- Where to run them
- Which arguments to pass to them
- Loading of parameters
- Remapping topic names, parameters, etc.
---
## Creating Launch files
### Location of launch file
- ROS 2 Launch files are coded in python
- They are executed by ROS 2 CLI tool, `ros2 launch`
- Create a `launch` directory inside your package as given below
- Create a launch file with `.py`inside `launch` directory
---
## Creating Launch files
### Understanding launch files
---
## Referencing other launch files
---
## Launch files
### Using launch files
- Use `colcon build` and ``source workspace`` and then use ros2 CLI.
ros2 launch package_name launch_file_name
---
class: center, middle
# End of Presentation
### Questions ?
---