Command Interface —> send commands to the robot hardware

State interface —> receive information (read the current state of the hardware)

Resource manager —> can load hardware components(sensors and actuators)

Controller manager —> can load multiple controller(implement control logic)

image.png

ROS2 control library —> contains the definition of the controller manager and resource manager

ROS2 controller library —> contains definitions of some controllers

image.png

robot.urdf.xacro

<?xml version="1.0"?>
<robot xmlns:xacro="<http://www.ros.org/wiki/xacro>" name="4dof_robot">

<xacro:include filename="$(find robot_description)/urdf/robot_gazebo.xacro"/>
<xacro:include filename="$(find robot_description)/urdf/robot_control.xacro"/>

  <!-- World link at origin -->
  <link name="world"/>
  <joint name="world_to_link_1" type="revolute">
    <parent link="world"/>
    <child link="link_1"/>
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <axis xyz="0 1 0"/>
    <limit lower="-1.57" upper="1.57" effort="50" velocity="1.0"/>
  </joint>

  <!-- Link 1 -->
  <link name="link_1">
    <inertial>
      <mass value="1.0"/>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="0.02" ixy="0" ixz="0" iyy="0.02" iyz="0" izz="0.02"/>
    </inertial>
    <visual>
      <origin xyz="0.1 0 0" rpy="0 0 0"/>
      <geometry><box size="0.2 0.02 0.02"/></geometry>
      <material>
        <color rgba="0.8 0.8 0.8 1.0"/>
      </material>
    </visual>
    <collision>
      <origin xyz="0.1 0 0" rpy="0 0 0"/>
      <geometry><box size="0.2 0.02 0.02"/></geometry>
    </collision>
  </link>

  <joint name="link_1_to_link_2" type="revolute">
    <parent link="link_1"/>
    <child link="link_2"/>
    <origin xyz="0.2 0 0" rpy="0 0 0"/>
    <axis xyz="0 1 0"/>
    <limit lower="-1.57" upper="1.57" effort="50" velocity="1.0"/>
  </joint>

  <!-- Link 2 -->
  <link name="link_2">
    <inertial>
      <mass value="0.8"/>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="0.015" ixy="0" ixz="0" iyy="0.015" iyz="0" izz="0.015"/>
    </inertial>
    <visual>
      <origin xyz="0.1 0 0" rpy="0 0 0"/>
      <geometry><box size="0.2 0.02 0.02"/></geometry>
      <material>
        <color rgba="1.0 0.0 0.0 1.0"/>
      </material>
    </visual>
    <collision>
      <origin xyz="0.1 0 0" rpy="0 0 0"/>
      <geometry><box size="0.2 0.02 0.02"/></geometry>
    </collision>
  </link>

  <joint name="link_2_to_link_3" type="revolute">
    <parent link="link_2"/>
    <child link="link_3"/>
    <origin xyz="0.2 0 0" rpy="0 0 0"/>
    <axis xyz="0 1 0"/>
    <limit lower="-1.57" upper="1.57" effort="50" velocity="1.0"/>
  </joint>

  <!-- Link 3 -->
  <link name="link_3">
    <inertial>
      <mass value="0.6"/>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="0.01" ixy="0" ixz="0" iyy="0.01" iyz="0" izz="0.01"/>
    </inertial>
    <visual>
      <origin xyz="0.075 0 0" rpy="0 0 0"/>
      <geometry><box size="0.15 0.02 0.02"/></geometry>
      <material>
        <color rgba="0.0 0.0 1.0 1.0"/>
      </material>
    </visual>
    <collision>
      <origin xyz="0.075 0 0" rpy="0 0 0"/>
      <geometry><box size="0.15 0.02 0.02"/></geometry>
    </collision>
  </link>

  <joint name="link_3_to_link_4" type="revolute">
    <parent link="link_3"/>
    <child link="link_4"/>
    <origin xyz="0.15 0 0" rpy="0 0 0"/>
    <axis xyz="0 1 0"/>
    <limit lower="-1.57" upper="1.57" effort="50" velocity="1.0"/>
  </joint>

  <!-- Link 4 -->
  <link name="link_4">
    <inertial>
      <mass value="0.4"/>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="0.008" ixy="0" ixz="0" iyy="0.008" iyz="0" izz="0.008"/>
    </inertial>
    <visual>
      <origin xyz="0.075 0 0" rpy="0 0 0"/>
      <geometry><box size="0.15 0.02 0.02"/></geometry>
      <material>
        <color rgba="0.0 1.0 0.0 1.0"/>
      </material>
    </visual>
    <collision>
      <origin xyz="0.075 0 0" rpy="0 0 0"/>
      <geometry><box size="0.15 0.02 0.02"/></geometry>
    </collision>
  </link>

  <!-- Spherical end effector -->
  <link name="end_effector">
    <inertial>
      <mass value="0.2"/>
      <origin xyz="0.15 0 0" rpy="0 0 0"/>
      <inertia ixx="0.002" ixy="0" ixz="0" iyy="0.002" iyz="0" izz="0.002"/>
    </inertial>
    <visual>
      <origin xyz="0.15 0 0" rpy="0 0 0"/>
      <geometry><sphere radius="0.02"/></geometry>
      <material>
        <color rgba="0.75 0.75 0.75 1.0"/>
      </material>
    </visual>
    <collision>
      <origin xyz="0.15 0 0" rpy="0 0 0"/>
      <geometry><sphere radius="0.02"/></geometry>
    </collision>
  </link>

  <joint name="link_4_to_end_effector" type="fixed">
    <parent link="link_4"/>
    <child link="end_effector"/>
    <origin xyz="0 0 0" rpy="0 0 0"/>
  </joint>
</robot>

image.png

for control need to change the URDF of robot and add some tags

ros2 pkg list | grep -E 'gz_ros2_control|ign_ros2_control'
		gz_ros2_control
		gz_ros2_control_demos

ls /opt/ros/jazzy/lib | grep gz_ros2_control
		gz_ros2_control_demos
		libgz_ros2_control-system.so