Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation. #283

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions canopen/sphinx/application/diff_drive.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Differential Drive Controller
=============================
97 changes: 92 additions & 5 deletions canopen/sphinx/application/trinamic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ Getting started

If you haven't already done so, follow the steps in the :doc:`../user-guide/configuration`.

To know more about how to create a configuration follow this steps: :doc:`../user-guide/how-to-create-a-configuration`.

Configuration
-------------

- Create new package named ``trinamic_pd42_can``. To know how to create a package follow the documentation provided in `ROS2 <https://docs.ros.org/en/foxy/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html>`_
- Follow the configuration folder tree steps as per the :doc:`../user-guide/configuration`. .
- Create a new folder in the ``config`` folder of your configuration package. Name it ``single-pd42``.
- Download ``.eds`` file from `Trinamic <https://www.trinamic.com/fileadmin/assets/Products/Drives_Software/TMCM-1270_CANopen_V326.zip>`_ and place ``TMCM-1270.eds`` in the ``single-pd42`` folder.
- Download ``.eds`` file from `Trinamic Github <https://github.com/hellantos/trinamic_pd42_can/blob/master/config/single-pd42/TMCM-1270.eds>`_ and place ``TMCM-1270.eds`` in the ``single-pd42`` folder.
- Create a ``bus.yml`` file in the ``single-pd42`` folder with the following content:

.. code-block:: yaml
Expand Down Expand Up @@ -50,7 +53,7 @@ Configuration
node_id: 1


- Edit the ``CMakeLists.txt`` file in the ``config`` folder of your configuration package and add the following lines:
- Edit the ``CMakeLists.txt`` file in the package and add the following lines:

.. code-block:: cmake

Expand Down Expand Up @@ -93,7 +96,91 @@ Configuration

ament_package()

- Create launch file in folder ``launch`` and add the following content:
- Create a source file in the ``src`` folder ``position_tick_motor.cpp`` and add the follow lines.

.. code-block:: cpp


#include <chrono>
#include <cstdlib>
#include <memory>

#include "canopen_interfaces/srv/co_target_double.hpp"
#include "rclcpp/rclcpp.hpp"
#include "std_srvs/srv/trigger.hpp"
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);

std::shared_ptr<rclcpp::Node> node = rclcpp::Node::make_shared("position_tick_motor_node");

RCLCPP_INFO(node->get_logger(), "Position Tick Motor Node Started");
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr init_client =
node->create_client<std_srvs::srv::Trigger>("/trinamic_pd42/init");
rclcpp::Client<std_srvs::srv::Trigger>::SharedPtr mode_client =
node->create_client<std_srvs::srv::Trigger>("/trinamic_pd42/cyclic_position_mode");
rclcpp::Client<canopen_interfaces::srv::COTargetDouble>::SharedPtr target_client =
node->create_client<canopen_interfaces::srv::COTargetDouble>("/trinamic_pd42/target");

while (!init_client->wait_for_service(std::chrono::seconds(1)) &&
!mode_client->wait_for_service(std::chrono::seconds(1)) &&
!target_client->wait_for_service(std::chrono::seconds(1)))
{
if (!rclcpp::ok())
{
RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting.");
return 0;
}
RCLCPP_INFO(node->get_logger(), "service not available, waiting again...");
}

auto trigger_req = std::make_shared<std_srvs::srv::Trigger::Request>();
auto result = init_client->async_send_request(trigger_req);
if (rclcpp::spin_until_future_complete(node, result) == rclcpp::FutureReturnCode::SUCCESS)
{
RCLCPP_INFO(node->get_logger(), "Init service called successfully");
}
else
{
RCLCPP_ERROR(node->get_logger(), "Failed to call init service");
}

result = mode_client->async_send_request(trigger_req);
if (rclcpp::spin_until_future_complete(node, result) == rclcpp::FutureReturnCode::SUCCESS)
{
RCLCPP_INFO(node->get_logger(), "Config position mode service called successfully");
}
else
{
RCLCPP_ERROR(node->get_logger(), "Failed to call config service");
}

RCLCPP_INFO(node->get_logger(), "Starting to send target values");

auto targer_req = std::make_shared<canopen_interfaces::srv::COTargetDouble::Request>();
double target = 0;
while (rclcpp::ok())
{
targer_req->target = target;
auto res = target_client->async_send_request(targer_req);
if (rclcpp::spin_until_future_complete(node, res) == rclcpp::FutureReturnCode::SUCCESS)
{
RCLCPP_INFO(node->get_logger(), "Set Target: %.2f", target);
}
else
{
RCLCPP_ERROR(node->get_logger(), "Failed to call target service");
}
rclcpp::sleep_for(std::chrono::seconds(1));

target += 1.0;
if (target >= 105.0) target = 0;
}

return 0;
}

- Create a launch file ``file_name.launch.py`` in folder ``launch`` and add the following content:

.. code-block:: python

Expand Down Expand Up @@ -168,7 +255,7 @@ Configuration
Running the example
-------------------

To begin, follow the instructions for :doc:`../quickstart/operation`, which can be done using either a virtual or peak CAN interface.
To begin, follow the instructions for :doc:`../quickstart/setup-network`, which can be done using either a virtual or peak CAN interface.

If you prefer to use a real CAN interface, you will need to modify the launch file by changing the ``can_interface_name`` argument to ``can0``.
Additionally, if you are using real hardware, you should comment out the fake slave launch by adding a *#* in front of the line *ld.add_action(slave_node_1)*.
Expand Down
66 changes: 66 additions & 0 deletions canopen/sphinx/examples/service-interface-examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Service Interface Examples
==========================

Before running these examples, ensure that to :ref:`start the vcan0 interface <quick-start-setup-can-controller>`.
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
-----------------------
24 changes: 14 additions & 10 deletions canopen/sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ This is the documentation of the ROS2 CANopen stack.
:glob:

quickstart/installation
quickstart/operation
quickstart/setup-network
quickstart/examples

.. toctree::
:maxdepth: 1
:caption: User Guide
:glob:

user-guide/operation
user-guide/configuration
user-guide/master
user-guide/proxy-driver
user-guide/cia402-driver
user-guide/how-to-create-a-configuration
user-guide/how-to-create-a-cia301-system
user-guide/how-to-create-a-robot-system
user-guide/1_operation
user-guide/2_interface
user-guide/3_configuration
user-guide/4_how_to_guide

.. toctree::
:maxdepth: 1
:caption: Examples
:glob:

examples/service-interface-examples


.. toctree::
Expand All @@ -37,7 +40,8 @@ This is the documentation of the ROS2 CANopen stack.
developers-guide/architecture
developers-guide/new-driver
developers-guide/new-master
API Reference <https://ros-industrial.github.io/ros2_canopen/api/>
developers-guide/new-device-manager
API Reference <https://ros-industrial.github.io/ros2_canopen/api/rolling/>

.. toctree::
:maxdepth: 1
Expand Down
29 changes: 27 additions & 2 deletions canopen/sphinx/quickstart/installation.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
Installation
===============================
Clone ros2_canopen into your ROS2 workspace's source folder, install dependencies and
build with colcon and your done.
- Clone ros2_canopen into your ROS2 workspace's source folder, install dependencies and build with colcon and your done.
- In order to create a workspace

.. code-block:: console

$ mkdir -p ~/name_ws/src
$ cd ~/name_ws/src

.. note::
Change the ``name_ws`` to your desired workspace name.

.. code-block:: console

$ git clone https://github.com/ros-industrial/ros2_canopen.git
$ cd ..
$ source /opt/ros/ros_distro/setup.bash # Replace the *ros distro as per your need.
$ rosdep install --from-paths src/ros2_canopen --ignore-src -r -y
$ colcon build
$ source install/setup.bash

.. note::
Kindly check the branch as per your configuration before cloning the repository.

Testing with pre-release binaries
---------------------------------
To test the package with pre-release binaries, you must first set up your ROS2 workspace to use the ROS2 pre-release repositories.
To do this, follow the instructions
`here <https://docs.ros.org/en/rolling/Installation/Testing.html#debian-testing-repository>`_ .
After that, you can install the packages using the following command,

.. code-block:: console

$ sudo apt update
$ sudo apt install ros-<distro>-canopen # Replace <distro> with your ROS2 distro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ Setup CAN Controller
====================
.. _quick-start-setup-can-controller:

To interact with the CAN controller you can use ``can-utils`` in order to know the output of the controller.

.. code-block:: console

$ sudo apt install can-utils
$ candump

.. note::
This step is only required in order to know the output of the controller. One can skip this step to proceed with the setup of the controller.

**Option 1**: Virtual CANController

.. code-block:: console
Expand All @@ -11,6 +21,7 @@ Setup CAN Controller
$ sudo ip link set vcan0 txqueuelen 1000
$ sudo ip link set up vcan0


**Option 2**: Peak CANController

.. code-block:: console
Expand Down
10 changes: 10 additions & 0 deletions canopen/sphinx/user-guide/1_operation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Operations
==========

.. toctree::
:maxdepth: 1
:caption: Operation
:glob:

1_operation/1_operation_modes
1_operation/2_operation_interface
15 changes: 15 additions & 0 deletions canopen/sphinx/user-guide/2_interface.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Interfaces
==========


.. toctree::
:maxdepth: 1
:caption: Configuration
:glob:

2_interface/1_interface_overview
2_interface/2_master_interface
2_interface/3_proxy_interface
2_interface/4_cia402_interface
2_interface/5_ros2_control_interface
2_interface/6_ros2_controllers
11 changes: 11 additions & 0 deletions canopen/sphinx/user-guide/3_configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Configuration
==============

.. toctree::
:maxdepth: 1
:caption: Configuration
:glob:

3_configuration/1_bus_configuration
3_configuration/2_cmake_configuration
3_configuration/3_device_configuration
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bus Configuration
=================
2 changes: 2 additions & 0 deletions canopen/sphinx/user-guide/4_how_to_guide.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
How to create your own CANopen Package
======================================
Loading