rcruzoliver_1-1721223173811.png

SDK - Shared memory communication between ROS2, Datalayer and PLC

rcruzoliver
Long-established Member

In this how-to we present an example to make information flow from a ROS2 topic stream to PLC and vice versa, via the datalayer, using shared memory as communication mechanism. 

1. System architecture

The example 'system architecture' is depicted in the next figure.

System architectureSystem architecture

There are two devices:

  • External device: In this case it is a desktop device running a ROS2 application.
  • ctrlX CORE: It contains the ROS2 runtime and ROS2 apps, as well as the official Rexroth PLC app.

These two devices are connected in the same Local Network (LAN) to allow the ROS2 DDS discovery to read-write the necessary information.

The information flows in the following way:

  1. A ROS2 application running in the Desktop device publishes a topic stream under /test_vector3 at 200Hz. It contains a message of type geometry_msgs/msg/Vector3.
  2. A ROS2 node (shm_dl_subscriber) encapsulated into the ros2-listener-shm-dl app, subscribes to the /test_vector3 topic, writing the information further into the datalayer using shared memory.

    ROS2 input nodeROS2 input node
  3. This information is then retrieved by the PLC and mapped into a global variable.

    PLC input mappingPLC input mapping
  4. Some computation happens in the PLC logic, with a cycle time of 5ms (200Hz). In this case a simply copy of the input variable into another variable (that will be mapped to the output).

    PLC programPLC program
  5. The Rexroth PLC app has the functionality to create a location in the datalayer and write memory there, using shared memory. Given this, the output variable is mapped to that location in the datalayer.PLC output mapPLC output mapPLC location in datalayerPLC location in datalayer
  6. The location in datalayer created by the PLC app is read by a ROS2 Node (shm_dl_publisher) encapsulated in the ros2-talker-shm-dl app. This node publishes under the topic /PLC_output the information that is read from the datalayer, at 200Hz because it is the frequency to which the information arrives.
  7. The topic stream /PLC_output, which by the way is of the same type as /test_vector3 could be subscribed by another ROS2 program and do further computations with it.
2. Desploymente tests

This exampe has been successfully deployed in ctrlX CORE X3, X7 and virtual, in all of them with a spinning frequency of 200Hz.

In the next picture we can observe a plot of the topics /test_vector3 and /PLC_output.

Plot of the topics /test_vector3 and /PLC_outputPlot of the topics /test_vector3 and /PLC_output

When looking at the detailed statistics we see a delay of 5ms between /PLC_output and /test_vector3, which is indeed the PLC computation cycle time, being this phenomenon the exactly expected behavior that should be observed.

3. Solution potential

This example shows that a shared memory on the datalayer is an effective strategy to achieve a fast communication between apps running in the ctrlX CORE.
This is critical in real-time applications, in which information streams must flow at high rates. Examples of solutions that demands this would be for instance robotic arms or AGV control, where information between a ROS2 algorithm and a PLC program must be shared.


If you are interested in an application like this one, do not hesitate to leave a comment! We are sure your application will find the perfect match.

rcruzoliver
rcruzoliver
Enhancing ctrlX platform with solutions. Everything can be snapcrafted! Robotics specialist, ask me anything about ROS2 and ctrlX OS.
Must Read
Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist