diff --git a/docs/.DS_Store b/docs/.DS_Store
new file mode 100644
index 0000000..9717f51
Binary files /dev/null and b/docs/.DS_Store differ
diff --git a/docs/graphs/network.mmd.svg b/docs/graphs/network.mmd.svg
new file mode 100644
index 0000000..d5a8f74
--- /dev/null
+++ b/docs/graphs/network.mmd.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/docs/graphs/network.png b/docs/graphs/network.png
new file mode 100644
index 0000000..66a449b
Binary files /dev/null and b/docs/graphs/network.png differ
diff --git a/docs/graphs/test.png b/docs/graphs/test.png
new file mode 100644
index 0000000..199bde2
Binary files /dev/null and b/docs/graphs/test.png differ
diff --git a/docs/source/action_clients.rst b/docs/source/action_clients.rst
index 7700797..a2813e6 100644
--- a/docs/source/action_clients.rst
+++ b/docs/source/action_clients.rst
@@ -89,8 +89,8 @@ of the instance to guarantee they will not get out of scope before the result is
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
:language: python
- :lines: 37-43
- :emphasize-lines: 4,6,7
+ :lines: 37-45
+ :emphasize-lines: 4,7,8
The following method can be used to send the action goal and trigger the entire process. Notably, suppose that a suitable
action has already been instantiated and is sent as argument to this method. We wait for the action server to be available.
@@ -104,7 +104,7 @@ is for the result of the goal request operation.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
:language: python
- :lines: 45-55
+ :lines: 47-57
:emphasize-lines: 1,5,10,11
After the goal is processed, the goal-related callback will be automatically called for us given that it was added to the respective
@@ -115,7 +115,7 @@ We ask for a result asynchronously. We then assign a third callback for when a r
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
:language: python
- :lines: 57-66
+ :lines: 59-68
:emphasize-lines: 1,4,9,10
The result callback will receive a future and process the result of the action somehow. In this toy example, we simply
@@ -123,13 +123,13 @@ print the results to the screen.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
:language: python
- :lines: 68-70
+ :lines: 70-72
Lastly, we see that the callback for the feedback is, again, very similar to that for a subscriber.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
:language: python
- :lines: 72-74
+ :lines: 74-76
To simplify this example slightly, please notice that the action is instantiated in the :code:`main` function, and
the action is triggered only once.
@@ -139,7 +139,7 @@ the object will not yet exist, or you will be locked in the spinner before sendi
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
:language: python
- :lines: 85-93
+ :lines: 87-95
Build and source
----------------
diff --git a/docs/source/cybersecurity/secret_message_decrypted.txt b/docs/source/cybersecurity/secret_message_decrypted.txt
new file mode 100644
index 0000000..b8fdd8b
--- /dev/null
+++ b/docs/source/cybersecurity/secret_message_decrypted.txt
@@ -0,0 +1 @@
+You have solved the exercise.
diff --git a/docs/source/gazebo/custom_nodes.rst b/docs/source/gazebo/custom_nodes.rst
index 3fc1bb3..8ce826f 100644
--- a/docs/source/gazebo/custom_nodes.rst
+++ b/docs/source/gazebo/custom_nodes.rst
@@ -273,7 +273,7 @@ name for :program:`Gazebo` to know which entity to set the pose. This name can b
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py
:language: python
- :lines: 46-65
+ :lines: 47-66
:emphasize-lines: 7
The second possibly unfamiliar is the choice of ``rclpy.spin_until_future_complete`` to illustrate calling the service
@@ -281,7 +281,7 @@ client only once.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py
:language: python
- :lines: 68-83
+ :lines: 69-84
:emphasize-lines: 11
.. admonition:: Exercises
@@ -334,7 +334,7 @@ and :program:`Gazebo` won't recognise it.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py
:language: python
- :lines: 46-70
+ :lines: 47-71
:emphasize-lines: 7
.. admonition:: Wait... what?
@@ -387,13 +387,13 @@ Lastly, `_gazebo_entity_id` is used to send the wrench to the correct entity.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py
:language: python
- :lines: 40-44
+ :lines: 43-47
There is also a simple proportional controller in one dimension.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py
:language: python
- :lines: 68-72
+ :lines: 71-75
Lastly, in the ``timer_callback``, we use the current coordinate value to compute the control action and send it to
:program:`Gazebo`.
@@ -401,7 +401,7 @@ Lastly, in the ``timer_callback``, we use the current coordinate value to comput
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py
:language: python
:emphasize-lines: 11,13
- :lines: 94-115
+ :lines: 97-118
.. admonition:: Exercises
diff --git a/docs/source/navigation/custom_nodes.rst b/docs/source/navigation/custom_nodes.rst
index b6286ff..540d592 100644
--- a/docs/source/navigation/custom_nodes.rst
+++ b/docs/source/navigation/custom_nodes.rst
@@ -394,7 +394,7 @@ with the initialisation.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py
:language: python
- :lines: 44-49
+ :lines: 45-50
:emphasize-lines: 2
The second part that might be unfamiliar is the covariance used in the message. The covariance matrix holds the variance
@@ -405,7 +405,7 @@ The covariance is highlighted below.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py
:language: python
- :lines: 51-73
+ :lines: 52-74
:emphasize-lines: 19-21
It is important not to be distracted by the nested ``pose``. The first one os the ``PoseWithCovariance``, part of the
diff --git a/docs/source/parameters_and_launch.rst b/docs/source/parameters_and_launch.rst
index 1b293a2..7fd22d5 100644
--- a/docs/source/parameters_and_launch.rst
+++ b/docs/source/parameters_and_launch.rst
@@ -91,7 +91,7 @@ For one-off parameters, we just get them once after declaring them. Because we'r
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py
:language: python
- :lines: 40-51
+ :lines: 42-53
:emphasize-lines: 2-5,9,12
In this case, we're making the topic name and publication periodicity as one-off configurable parameters.
@@ -108,13 +108,13 @@ For parameters that we obtain continuously through the lifetime of the Node, we
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py
:language: python
- :lines: 36-38
+ :lines: 38-40
then obtain them in another method, like so
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py
:language: python
- :lines: 55-68
+ :lines: 57-70
:emphasize-lines: 4,5,9,10
In this example, we are making the :code:`quote` and the :code:`philosopher_name` as configurable parameters that can be changed continuously, during the lifetime of the Node. After they are changed, the node will publish a message with different contents.
diff --git a/docs/source/publishers_and_subscribers.rst b/docs/source/publishers_and_subscribers.rst
index 4515bba..0e9fe20 100644
--- a/docs/source/publishers_and_subscribers.rst
+++ b/docs/source/publishers_and_subscribers.rst
@@ -148,14 +148,14 @@ When we built our :file:`package_with_interfaces` in the last section, what ROS2
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py
:language: python
- :lines: 24-27
+ :lines: 24-29
:emphasize-lines: 4
The publisher must be created with the :code:`Node.create_publisher(...)` method, which has the three parameters defined in the :ref:`publisher and subscriber parameter table`.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py
:language: python
- :lines: 36-39
+ :lines: 38-41
.. _publisher and subscriber parameter table:
@@ -178,13 +178,13 @@ Then, each message is handled much like any other class in Python. We instantiat
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py
:language: python
- :lines: 49-52
+ :lines: 51-54
Lastly, the message needs to be published using :code:`Node.publish(msg)`.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py
:language: python
- :lines: 54
+ :lines: 56
.. note::
@@ -218,21 +218,21 @@ Similarly to the publisher, in the subscriber, we start by importing the message
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py
:language: python
- :lines: 24-27
+ :lines: 24-28
:emphasize-lines: 4
Then, in our subclass of :code:`Node`, we call :code:`Node.create_subscription(...)` as follows
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py
:language: python
- :lines: 35-39
+ :lines: 36-40
:emphasize-lines: 4
where the only difference with respect to the publisher is the third argument, namely :code:`callback`, in which a method that receives a :code:`msg_type` and returns nothing is expected. For example, the :code:`amazing_quote_subscriber_callback`.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py
:language: python
- :lines: 41-54
+ :lines: 42-55
:emphasize-lines: 8,12,14
That callback method will be automatically called by ROS2, as one of the tasks performed by :code:`rclpy.spin(Node)`. Depending on the :code:`qos_profile`, it will not necessarily be the latest message.
diff --git a/docs/source/python_node_explained.rst b/docs/source/python_node_explained.rst
index 3ce346c..d08b703 100644
--- a/docs/source/python_node_explained.rst
+++ b/docs/source/python_node_explained.rst
@@ -23,7 +23,7 @@ The current version of ROS2 behaves better when your custom Node is a subclass o
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
:language: python
- :lines: 29-34
+ :lines: 30-35
:emphasize-lines: 1,5
About inheritance in Python, you can check the official documentation on `inheritance `_ and on `super() `_.
@@ -45,14 +45,14 @@ To do so, have the node create it with the :code:`create_timer()` method, as fol
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
:language: python
- :lines: 32-36
+ :lines: 33-37
:emphasize-lines: 4
The method that is periodically called by the Timer is, in this case, as follows. We use :code:`self.get_logger().info()` to print to the terminal periodically.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
:language: python
- :lines: 38-40
+ :lines: 39-41
:emphasize-lines: 1
In ROS2, the logging methods, i.e. :code:`self.get_logger().info()`, are methods of the Node itself. So, the capability to log (print to the terminal) using ROS2 Nodes is dependent on the scope in which that Node exists.
@@ -66,7 +66,7 @@ Anyhow, the point is that nothing related to ROS2 will happen unless the two fol
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
:language: python
- :lines: 44-59
+ :lines: 45-60
:emphasize-lines: 8,12
Have a :code:`try-catch` block for :code:`KeyboardInterrupt`
@@ -86,7 +86,7 @@ That is particularly important when real robots need to be gracefully shut down
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
:language: python
- :lines: 44-59
+ :lines: 45-60
:emphasize-lines: 7,13
.. important::
@@ -114,12 +114,12 @@ Example of a class:
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
:language: python
- :lines: 29-30
+ :lines: 30-31
:emphasize-lines: 2
Example of a method:
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
:language: python
- :lines: 38-39
+ :lines: 39-40
:emphasize-lines: 2
diff --git a/docs/source/service_servers_and_clients.rst b/docs/source/service_servers_and_clients.rst
index d3e130e..8daebdd 100644
--- a/docs/source/service_servers_and_clients.rst
+++ b/docs/source/service_servers_and_clients.rst
@@ -146,20 +146,20 @@ The code begins with an import to the service we created. No surprise here.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py
:language: python
- :lines: 24-30
+ :lines: 24-31
:emphasize-lines: 4
The Service Server must be initialised with the :code:`create_service()`, as follows, with parameters that should by now be quite obvious to us.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py
:language: python
- :lines: 36-39
+ :lines: 37-40
The Service Server receives a :code:`AddPoints.Request` and returns a :code:`AddPoints.Response`.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py
:language: python
- :lines: 43-49
+ :lines: 44-50
:emphasize-lines: 2,4
.. warning::
@@ -171,7 +171,7 @@ We use the members of :code:`AddPoints.Request` to calculate and populate the :c
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py
:language: python
- :lines: 51-55
+ :lines: 52-56
The Service Server was quite painless, but it doesn't do much. The Service Client might be a bit more on the painful side for the uninitiated.
@@ -226,7 +226,7 @@ To have access to the service, we import it with :code:`from .srv impor
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 24-31
+ :lines: 24-33
:emphasize-lines: 8
Instantiate a Service Client
@@ -236,7 +236,7 @@ We instantiate a Service Client with :code:`Node.create_client()`. The values of
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 40-42
+ :lines: 42-44
(Recommended) Wait for the Service Server to be available
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -257,7 +257,7 @@ As part of the :code:`async` framework, we instantiate a :code:`Future` (`More i
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 47
+ :lines: 49
Instantiate a Timer
+++++++++++++++++++
@@ -266,13 +266,13 @@ Whenever periodic work must be done, it is recommended to use a :code:`Timer`, a
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 49-52
+ :lines: 51-54
The need for a callback for the :code:`Timer`, should also be no surprise.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 54-55
+ :lines: 56-57
Service Clients use :code:`.Request()`
+++++++++++++++++++++++++++++++++++++++++++
@@ -281,7 +281,7 @@ Given that services work in a request-response model, the Service Client must in
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 57-65
+ :lines: 59-67
Make service calls with :code:`call_async()`
++++++++++++++++++++++++++++++++++++++++++++
@@ -300,14 +300,14 @@ The benefit of this is that the callback will not block our resources until the
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 67-72
+ :lines: 69-74
:emphasize-lines: 5,6
Given that we are periodically calling the service, before replacing the class :code:`Future` with the next service call, we can check if the service call was done with :code:`Future.done()`. If it is not done, we can use :code:`Future.cancel()` so that our callback can handle this case as well. For instance, if the Service Server has been shutdown, the :code:`Future` would never be done.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 67-72
+ :lines: 69-74
:emphasize-lines: 1-4
The Future callback
@@ -319,7 +319,7 @@ The result of the :code:`Future` is obtained using :code:`Future.result()`. The
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
:language: python
- :lines: 74-80
+ :lines: 76-82
:emphasize-lines: 1,3,4
Update the :file:`setup.py`
diff --git a/docs/source/transformations/tf2.rst b/docs/source/transformations/tf2.rst
index 3da19a2..fe981da 100644
--- a/docs/source/transformations/tf2.rst
+++ b/docs/source/transformations/tf2.rst
@@ -116,7 +116,7 @@ it persists across callback calls.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py
:language: python
- :lines: 36-49
+ :lines: 37-50
:emphasize-lines: 5,9,12
We add two parameters to be able to adjust the trajectory properties if desired. Again, these could be configurable
@@ -124,7 +124,7 @@ parameters but we leave them hard-coded for simplicity.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py
:language: python
- :lines: 51-55
+ :lines: 52-56
:emphasize-lines: 4,5
We create the ``TransformStamped`` as follows. Our rotation is simple so we build Quaternion for the
@@ -133,14 +133,14 @@ and ``child_frame_id`` as this robot's frame.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py
:language: python
- :lines: 58-78
+ :lines: 59-79
Finally, we send the transform with ``transform_broadcaster.sendTransform`` and update the local time counter for
the trajectory.
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py
:language: python
- :lines: 80-84
+ :lines: 81-85
Creating the listener
---------------------
@@ -162,7 +162,7 @@ would be to make this configurable as a parameter. We do not do that here to not
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py
:language: python
- :lines: 36-42
+ :lines: 38-44
:emphasize-lines: 2
We then create an instance of ``Timer`` and add the callback. In the callback, we use the buffer we created in the
@@ -174,7 +174,7 @@ The object created with ``rclpy.time.Time()`` is `equivalent to a time of zero <
.. literalinclude:: ../../../ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py
:language: python
- :lines: 47-60
+ :lines: 49-62
:emphasize-lines: 4-7
diff --git a/docs/source/using_python_library.rst b/docs/source/using_python_library.rst
index 63ae648..3120e3d 100644
--- a/docs/source/using_python_library.rst
+++ b/docs/source/using_python_library.rst
@@ -96,14 +96,14 @@ Indeed, the most difficult part is to make and configure the library itself. Aft
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py
:language: python
- :lines: 24-30
+ :lines: 24-31
:emphasize-lines: 7
And then use the symbols we imported as we would with any other Python library.
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py
:language: python
- :lines: 41-56
+ :lines: 42-57
:emphasize-lines: 10, 14
Build and source
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/package.xml b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/package.xml
index c934a61..52c132a 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/package.xml
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/package.xml
@@ -8,6 +8,7 @@
TODO: License declarationrclpy
+ geometry_msgsros_gz_interfacestf2_ros
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py
index 00c8e0f..51250a5 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/control_shape_thrust_node.py
@@ -26,6 +26,9 @@
import rclpy
from rclpy.node import Node
+from geometry_msgs.msg import TransformStamped
+from rclpy.publisher import Publisher
+from rclpy.timer import Timer
from rclpy.executors import ExternalShutdownException
import tf2_ros
@@ -44,7 +47,7 @@ def __init__(self) -> None:
self._gazebo_entity_id = 9 # Find this in Gazebo
# Set up the wrench publisher
- self.wrench_publisher = self.create_publisher(
+ self.wrench_publisher: Publisher = self.create_publisher(
msg_type=EntityWrench,
topic=self._wrench_topic,
qos_profile=1)
@@ -63,7 +66,7 @@ def __init__(self) -> None:
self.child_name = self._gazebo_entity_name # It will be populated this way by Gazebo
self.timer_period: float = 0.001
- self.timer = self.create_timer(self.timer_period, self.timer_callback)
+ self.timer: Timer = self.create_timer(self.timer_period, self.timer_callback)
def compute_control_action(self, current: float, target: float,
proportional_gain: float = 5.0) -> float:
@@ -74,7 +77,7 @@ def compute_control_action(self, current: float, target: float,
def send_force_to_gazebo(self, force: tuple[float, float, float] = (0, 0, 0)) -> None:
"""Basic method to send force to an entity."""
- ew = EntityWrench()
+ ew: EntityWrench = EntityWrench()
# Add the entity id. The entity.name is currently ignored by Gazebo.
ew.entity.id = self._gazebo_entity_id
@@ -95,7 +98,7 @@ def timer_callback(self) -> None:
"""The timer callback will look up the transforms and send the next control action."""
try:
- tfs = self.transform_listener_buffer.lookup_transform(
+ tfs: TransformStamped = self.transform_listener_buffer.lookup_transform(
self.parent_name,
self.child_name,
rclpy.time.Time())
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py
index 057155a..71cb7fb 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_poses_to_gazebo_node.py
@@ -26,6 +26,7 @@
import rclpy
from rclpy.node import Node
+from rclpy.client import Client
from rclpy.executors import ExternalShutdownException
from rclpy.task import Future
@@ -35,7 +36,7 @@ class SendPosesToGazeboNode(Node):
def __init__(self) -> None:
super().__init__('send_poses_to_gazebo_node')
- self.service_client = self.create_client(
+ self.service_client: Client = self.create_client(
srv_type=SetEntityPose,
srv_name='/world/shapes_with_tf2_and_wrench/set_pose')
@@ -46,7 +47,7 @@ def __init__(self) -> None:
def send_pose_to_gazebo(self) -> Future[SetEntityPose.Response]:
"""Sample method sending a pose to and entity in Gazebo."""
- request = SetEntityPose.Request()
+ request: SetEntityPose.Request = SetEntityPose.Request()
# Add the entity name. For this one, Gazebo accepts the name. :)
request.entity.name = "box"
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py
index 1f37e4d..fbb508f 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_gazebo/python_package_that_uses_gazebo/send_wrenches_to_gazebo_node.py
@@ -26,6 +26,7 @@
import rclpy
from rclpy.node import Node
+from rclpy.publisher import Publisher
from rclpy.executors import ExternalShutdownException
class SendWrenchesToGazeboNode(Node):
@@ -34,7 +35,7 @@ class SendWrenchesToGazeboNode(Node):
def __init__(self) -> None:
super().__init__('send_wrenches_to_gazebo_node')
- self.publisher = self.create_publisher(
+ self.publisher: Publisher = self.create_publisher(
msg_type=EntityWrench,
topic='/world/shapes_with_tf2_and_wrench/wrench',
qos_profile=1)
@@ -46,7 +47,7 @@ def __init__(self) -> None:
def send_wrench_to_gazebo(self) -> None:
"""Basic method publishing wrenches to Gazebo."""
- ew = EntityWrench()
+ ew: EntityWrench = EntityWrench()
# Add the entity id. The entity.name is currently ignored by Gazebo.
ew.entity.id = 9
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_geometry_msgs/python_package_that_uses_geometry_msgs/create_stamped_transforms_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_geometry_msgs/python_package_that_uses_geometry_msgs/create_stamped_transforms_node.py
index a1d97bc..b05568f 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_geometry_msgs/python_package_that_uses_geometry_msgs/create_stamped_transforms_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_geometry_msgs/python_package_that_uses_geometry_msgs/create_stamped_transforms_node.py
@@ -36,7 +36,7 @@ def __init__(self) -> None:
def create_and_print_stamped_transform(self) -> None:
"""Basic method showing the creation of TransformStamped objects."""
- tfs = TransformStamped()
+ tfs: TransformStamped = TransformStamped()
# Initialize header with
## Timestamp equal to the current clock time
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py
index b8ea803..67a40dd 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_initial_pose_publisher_node.py
@@ -25,6 +25,7 @@
import rclpy
from rclpy.node import Node
+from rclpy.publisher import Publisher
from rclpy.executors import ExternalShutdownException
from geometry_msgs.msg import PoseWithCovarianceStamped
@@ -36,7 +37,7 @@ def __init__(self) -> None:
self._topic = '/initialpose'
- self.publisher = self.create_publisher(
+ self.publisher: Publisher = self.create_publisher(
msg_type=PoseWithCovarianceStamped,
topic=self._topic,
qos_profile=1)
@@ -53,7 +54,7 @@ def send_initial_pose_with_covariance(self) -> None:
self.get_logger().info(f"Publishing pose to topic: {self._topic}.")
- pwcs = PoseWithCovarianceStamped()
+ pwcs: PoseWithCovarianceStamped = PoseWithCovarianceStamped()
pwcs.header.stamp = self.get_clock().now().to_msg()
pwcs.header.frame_id = 'map'
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_navigate_to_pose_action_client_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_navigate_to_pose_action_client_node.py
index 7435699..264c34d 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_navigate_to_pose_action_client_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_nav2/python_package_that_uses_nav2/nav2_navigate_to_pose_action_client_node.py
@@ -37,13 +37,13 @@ class Nav2NavigateToPoseActionClient(Node):
def __init__(self) -> None:
super().__init__('nav2_navigate_to_pose_action_client')
- self.action_client = ActionClient(self, NavigateToPose, '/navigate_to_pose')
+ self.action_client: ActionClient = ActionClient(self, NavigateToPose, '/navigate_to_pose')
self.send_goal_future: Future # This will be used in `send_goal`
self.get_result_future: Future # This will be used in 'goal_response_callback'
def send_goal_async(self, desired_pose: Pose, behaviour_tree: str) -> None:
- goal_msg = NavigateToPose.Goal()
+ goal_msg: NavigateToPose.Goal = NavigateToPose.Goal()
goal_msg.pose.header.stamp = self.get_clock().now().to_msg()
goal_msg.pose.header.frame_id = 'map'
goal_msg.pose.pose = desired_pose
@@ -85,9 +85,9 @@ def main(args: list[str] | None = None) -> None:
try:
rclpy.init(args=args)
- node = Nav2NavigateToPoseActionClient()
+ node: Nav2NavigateToPoseActionClient = Nav2NavigateToPoseActionClient()
- desired_pose = Pose()
+ desired_pose: Pose = Pose()
desired_pose.position.x = 1.0
desired_pose.position.y = -1.0
desired_pose.orientation.w = 1.0
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py
index 264706c..b435e82 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_parameters_and_launch_files/python_package_that_uses_parameters_and_launch_files/amazing_quote_configurable_publisher_node.py
@@ -23,6 +23,8 @@
"""
import rclpy
from rclpy.node import Node
+from rclpy.publisher import Publisher
+from rclpy.timer import Timer
from rclpy.executors import ExternalShutdownException
from package_with_interfaces.msg import AmazingQuote
@@ -43,12 +45,12 @@ def __init__(self) -> None:
self.declare_parameter('period', 0.5)
timer_period: float = self.get_parameter('period').get_parameter_value().double_value
- self.configurable_amazing_quote_publisher = self.create_publisher(
+ self.configurable_amazing_quote_publisher: Publisher = self.create_publisher(
msg_type=AmazingQuote,
topic=topic_name,
qos_profile=1)
- self.timer = self.create_timer(timer_period, self.timer_callback)
+ self.timer: Timer = self.create_timer(timer_period, self.timer_callback)
self.incremental_id: int = 0
@@ -58,7 +60,7 @@ def timer_callback(self) -> None:
quote: str = self.get_parameter('quote').get_parameter_value().string_value
philosopher_name: str = self.get_parameter('philosopher_name').get_parameter_value().string_value
- amazing_quote = AmazingQuote()
+ amazing_quote: AmazingQuote = AmazingQuote()
amazing_quote.id = self.incremental_id
amazing_quote.quote = quote
amazing_quote.philosopher_name = philosopher_name
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py
index 13025b2..8309379 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_broadcaster_node.py
@@ -26,6 +26,7 @@
import rclpy
from rclpy.node import Node
+from rclpy.timer import Timer
from rclpy.executors import ExternalShutdownException
import tf2_ros
@@ -45,7 +46,7 @@ def __init__(self) -> None:
self.timer_period: float = 0.01
self.timer_elapsed_time: float = 0
- self.timer = self.create_timer(self.timer_period, self.timer_callback)
+ self.timer: Timer = self.create_timer(self.timer_period, self.timer_callback)
def timer_callback(self) -> None:
# We define some parameters of our trajectory.
@@ -55,7 +56,7 @@ def timer_callback(self) -> None:
trajectory_frequency = 0.1
# Create an instance of a TransformStamped, used by the broadcaster
- tfs = TransformStamped()
+ tfs: TransformStamped = TransformStamped()
## Initialize header with
# Timestamp equal to the current clock time
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py
index 2c5efc8..4bdfd0f 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_tf2/python_package_that_uses_tf2/tf2_listener_node.py
@@ -23,6 +23,8 @@
"""
import rclpy
from rclpy.node import Node
+from geometry_msgs.msg import TransformStamped
+from rclpy.timer import Timer
from rclpy.executors import ExternalShutdownException
import tf2_ros
@@ -42,12 +44,12 @@ def __init__(self) -> None:
self.child_name = "robot_1"
self.timer_period: float = 0.1
- self.timer = self.create_timer(self.timer_period, self.timer_callback)
+ self.timer: Timer = self.create_timer(self.timer_period, self.timer_callback)
def timer_callback(self) -> None:
try:
- tfs = self.transform_listener_buffer.lookup_transform(
+ tfs: TransformStamped = self.transform_listener_buffer.lookup_transform(
self.parent_name,
self.child_name,
rclpy.time.Time())
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
index 956bccb..8edf86a 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_client_node.py
@@ -37,13 +37,14 @@ class MoveStraightIn2DActionClientNode(Node):
def __init__(self) -> None:
super().__init__('move_straight_in_2d_action_client')
- self.action_client = ActionClient(self, MoveStraightIn2D, '/move_straight_in_2d')
+ self.action_client: ActionClient = ActionClient(
+ self, MoveStraightIn2D, '/move_straight_in_2d')
self.send_goal_future: Future # This will be used in `send_goal`
self.get_result_future: Future # This will be used in 'goal_response_callback'
def send_goal_async(self, desired_position: Point) -> None:
- goal_msg = MoveStraightIn2D.Goal()
+ goal_msg: MoveStraightIn2D.Goal = MoveStraightIn2D.Goal()
goal_msg.desired_position = desired_position
while not self.action_client.wait_for_server(timeout_sec=1.0):
@@ -85,7 +86,7 @@ def main(args: list[str] | None = None) -> None:
node = MoveStraightIn2DActionClientNode()
# Send the goal once and then do nothing until the user shuts this node down.
- desired_position = Point()
+ desired_position: Point = Point()
desired_position.x = 1.0
desired_position.y = -1.0
node.send_goal_async(desired_position)
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_server_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_server_node.py
index 1cdaabc..13ebc12 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_server_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_actions/python_package_that_uses_the_actions/move_straight_in_2d_action_server_node.py
@@ -39,11 +39,11 @@ class MoveStraightIn2DActionServerNode(Node):
def __init__(self) -> None:
super().__init__('move_straight_in_2d_action_server')
- self.current_position = Point()
+ self.current_position: Point = Point()
self.MAX_ITERATIONS: int = 100
self.sampling_time: float = 0.01
- self.action_server = ActionServer(
+ self.action_server: ActionServer = ActionServer(
self,
MoveStraightIn2D,
'/move_straight_in_2d',
@@ -93,7 +93,7 @@ def execute_callback(self, goal: ServerGoalHandle) -> MoveStraightIn2D.Result:
self.get_logger().info(f'current_position is {self.current_position}.')
self.get_logger().info(f'desired_position set to {desired_position}.')
- feedback_msg = MoveStraightIn2D.Feedback()
+ feedback_msg: MoveStraightIn2D.Feedback = MoveStraightIn2D.Feedback()
# Let's limit the maximum number of iterations this can accept
for i in range(self.MAX_ITERATIONS):
@@ -111,7 +111,7 @@ def execute_callback(self, goal: ServerGoalHandle) -> MoveStraightIn2D.Result:
# A sleep illustrating the time it would take in real life for a robot to move
time.sleep(self.sampling_time)
- result = MoveStraightIn2D.Result()
+ result: MoveStraightIn2D.Result = MoveStraightIn2D.Result()
result.final_position = self.current_position
return result
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py
index 89bbdef..8aa5a6e 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_library/python_package_that_uses_the_library/library_user_node.py
@@ -26,6 +26,7 @@
import rclpy
from rclpy.node import Node
+from rclpy.timer import Timer
from rclpy.executors import ExternalShutdownException
from python_package_with_a_library.sample_python_library import SampleClass, sample_function_for_square_of_sum
@@ -36,7 +37,7 @@ class LibraryUser(Node):
def __init__(self) -> None:
super().__init__('library_user')
timer_period: float = 0.5
- self.timer = self.create_timer(timer_period, self.timer_callback)
+ self.timer: Timer = self.create_timer(timer_period, self.timer_callback)
def timer_callback(self) -> None:
"""
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py
index 1fde6ac..b07b370 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_publisher_node.py
@@ -23,6 +23,8 @@
"""
import rclpy
from rclpy.node import Node
+from rclpy.publisher import Publisher
+from rclpy.timer import Timer
from rclpy.executors import ExternalShutdownException
from package_with_interfaces.msg import AmazingQuote
@@ -33,20 +35,20 @@ class AmazingQuotePublisherNode(Node):
def __init__(self) -> None:
super().__init__('amazing_quote_publisher_node')
- self.amazing_quote_publisher = self.create_publisher(
+ self.amazing_quote_publisher: Publisher = self.create_publisher(
msg_type=AmazingQuote,
topic='/amazing_quote',
qos_profile=1)
timer_period: float = 0.5
- self.timer = self.create_timer(timer_period, self.timer_callback)
+ self.timer: Timer = self.create_timer(timer_period, self.timer_callback)
self.incremental_id: int = 0
def timer_callback(self) -> None:
"""Method that is periodically called by the timer."""
- amazing_quote = AmazingQuote()
+ amazing_quote: AmazingQuote = AmazingQuote()
amazing_quote.id = self.incremental_id
amazing_quote.quote = 'Use the force, Pikachu!'
amazing_quote.philosopher_name = 'Uncle Ben'
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py
index 1ab5bde..731c7be 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_messages/python_package_that_uses_the_messages/amazing_quote_subscriber_node.py
@@ -23,6 +23,7 @@
"""
import rclpy
from rclpy.node import Node
+from rclpy.subscription import Subscription
from rclpy.executors import ExternalShutdownException
from package_with_interfaces.msg import AmazingQuote
@@ -32,7 +33,7 @@ class AmazingQuoteSubscriberNode(Node):
def __init__(self) -> None:
super().__init__('amazing_quote_subscriber_node')
- self.amazing_quote_subscriber = self.create_subscription(
+ self.amazing_quote_subscriber: Subscription = self.create_subscription(
msg_type=AmazingQuote,
topic='/amazing_quote',
callback=self.amazing_quote_subscriber_callback,
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_just_once_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_just_once_node.py
index afea355..061dc2c 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_just_once_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_just_once_node.py
@@ -26,6 +26,7 @@
import rclpy
from rclpy.task import Future
from rclpy.node import Node
+from rclpy.client import Client
from rclpy.executors import ExternalShutdownException
from package_with_interfaces.srv import AddPoints
@@ -37,7 +38,7 @@ class AddPointsServiceClientJustOnceNode(Node):
def __init__(self) -> None:
super().__init__('add_points_service_client_just_once')
- self.service_client = self.create_client(
+ self.service_client: Client = self.create_client(
srv_type=AddPoints,
srv_name='/add_points')
@@ -48,7 +49,7 @@ def __init__(self) -> None:
self.future: Future = None
# Create service request
- request = AddPoints.Request()
+ request: AddPoints.Request = AddPoints.Request()
request.a.x = random.uniform(0, 1000)
request.a.y = random.uniform(0, 1000)
@@ -59,7 +60,7 @@ def __init__(self) -> None:
request.b.z = random.uniform(0, 1000)
# Call the service async and set the done callback
- self.future = self.service_client.call_async(request)
+ self.future: Future = self.service_client.call_async(request)
self.future.add_done_callback(self.process_response)
def process_response(self, future: Future) -> None:
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
index 77fe46c..dd1b884 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_client_node.py
@@ -26,6 +26,8 @@
import rclpy
from rclpy.task import Future
from rclpy.node import Node
+from rclpy.client import Client
+from rclpy.timer import Timer
from rclpy.executors import ExternalShutdownException
from package_with_interfaces.srv import AddPoints
@@ -37,7 +39,7 @@ class AddPointsServiceClientNode(Node):
def __init__(self) -> None:
super().__init__('add_points_service_client')
- self.service_client = self.create_client(
+ self.service_client: Client = self.create_client(
srv_type=AddPoints,
srv_name='/add_points')
@@ -47,14 +49,14 @@ def __init__(self) -> None:
self.future: Future = None
timer_period: float = 0.5
- self.timer = self.create_timer(
+ self.timer: Timer = self.create_timer(
timer_period_sec=timer_period,
callback=self.timer_callback)
def timer_callback(self) -> None:
"""Method that is periodically called by the timer."""
- request = AddPoints.Request()
+ request: AddPoints.Request = AddPoints.Request()
request.a.x = random.uniform(0, 1000)
request.a.y = random.uniform(0, 1000)
@@ -68,7 +70,7 @@ def timer_callback(self) -> None:
self.future.cancel() # Cancel the future. The callback will be called with Future.result == None.
self.get_logger().warn("Service Future canceled. The Node took too long to process the service call."
"Is the Service Server still alive?")
- self.future = self.service_client.call_async(request)
+ self.future: Future = self.service_client.call_async(request)
self.future.add_done_callback(self.process_response)
def process_response(self, future: Future) -> None:
diff --git a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py
index b7d6db2..9e422ae 100644
--- a/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py
+++ b/ros2_tutorial_workspace/src/python_package_that_uses_the_services/python_package_that_uses_the_services/add_points_service_server_node.py
@@ -23,6 +23,7 @@
"""
import rclpy
from rclpy.node import Node
+from rclpy.service import Service
from rclpy.executors import ExternalShutdownException
from package_with_interfaces.srv import AddPoints
@@ -33,7 +34,7 @@ class AddPointsServiceServerNode(Node):
def __init__(self) -> None:
super().__init__('add_points_service_server')
- self.service_server = self.create_service(
+ self.service_server: Service = self.create_service(
srv_type=AddPoints,
srv_name='/add_points',
callback=self.add_points_service_callback)
diff --git a/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py b/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
index 4a95e95..6bc787f 100644
--- a/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
+++ b/ros2_tutorial_workspace/src/python_package_with_a_node/python_package_with_a_node/print_forever_node.py
@@ -23,6 +23,7 @@
"""
import rclpy
from rclpy.node import Node
+from rclpy.timer import Timer
from rclpy.executors import ExternalShutdownException
@@ -32,7 +33,7 @@ class PrintForever(Node):
def __init__(self) -> None:
super().__init__('print_forever')
timer_period: float = 0.5
- self.timer = self.create_timer(timer_period, self.timer_callback)
+ self.timer: Timer = self.create_timer(timer_period, self.timer_callback)
self.print_count: int = 0
def timer_callback(self) -> None: