|
| 1 | +Iron to Jazzy |
| 2 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 3 | + |
| 4 | +component parser |
| 5 | +***************** |
| 6 | +Changes from `(PR #1256) <https://github.com/ros-controls/ros2_control/pull/1256>`__ |
| 7 | + |
| 8 | +* All ``joints`` defined in the ``<ros2_control>``-tag have to be present in the URDF received :ref:`by the controller manager <doc/ros2_control/controller_manager/doc/userdoc:subscribers>`, otherwise a ``std::runtime_error`` is thrown. This is to ensure that the URDF and the ``<ros2_control>``-tag are consistent. E.g., for configuration ports use ``gpio`` tags instead. |
| 9 | +* The syntax for mimic joints is changed to the `official URDF specification <https://wiki.ros.org/urdf/XML/joint>`__. The parameters within the ``ros2_control`` tag are not supported any more. Instead of |
| 10 | + |
| 11 | + .. code-block:: xml |
| 12 | +
|
| 13 | + <ros2_control name="GazeboSystem" type="system"> |
| 14 | + <joint name="right_finger_joint"> |
| 15 | + <command_interface name="position"/> |
| 16 | + <state_interface name="position"> |
| 17 | + <param name="initial_value">0.15</param> |
| 18 | + </state_interface> |
| 19 | + <state_interface name="velocity"/> |
| 20 | + <state_interface name="effort"/> |
| 21 | + </joint> |
| 22 | + <joint name="left_finger_joint"> |
| 23 | + <param name="mimic">right_finger_joint</param> |
| 24 | + <param name="multiplier">1</param> |
| 25 | + <command_interface name="position"/> |
| 26 | + <state_interface name="position"/> |
| 27 | + <state_interface name="velocity"/> |
| 28 | + <state_interface name="effort"/> |
| 29 | + </joint> |
| 30 | + </ros2_control> |
| 31 | +
|
| 32 | + define your mimic joints directly in the joint definitions: |
| 33 | + |
| 34 | + .. code-block:: xml |
| 35 | +
|
| 36 | + <joint name="right_finger_joint" type="prismatic"> |
| 37 | + <axis xyz="0 1 0"/> |
| 38 | + <origin xyz="0.0 -0.48 1" rpy="0.0 0.0 0.0"/> |
| 39 | + <parent link="base"/> |
| 40 | + <child link="finger_right"/> |
| 41 | + <limit effort="1000.0" lower="0" upper="0.38" velocity="10"/> |
| 42 | + </joint> |
| 43 | + <joint name="left_finger_joint" type="prismatic"> |
| 44 | + <mimic joint="right_finger_joint" multiplier="1" offset="0"/> |
| 45 | + <axis xyz="0 1 0"/> |
| 46 | + <origin xyz="0.0 0.48 1" rpy="0.0 0.0 3.1415926535"/> |
| 47 | + <parent link="base"/> |
| 48 | + <child link="finger_left"/> |
| 49 | + <limit effort="1000.0" lower="0" upper="0.38" velocity="10"/> |
| 50 | + </joint> |
| 51 | +
|
| 52 | +Adaption of Command-/StateInterfaces |
| 53 | +*************************************** |
| 54 | +Changes from `(PR #1240) <https://github.com/ros-controls/ros2_control/pull/1240>`__ |
| 55 | + |
| 56 | +* ``Command-/StateInterfaces`` are now created and exported automatically by the framework via the ``on_export_command_interfaces()`` or ``on_export_state_interfaces()`` method based on the ``InterfaceDescription`` (check the hardware_info.hpp). |
| 57 | +* The memory for storing the value of a ``Command-/StateInterfaces`` is no longer allocated in the hardware but instead in the ``Command-/StateInterfaces`` itself. |
| 58 | +* To access the automatically created ``Command-/StateInterfaces`` we provide to ``std::unordered_map<std::string, InterfaceDescription>``. Where the string is the fully qualified name of the interface and the ``InterfaceDescription`` the configuration of the interface. The ``std::unordered_map<>`` are divided into ``type_state_interfaces_`` and ``type_command_interfaces_`` where type can be: ``joint``, ``sensor``, ``gpio`` and ``unlisted``. E.g. the ``CommandInterfaces`` for all joints can be found in the ``joint_command_interfaces_`` map. The ``unlisted`` includes all interfaces not listed in the .ros2_control.xacro but created by overriding the ``export_command_interfaces_2()`` or ``export_state_interfaces_2()`` function and creating some custom ``Command-/StateInterfaces``. |
| 59 | + |
| 60 | +Migration of Command-/StateInterfaces |
| 61 | +------------------------------------- |
| 62 | +To adapt to the new way of creating and exporting ``Command-/StateInterfaces`` follow those steps: |
| 63 | +1. Delete the ``std::vector<hardware_interface::CommandInterface> export_command_interfaces() override`` and ``std::vector<hardware_interface::StateInterface> export_state_interfaces() override``. |
| 64 | +2. Delete the allocated Memory for any ``Command-/StateInterfaces``: |
| 65 | +3. If you have a ``std::vector<double> hw_commands_;`` for joint ``CommandInterfaces`` delete it and any usage/appearance. Wherever you iterated over a state/command or accessed commands stated like this: |
| 66 | + |
| 67 | +.. code-block:: c++ |
| 68 | + |
| 69 | + // states |
| 70 | + for (uint i = 0; i < hw_states_.size(); i++) |
| 71 | + { |
| 72 | + hw_states_[i] = 0; |
| 73 | + auto some_state = hw_states_[i]; |
| 74 | + } |
| 75 | + |
| 76 | + // commands |
| 77 | + for (uint i = 0; i < hw_commands_.size(); i++) |
| 78 | + { |
| 79 | + hw_commands_[i] = 0; |
| 80 | + auto some_command = hw_commands_[i]; |
| 81 | + } |
| 82 | + |
| 83 | + // specific state/command |
| 84 | + hw_commands_[x] = hw_states_[y]; |
| 85 | + |
| 86 | +replace it with |
| 87 | + |
| 88 | +.. code-block:: c++ |
| 89 | + |
| 90 | + // states replace with this |
| 91 | + for (const auto & [name, descr] : joint_state_interfaces_) |
| 92 | + { |
| 93 | + set_state(name, 0.0); |
| 94 | + auto some_state = get_state(name); |
| 95 | + } |
| 96 | + |
| 97 | + //commands replace with this |
| 98 | + for (const auto & [name, descr] : joint_commands_interfaces_) |
| 99 | + { |
| 100 | + set_command(name, 0.0); |
| 101 | + auto some_command = get_command(name); |
| 102 | + } |
| 103 | + |
| 104 | + // replace specific state/command, for this you need to store the names which are std::strings |
| 105 | + // somewhere or know them. However be careful since the names are fully qualified names which |
| 106 | + // means that the prefix is included for the name: E.g.: prefix/joint_1/velocity |
| 107 | + set_command(name_of_command_interface_x, get_state(name_of_state_interface_y)); |
| 108 | + |
| 109 | +Migration of unlisted Command-/StateInterfaces not defined in .ros2_control.xacro |
| 110 | +--------------------------------------------------------------------------------- |
| 111 | +If you have some unlisted ``Command-/StateInterfaces`` not included in the .ros2_control.xacro you can follow those steps: |
| 112 | +1. Override the ``virtual std::vector<hardware_interface::InterfaceDescription> export_command_interfaces_2()`` or ``virtual std::vector<hardware_interface::InterfaceDescription> export_state_interfaces_2()`` |
| 113 | +2. Create the InterfaceDescription for each of the Interfaces you want to create in the override ``export_command_interfaces_2()`` or ``export_state_interfaces_2()`` function, add it to a vector and return the vector: |
| 114 | + |
| 115 | + .. code-block:: c++ |
| 116 | + |
| 117 | + std::vector<hardware_interface::InterfaceDescription> my_unlisted_interfaces; |
| 118 | + |
| 119 | + InterfaceInfo unlisted_interface; |
| 120 | + unlisted_interface.name = "some_unlisted_interface"; |
| 121 | + unlisted_interface.min = "-5.0"; |
| 122 | + unlisted_interface.data_type = "5.0"; |
| 123 | + unlisted_interface.data_type = "1.0"; |
| 124 | + unlisted_interface.data_type = "double"; |
| 125 | + my_unlisted_interfaces.push_back(InterfaceDescription(info_.name, unlisted_interface)); |
| 126 | + |
| 127 | + return my_unlisted_interfaces; |
| 128 | + |
| 129 | + 3. The unlisted interface will then be stored in either the ``unlisted_command_interfaces_`` or ``unlisted_state_interfaces_`` map depending in which function they are created. |
| 130 | + 4. You can access it like any other interface with the ``get_state(name)``, ``set_state(name, value)``, ``get_command(name)`` or ``set_command(name, value)``. E.g. ``get_state("some_unlisted_interface")``. |
| 131 | + |
| 132 | +Custom exportation of Command-/StateInterfaces |
| 133 | +---------------------------------------------- |
| 134 | +In case the default implementation (``on_export_command_interfaces()`` or ``on_export_state_interfaces()`` ) for exporting the ``Command-/StateInterfaces`` is not enough you can override them. You should however consider the following things: |
| 135 | +* If you want to have unlisted interfaces available you need to call the ``export_command_interfaces_2()`` or ``export_state_interfaces_2()`` and add them to the ``unlisted_command_interfaces_`` or ``unlisted_state_interfaces_``. |
| 136 | +* Don't forget to store the created ``Command-/StateInterfaces`` internally as you only return shared_ptrs and the resource manager will not provide access to the created ``Command-/StateInterfaces`` for the hardware. So you must take care of storing them yourself. |
| 137 | +* Names must be unique! |
0 commit comments