Skip to content

Commit 3d2e036

Browse files
author
Murilo Marinho
committed
[sas_robot_driver_myrobot] Fixed launch and added explanation for the sas_robot_driver subclass.
1 parent 1cce565 commit 3d2e036

File tree

3 files changed

+112
-10
lines changed

3 files changed

+112
-10
lines changed

docs/source/sas/sas_robot_driver_add_new_robot.rst

Lines changed: 110 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,20 @@ Package-related sources
5454
.. admonition:: In this step, we'll work on these.
5555

5656
.. code-block:: console
57-
:emphasize-lines: 2,6
57+
:emphasize-lines: 2,8
58+
59+
└── sas_robot_driver_myrobot
60+
├── CMakeLists.txt
61+
├── include
62+
│   └── sas_robot_driver_myrobot
63+
│   └── sas_robot_driver_myrobot.hpp
64+
├── launch
65+
│   └── real_robot_launch.py
66+
├── package.xml
67+
└── src
68+
├── sas_robot_driver_myrobot.cpp
69+
└── sas_robot_driver_myrobot_node.cpp
5870

59-
└── sas_robot_driver_myrobot
60-
├── CMakeLists.txt
61-
├── include
62-
│   └── sas_robot_driver_myrobot
63-
├── package.xml
64-
└── src
6571

6672
The files already exist, we just need to modify them as follows
6773

@@ -110,6 +116,102 @@ Create all relevant files
110116
mkdir -p launch
111117
touch launch/real_robot_launch.py
112118
113-
Contents of the header file
119+
The robot driver class
120+
----------------------
121+
122+
.. admonition:: In this step, we'll work on these.
123+
124+
.. code-block:: console
125+
:emphasize-lines: 5,10
126+
127+
└── sas_robot_driver_myrobot
128+
├── CMakeLists.txt
129+
├── include
130+
│   └── sas_robot_driver_myrobot
131+
│   └── sas_robot_driver_myrobot.hpp
132+
├── launch
133+
│   └── real_robot_launch.py
134+
├── package.xml
135+
└── src
136+
├── sas_robot_driver_myrobot.cpp
137+
└── sas_robot_driver_myrobot_node.cpp
138+
139+
The example class file has two important design choices to note.
140+
141+
First, we rely on the struct ``RobotDriverMyrobotConfiguration``
142+
to simplify interaction with the constructor. This reduces the amount of code that needs to be changed if a parameter is
143+
added or removed.
144+
145+
Second, we rely on the `PIMPL idiom <https://en.cppreference.com/w/cpp/language/pimpl>`_. This idiom is important to
146+
prevent driver internals to pollute the exported header. This is a very important step to guarantee that your users
147+
don't have to worry about source files specific to the robot and that your package is correctly self-contained.
148+
149+
.. tab-set::
150+
151+
.. tab-item:: sas_robot_driver_myrobot.hpp
152+
153+
:download:`sas_robot_driver_myrobot.hpp <../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/include/sas_robot_driver_myrobot/sas_robot_driver_myrobot.hpp>`
154+
155+
.. literalinclude:: ../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/include/sas_robot_driver_myrobot/sas_robot_driver_myrobot.hpp
156+
:language: cpp
157+
:linenos:
158+
:lines: 26-
159+
160+
.. tab-item:: sas_robot_driver_myrobot.cpp
161+
162+
:download:`sas_robot_driver_myrobot.cpp <../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/src/sas_robot_driver_myrobot.cpp`
163+
164+
.. literalinclude:: ../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/src/sas_robot_driver_myrobot.cpp
165+
:language: cpp
166+
:linenos:
167+
:lines: 25-
168+
169+
Contents of the launch file
114170
---------------------------
115171

172+
.. admonition:: In this step, we'll work on this.
173+
174+
.. code-block:: console
175+
:emphasize-lines: 7
176+
177+
└── sas_robot_driver_myrobot
178+
├── CMakeLists.txt
179+
├── include
180+
│   └── sas_robot_driver_myrobot
181+
│   └── sas_robot_driver_myrobot.hpp
182+
├── launch
183+
│   └── real_robot_launch.py
184+
├── package.xml
185+
└── src
186+
├── sas_robot_driver_myrobot.cpp
187+
└── sas_robot_driver_myrobot_node.cpp
188+
189+
Running the launch file
190+
-----------------------
191+
192+
.. code-block:: console
193+
194+
ros2 launch sas_robot_driver_myrobot real_robot_launch.py
195+
196+
In another terminal
197+
198+
.. code-block:: console
199+
200+
ros2 topic list
201+
202+
will show all the available topics that were created for you, freely. Notice that in none of the source files
203+
we created so far had any mention to topics or subscribers. All are created by :program:`sas`.
204+
205+
.. code-block:: console
206+
207+
/myrobot_1/get/home_states
208+
/myrobot_1/get/joint_positions_max
209+
/myrobot_1/get/joint_positions_min
210+
/myrobot_1/get/joint_states
211+
/myrobot_1/set/clear_positions
212+
/myrobot_1/set/homing_signal
213+
/myrobot_1/set/target_joint_forces
214+
/myrobot_1/set/target_joint_positions
215+
/myrobot_1/set/target_joint_velocities
216+
/parameter_events
217+
/rosout

sas_tutorial_workspace/src/sas_robot_driver_myrobot/launch/real_robot_launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def generate_launch_description():
1717
emulate_tty=True,
1818
package='sas_robot_driver_myrobot',
1919
executable='sas_robot_driver_myrobot_node',
20-
name='ur_1',
20+
name='myrobot_1',
2121
parameters=[{
2222
"ip": "127.0.0.1",
2323
"joint_limits_min": [-360.0, -360.0, -360.0, -360.0, -360.0, -720.0],

sas_tutorial_workspace/src/sas_robot_driver_myrobot/src/sas_robot_driver_myrobot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void RobotDriverMyrobot::connect()
117117

118118
//Usually after the connection is established we can read joint positions
119119
//but not all drivers work like this
120-
impl_->joint_positions_ << 0, 0, 0, 0, 0, 0;
120+
impl_->joint_positions_ = (VectorXd(6) << 0, 0, 0, 0, 0, 0).finished();
121121
}
122122

123123
/**

0 commit comments

Comments
 (0)