Creating and building ROS2 in the Fleet Manager
===============================================
If there is a problem with the action in ``FleetManager/ROS2``, or a problem with the topic in ``FleetManager/StateVector``, you need to modify the folder to create the action or the topic again.
State Vector Subscriber
-----------------------
Delete files
~~~~~~~~~~~~
In ``FleetManager/StateVector``, move the ``src`` folder and remove all the folders except ``grpc``.
Create a workspace
~~~~~~~~~~~~~~~~~~
.. code-block:: bash
cd StateVector
mkdir src
cd src
Create a package
~~~~~~~~~~~~~~~~
In ``StateVector/src``, execute:
.. code-block:: bash
ros2 pkg create --build-type ament_python --license Apache-2.0 state_vector_pubsub
Import the subscriber node
~~~~~~~~~~~~~~~~~~~~~~~~~~
Navigate into ``StateVector/src/state_vector_pubsub/state_vector_pubsub``. Then, move into the directory the ``.py`` modules that are in ``src/state_vector_pubsub/state_vector_pubsub``.
Add dependencies
~~~~~~~~~~~~~~~~
Add the following dependencies into ``package.xml`` (``StateVector/src/state_vector_pubsub``):
.. code-block:: xml
rclpy
std_msgs
Add an entry point
~~~~~~~~~~~~~~~~~~
In ``setup.py``, add the following line within the ``console_scripts`` brackets of the ``entry_points`` field:
.. code-block:: python
entry_points={
'console_scripts': [
'listener = py_pubsub.subscriber_member_function:main',
],
}
Check ``setup.cfg``
~~~~~~~~~~~~~~~~~~~
Check that ``setup.cfg`` has the following content:
.. code-block:: ini
[develop]
script_dir=$base/lib/state_vector_pubsub
[install]
install_scripts=$base/lib/state_vector_pubsub
Build and run
~~~~~~~~~~~~~
Still in the root of your workspace, ``StateVector``, build your new package:
.. code-block:: bash
colcon build --packages-select state_vector_pubsub
Open a new terminal, navigate to ``StateVector``, and source the setup files:
.. code-block:: bash
source install/setup.bash
Now run the listener node:
.. code-block:: bash
ros2 run state_vector_pubsub listener
Action Client
-------------
Delete files
~~~~~~~~~~~~
In ``FleetManager/ROS2``, move the ``src`` folder and remove all the folders except ``grpc``.
Create a workspace
~~~~~~~~~~~~~~~~~~
.. code-block:: bash
cd ROS2
mkdir src
cd src
Create an interface package
~~~~~~~~~~~~~~~~~~~~~~~~~~~
In ``ROS2/src``, execute:
.. code-block:: bash
ros2 pkg create --license Apache-2.0 commands_action_interface
Restore the action
~~~~~~~~~~~~~~~~~~
Create an ``action`` directory in the ROS 2 package ``commands_action_interface``:
.. code-block:: bash
cd commands_action_interface
mkdir action
Move ``Commands.action`` from ``src/commands_action_interface/action`` into ``ROS2/src/commands_action_interface/action``.
Building the action
~~~~~~~~~~~~~~~~~~~
Add the following lines to ``CMakeLists.txt`` before the ``ament_package()`` line:
.. code-block:: cmake
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"action/Commands.action"
)
Add the required dependencies to ``package.xml``:
.. code-block:: xml
rosidl_default_generators
rosidl_interface_packages
Build the package by executing the following commands:
.. code-block:: bash
# Change to the root of the workspace
cd ~/ROS2
# Build
colcon build
Run the server
~~~~~~~~~~~~~~
Move all the ``.py`` modules from ``src/commands_action_interface/src`` to ``ROS2/src/commands_action_interface/src``.
To run the server, open a new terminal, navigate to ``ROS2``, and source the setup files:
.. code-block:: bash
source install/setup.bash
Now run the client:
.. code-block:: bash
python3 src.commands_action_interface.src.commands_action_client.py