From db3a93d92a73e2a798fae825ac8bc260ca98aa8c Mon Sep 17 00:00:00 2001 From: ipa-vsp Date: Tue, 23 Apr 2024 19:58:04 +0200 Subject: [PATCH] WIP: service interface examples --- .../examples/service-interface-examples.rst | 66 +++++++++++++++++++ canopen/sphinx/index.rst | 9 ++- canopen_tests/CMakeLists.txt | 2 +- canopen_tests/config/simple/bus.yml | 15 ++--- 4 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 canopen/sphinx/examples/service-interface-examples.rst diff --git a/canopen/sphinx/examples/service-interface-examples.rst b/canopen/sphinx/examples/service-interface-examples.rst new file mode 100644 index 00000000..8afdc436 --- /dev/null +++ b/canopen/sphinx/examples/service-interface-examples.rst @@ -0,0 +1,66 @@ +Service Interface Examples +========================== + +Before running these examples, ensure that to :ref:`start the vcan0 interface `. +You can find these examples in the ``canopen_test`` package. + +Proxy Driver Examples +--------------------- +A proxy driver provides a simple way to forward CANopen functionalities for a specific device using ROS2 services and messages. For more details on the proxy driver, see :doc:`../user-guide/proxy-driver`. + +Configuring ``bus.yaml`` +~~~~~~~~~~~~~~~~~~~~~~~~ +The configuration for the proxy driver is specified in the ``bus.yaml`` file. Here's an example configuration: + +.. code-block:: yaml + + options: + dcf_path: "@BUS_CONFIG_PATH@" + + master: + node_id: 1 + driver: "ros2_canopen::MasterDriver" + package: "canopen_master_driver" + + defaults: + dcf: "simple.eds" + driver: "ros2_canopen::ProxyDriver" + package: "canopen_proxy_driver" + polling: true + period: 10 + + nodes: + proxy_device_1: + node_id: 2 + proxy_device_2: + node_id: 3 + +For further details about the configuration, refer to :doc:`../user-guide/configuration`. Additionally, add ``cogen_dcf(simple)`` in the *CMakeLists.txt* file to generate the necessary artifacts for the proxy driver. + +Running the Proxy Driver Examples +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +To launch the proxy driver setup, use the following command: + +.. code-block:: bash + + $ ros2 launch canopen_tests proxy_setup.launch.py + +Verify that all services are available by running the ROS2 topic and service list commands. To conduct a test: + +.. code-block:: bash + + $ ros2 topic pub /proxy_device_1/tpdo canopen_interfaces/msg/COData "{ index: 0x4000, subindex: 0, data: 200 }" + +Check the output by running: + +.. code-block:: bash + + $ ros2 topic echo /proxy_device_1/rpdo + +.. note:: + + These examples use a fake slave device. Running on actual hardware may yield different results. + Always refer to the device's documentation for specific details. + +CiA402 Driver Examples +----------------------- \ No newline at end of file diff --git a/canopen/sphinx/index.rst b/canopen/sphinx/index.rst index 178fca32..7aed1172 100644 --- a/canopen/sphinx/index.rst +++ b/canopen/sphinx/index.rst @@ -26,6 +26,13 @@ This is the documentation of the ROS2 CANopen stack. user-guide/how-to-create-a-cia301-system user-guide/how-to-create-a-robot-system +.. toctree:: + :maxdepth: 1 + :caption: Examples + :glob: + + examples/service-interface-examples + .. toctree:: :maxdepth: 1 @@ -37,7 +44,7 @@ This is the documentation of the ROS2 CANopen stack. developers-guide/architecture developers-guide/new-driver developers-guide/new-master - API Reference + API Reference .. toctree:: :maxdepth: 1 diff --git a/canopen_tests/CMakeLists.txt b/canopen_tests/CMakeLists.txt index f2f7c052..8374bf3d 100644 --- a/canopen_tests/CMakeLists.txt +++ b/canopen_tests/CMakeLists.txt @@ -10,7 +10,7 @@ find_package(ament_cmake REQUIRED) find_package(lely_core_libraries REQUIRED) -generate_dcf(simple) +cogen_dcf(simple) generate_dcf(canopen_system) cogen_dcf(cia402_system) cogen_dcf(cia402_namespaced_system) diff --git a/canopen_tests/config/simple/bus.yml b/canopen_tests/config/simple/bus.yml index 8b26d4e8..cc8bc0ae 100644 --- a/canopen_tests/config/simple/bus.yml +++ b/canopen_tests/config/simple/bus.yml @@ -6,18 +6,15 @@ master: driver: "ros2_canopen::MasterDriver" package: "canopen_master_driver" -proxy_device_1: - node_id: 2 +defaults: dcf: "simple.eds" driver: "ros2_canopen::ProxyDriver" package: "canopen_proxy_driver" polling: true period: 10 -proxy_device_2: - node_id: 3 - dcf: "simple.eds" - driver: "ros2_canopen::ProxyDriver" - package: "canopen_proxy_driver" - polling: true - period: 10 +nodes: + proxy_device_1: + node_id: 2 + proxy_device_2: + node_id: 3