Skip to content

Commit

Permalink
Integrate JTC switching demo to example_1 (#243)
Browse files Browse the repository at this point in the history
Co-authored-by: Dr. Denis <[email protected]>
  • Loading branch information
christophfroehlich and destogl committed Mar 8, 2023
1 parent 0f125be commit aad8d5e
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 271 deletions.
141 changes: 1 addition & 140 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ The robot is basically a box moving according to differential drive kinematics.
The example shows how to implement robot hardware with separate communication to each actuator.


##### Example 8
##### Example 8: Using transmissions
*RRBot* - or ''Revolute-Revolute Manipulator Robot'' - with an exposed transmission interface


Expand Down Expand Up @@ -268,142 +268,3 @@ Available launch file options:
### Example 1-Sim: "Industrial Robots with only one interface" (Gazebo simulation)

- **TBA**




## Controllers and moving hardware

To move the robot you should load and start controllers.
The `JointStateBroadcaster` is used to publish the joint states to ROS topics.
Direct joint commands are sent to this robot via the `ForwardCommandController` and `JointTrajectoryController`.
The sections below describe their usage.
Check the [Results](##result) section on how to ensure that things went well.

**NOTE**: Before doing any action with controllers check their state using command:
```
ros2 control list_controllers
```


### JointStateBroadcaster

Open another terminal and load, configure and start `joint_state_broadcaster`:
```
ros2 control set_controller_state joint_state_broadcaster start
```
Check if controller is loaded properly:
```
ros2 control list_controllers
```
You should get the response:
```
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
```

Now you should also see the *RRbot* represented correctly in `RViz`.


### Using ForwardCommandController

1. If you want to test hardware with `ForwardCommandController` first load a controller (not always needed):
```
ros2 control load_controller forward_position_controller
```
Check if the controller is loaded properly:
```
ros2 control list_controllers
```

2. Then configure it:
```
ros2 control set_controller_state forward_position_controller configure
```
Check if the controller is loaded properly:
```
ros2 control list_controllers
```
You should get the response:
```
forward_position_controller[forward_command_controller/ForwardCommandController] inactive
```

3. Now start the controller:
```
ros2 control switch_controllers --start forward_position_controller
```
Check if controllers are activated:
```
ros2 control list_controllers
```
You should get `active` in the response:
```
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
forward_position_controller[forward_command_controller/ForwardCommandController] active
```

4. Send a command to the controller, either:

a. Manually using ros2 cli interface:
```
ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data:
- 0.5
- 0.5"
```
B. Or you can start a demo node which sends two goals every 5 seconds in a loop:
```
ros2 launch ros2_control_demo_bringup test_forward_position_controller.launch.py
```
You can adjust the goals in [rrbot_forward_position_publisher.yaml](ros2_control_demo_bringup/config/rrbot_forward_position_publisher.yaml).

### Using JointTrajectoryController

1. If you want to test hardware with `JointTrajectoryController` first load and configure a controller (not always needed):
```
ros2 control load_controller position_trajectory_controller --set-state configure
```
Check if the controller is loaded and configured properly:
```
ros2 control list_controllers
```
You should get the response:
```
position_trajectory_controller[joint_trajectory_controller/JointTrajectoryController] inactive
```

2. Now start the controller (and stop other running contorller):
```
ros2 control switch_controllers --stop forward_position_controller --start position_trajectory_controller
```
Check if controllers are activated:
```
ros2 control list_controllers
```
You should get `active` in the response:
```
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
position_trajectory_controller[joint_trajectory_controller/JointTrajectoryController] active
```

3. Send a command to the controller using demo node which sends four goals every 6 seconds in a loop:
```
ros2 launch ros2_control_demo_bringup test_joint_trajectory_controller.launch.py
```
You can adjust the goals in [rrbot_joint_trajectory_publisher.yaml](ros2_control_demo_bringup/config/rrbot_joint_trajectory_publisher.yaml).

## Result

1. Independently from the controller you should see how the example's output changes.
Look for the following lines
```
[RRBotSystemPositionOnlyHardware]: Got state 0.0 for joint 0!
[RRBotSystemPositionOnlyHardware]: Got state 0.0 for joint 1!
```

2. If you echo the `/joint_states` or `/dynamic_joint_states` topics you should also get similar values.
```
ros2 topic echo /joint_states
ros2 topic echo /dynamic_joint_states
```

3. You should also see the *RRbot* moving in `RViz`.
110 changes: 0 additions & 110 deletions doc/index.rst

This file was deleted.

101 changes: 100 additions & 1 deletion example_1/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The *RRBot* URDF files can be found in the ``description/urdf`` folder.

.. code-block:: shell
ros2 topic pub /position_commands std_msgs/msg/Float64MultiArray "data:
ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data:
- 0.5
- 0.5"
Expand All @@ -87,6 +87,100 @@ The *RRBot* URDF files can be found in the ``description/urdf`` folder.
[RRBotSystemPositionOnlyHardware]: Got command 0.50000 for joint 0!
[RRBotSystemPositionOnlyHardware]: Got command 0.50000 for joint 1!
If you echo the ``/joint_states`` or ``/dynamic_joint_states`` topics you should now get similar values, namely the simulated states of the robot

.. code-block:: shell
ros2 topic echo /joint_states
ros2 topic echo /dynamic_joint_states
6. Let's switch to a different controller, the ``Joint Trajectory Controller``.
Load the controller manually by

.. code-block:: shell
ros2 control load_controller position_trajectory_controller
what should return ``Successfully loaded controller position_trajectory_controller``. Check the status

.. code-block:: shell
ros2 control list_controllers
what shows you that the controller is loaded but unconfigured.

.. code-block:: shell
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
forward_position_controller[forward_command_controller/ForwardCommandController] active
position_trajectory_controller[joint_trajectory_controller/JointTrajectoryController] unconfigured
Configure the controller by setting it ``inactive`` by

.. code-block:: shell
ros2 control set_controller_state position_trajectory_controller inactive
what should give ``Successfully configured position_trajectory_controller``.
Note that the parameters are already set in `rrbot_controllers.yaml <bringup/config/rrbot_controllers.yaml>`__
but the controller was not loaded from the `launch file rrbot.launch.py <bringup/launch/rrbot.launch.py>`__ before.

As an alternative, you can load the controller directly in ``inactive``-state by means of the option for ``load_controller``

.. code-block:: shell
ros2 control load_controller position_trajectory_controller --set-state inactive
You should get the result ``Successfully loaded controller position_trajectory_controller into state inactive``.

See if it loaded properly with

.. code-block:: shell
ros2 control list_controllers
what should now return

.. code-block:: shell
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
forward_position_controller[forward_command_controller/ForwardCommandController] active
position_trajectory_controller[joint_trajectory_controller/JointTrajectoryController] inactive
Note that the controller is loaded but still ``inactive``. Now you can switch the controller by

.. code-block:: shell
ros2 control set_controller_state forward_position_controller inactive
ros2 control set_controller_state position_trajectory_controller active
or simply via this one-line command

.. code-block:: shell
ros2 control switch_controllers --activate position_trajectory_controller --deactivate forward_position_controller
Again, check via

.. code-block:: shell
ros2 control list_controllers
what should now return

.. code-block:: shell
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
forward_position_controller[forward_command_controller/ForwardCommandController] inactive
position_trajectory_controller[joint_trajectory_controller/JointTrajectoryController] active
Send a command to the controller using demo node, which sends four goals every 6 seconds in a loop:

.. code-block:: shell
ros2 launch ros2_control_demo_example_1 test_joint_trajectory_controller.launch.py
You can adjust the goals in `rrbot_joint_trajectory_publisher <bringup/config/rrbot_joint_trajectory_publisher.yaml>`__.

Files used for this demos
#########################
Expand All @@ -99,6 +193,10 @@ Files used for this demos
+ ``ros2_control`` tag: `rrbot.ros2_control.xacro <description/ros2_control/rrbot.ros2_control.xacro>`__

- RViz configuration: `rrbot.rviz <description/rviz/rrbot.rviz>`__
- Test nodes goals configuration:

+ `rrbot_forward_position_publisher <bringup/config/rrbot_forward_position_publisher.yaml>`__
+ `rrbot_joint_trajectory_publisher <bringup/config/rrbot_joint_trajectory_publisher.yaml>`__

- Hardware interface plugin: `rrbot.cpp <hardware/rrbot.cpp>`__

Expand All @@ -107,3 +205,4 @@ Controllers from this demo
##########################
- ``Joint State Broadcaster`` (`ros2_controllers repository <https://github.com/ros-controls/ros2_controllers>`__): `doc <https://control.ros.org/master/doc/ros2_controllers/joint_state_broadcaster/doc/userdoc.html>`__
- ``Forward Command Controller`` (`ros2_controllers repository <https://github.com/ros-controls/ros2_controllers>`__): `doc <https://control.ros.org/master/doc/ros2_controllers/forward_command_controller/doc/userdoc.html>`__
- ``Joint Trajectory Controller`` (`ros2_controllers repository <https://github.com/ros-controls/ros2_controllers>`__): `doc <https://control.ros.org/master/doc/ros2_controllers/joint_trajectory_controller/doc/userdoc.html>`__
Loading

0 comments on commit aad8d5e

Please sign in to comment.