Skip to content

Commit 451426c

Browse files
author
Murilo Marinho
committed
[sas_robot_driver_myrobot] Added further explanation for the header and source for the driver.
1 parent 5683e30 commit 451426c

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

docs/source/sas/sas_robot_driver_add_new_robot.rst

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,28 @@ The files already exist, we just need to modify them as follows
9090
:linenos:
9191
:emphasize-lines: 10,16-132
9292

93+
In :file:`CMakeLists.txt` we have a sequence of four blocks. These are all directly related to ROS2 and although in
94+
this tutorial I define a best practice, this is not particular to ``sas``.
95+
96+
97+
9398

9499
Making your own ``sas`` robot drivers
95100
-------------------------------------
96101

97102
.. admonition:: (Murilo's) ``sas_robot_driver`` best practices
98103

99-
For each new robot called ``myrobot`` we have
104+
For each new robot called ``myrobot`` we have the three steps below as a must
100105

101106
#. :file:`sas_robot_driver_myrobot.hpp` with the driver's class definition that that inherits from ``sas_robot_driver``. This file must not include any internal driver or library files because it will be exported.
102107
#. :file:`sas_robot_driver_myrobot.cpp` with the driver's class implementation. Any internal libraries or drivers must be included here so that they are not externally visible.
103108
#. :file:`sas_robot_driver_myrobot_node.cpp` that configures the driver and calls the ROS2 loop.
104109

110+
The creation of the following two is trivial
111+
112+
#. :file:`real_robot_launch.py` a suitable launch file to properly configure :file:`sas_robot_driver_myrobot_node.cpp`.
113+
#. :file:`joint_interface_example.py` a Python script to control the C++ node (if needed).
114+
105115
Let's create all the files used in the remainder of this tutorial.
106116

107117
.. code-block:: console
@@ -139,15 +149,7 @@ The robot driver class
139149
├── sas_robot_driver_myrobot.cpp
140150
└── sas_robot_driver_myrobot_node.cpp
141151
142-
The example class file has two important design choices to note.
143-
144-
First, we rely on the struct ``RobotDriverMyrobotConfiguration``
145-
to simplify interaction with the constructor. This reduces the amount of code that needs to be changed if a parameter is
146-
added or removed.
147-
148-
Second, we rely on the `PIMPL idiom <https://en.cppreference.com/w/cpp/language/pimpl>`_. This idiom is important to
149-
prevent driver internals to pollute the exported header. This is a very important step to guarantee that your users
150-
don't have to worry about source files specific to the robot and that your package is correctly self-contained.
152+
The files in question are as follows.
151153

152154
.. tab-set::
153155

@@ -169,6 +171,36 @@ don't have to worry about source files specific to the robot and that your packa
169171
:linenos:
170172
:lines: 25-
171173

174+
The example class file has two important design choices to note.
175+
176+
First, we rely on the struct ``RobotDriverMyrobotConfiguration``
177+
to simplify interaction with the constructor. This reduces the amount of code that needs to be changed if a parameter is
178+
added or removed.
179+
180+
.. literalinclude:: ../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/include/sas_robot_driver_myrobot/sas_robot_driver_myrobot.hpp
181+
:language: cpp
182+
:linenos:
183+
:lines: 36-40
184+
185+
Second, we rely on the `PIMPL idiom <https://en.cppreference.com/w/cpp/language/pimpl>`_. This idiom is important to
186+
prevent driver internals to pollute the exported header. This is a very important step to guarantee that your users
187+
don't have to worry about source files specific to the robot and that your package is correctly self-contained. This
188+
is an important design aspect and should not be confused simply with aesthetics or my constant need to sound smart.
189+
190+
.. literalinclude:: ../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/include/sas_robot_driver_myrobot/sas_robot_driver_myrobot.hpp
191+
:language: cpp
192+
:linenos:
193+
:lines: 47-49
194+
195+
When using the `PIMPL idiom <https://en.cppreference.com/w/cpp/language/pimpl>`_ it is important not to forget that the
196+
definition of the implementation class is made in the source. In this example, it is simply a dummy, but in practice
197+
this will depend heavily on the robot drivers.
198+
199+
.. literalinclude:: ../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/src/sas_robot_driver_myrobot.cpp
200+
:language: cpp
201+
:linenos:
202+
:lines: 36-51
203+
172204
Writing the ROS2 Node
173205
---------------------
174206

@@ -196,7 +228,7 @@ Writing the ROS2 Node
196228
.. literalinclude:: ../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/src/sas_robot_driver_myrobot_node.cpp
197229
:language: cpp
198230
:linenos:
199-
:lines: 1-
231+
:lines: 25-
200232

201233
Contents of the launch file
202234
---------------------------

0 commit comments

Comments
 (0)