Difference between revisions of "Advantech Robotic Suite/Modbus-Master Node"
(19 intermediate revisions by 3 users not shown) | |||
Line 3: | Line 3: | ||
Modbus enables communication among many devices connected to the same network, for example, a system that measures temperature and humidity and communicates the results to a computer. Modbus is often used to connect a supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems. | Modbus enables communication among many devices connected to the same network, for example, a system that measures temperature and humidity and communicates the results to a computer. Modbus is often used to connect a supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems. | ||
− | |||
− | Modbus-Master Node is a ROS node for user to subscribe | + | Many of the data types are named from its use in driving relays: a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or a contact. Modbus provide word data types for the number value are named register: a word value for read/write is called a holding register, and a word value for input is called a input register. |
+ | |||
+ | |||
+ | Modbus-Master Node is a ROS node, it can be set to access data form Modbus server and provide ROS2 DDS topic for user to subscribe, user can quickly receive Modbus data and do the post data process, for example data parse/store/analysis etc. Below chapter will introduce you about how to use Modbus-Master Node. | ||
<br/><br/> | <br/><br/> | ||
Line 20: | Line 22: | ||
The messages definition of SUSI node is defined in below link: | The messages definition of SUSI node is defined in below link: | ||
− | http://ess-wiki.advantech.com.tw/view/ | + | http://ess-wiki.advantech.com.tw/view/Advantech_Robotic_Suite/Advantech_ROS2_Data_Format |
<br/> | <br/> | ||
Line 34: | Line 36: | ||
The message is updated periodically, you can use ROS2 utility to verify the data update: | The message is updated periodically, you can use ROS2 utility to verify the data update: | ||
− | ==== Subscribe Sensor ==== | + | ==== Subscribe Sensor using ROS2 utility ==== |
− | Step1. Setup ROS2 | + | Step1. Setup ROS2 environmant variables: |
− | <pre>$ source /opt/ros/ | + | <pre>$ source /opt/ros/${ROS_DISTRO}/setup.bash</pre> |
− | Step2. Setup | + | Step2. Setup ROS2 Modbus-master node message: |
− | <pre>$ source /usr/local/Advantech/ros/ | + | <pre>$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash</pre> |
Step3. List all topics: | Step3. List all topics: | ||
Line 84: | Line 86: | ||
--- | --- | ||
</pre> | </pre> | ||
− | |||
= Sample Client = | = Sample Client = | ||
Line 99: | Line 100: | ||
'''Steps - Subscribe Sensor''' | '''Steps - Subscribe Sensor''' | ||
− | Step1. Setup ROS2 | + | Step1. Setup ROS2 environmant variables, replace ${ROS_DISTRO} with your ROS2 distribution (foxy, humble) to run this command: |
− | <pre>$ source /opt/ros/ | + | <pre>$ source /opt/ros/${ROS_DISTRO}/setup.bash</pre> |
− | Step2. Setup | + | Step2. Setup Modbus-Master node message: |
− | <pre>$ source /usr/local/Advantech/ros/ | + | <pre>$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash</pre> |
Step3. Go to node.js Modbus-Master node sample client path: | Step3. Go to node.js Modbus-Master node sample client path: | ||
− | <pre>$ cd /usr/local/Advantech/ros/ | + | <pre>$ cd /usr/local/Advantech/ros/${ROS_DISTRO}/sample_code/edge-data-client/rclnodejs_edge_data_client/</pre> |
Step4. Run node.js Modbus-Master client: | Step4. Run node.js Modbus-Master client: | ||
Line 143: | Line 144: | ||
This session describe how to set Modbus data by set action. To run the set sensor sample, your device need have writable sensor supported for Modbus driver. | This session describe how to set Modbus data by set action. To run the set sensor sample, your device need have writable sensor supported for Modbus driver. | ||
− | Step1. Setup ROS2 | + | Step1. Setup ROS2 environmant variables, replace ${ROS_DISTRO} with your ROS2 distribution (foxy, humble) to run this command: |
− | <pre>$ source /opt/ros/ | + | <pre>$ source /opt/ros/${ROS_DISTRO}/setup.bash</pre> |
− | Step2. Setup | + | Step2. Setup Modbus-Master node message: |
− | <pre>$ source /usr/local/Advantech/ros/ | + | <pre>$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash</pre> |
Step3. Go to node.js Modbus-Master node sample client path: | Step3. Go to node.js Modbus-Master node sample client path: | ||
− | <pre>$ cd /usr/local/Advantech/ros/ | + | <pre>$ cd /usr/local/Advantech/ros/${ROS_DISTRO}/sample_code/edge-data-client/rclnodejs_edge_data_client/</pre> |
Step4. Run Modbus-Master node set sensor client: | Step4. Run Modbus-Master node set sensor client: | ||
Line 176: | Line 177: | ||
'''Steps - Subscribe Sensor''' | '''Steps - Subscribe Sensor''' | ||
− | Step1. Setup ROS2 | + | Step1. Setup ROS2 environmant variables, replace ${ROS_DISTRO} with your ROS2 distribution (foxy, humble) to run this command: |
− | <pre>$ source /opt/ros/ | + | <pre>$ source /opt/ros/${ROS_DISTRO}/setup.bash</pre> |
− | Step2. Setup | + | Step2. Setup Modbus-Master node message: |
− | <pre>$ source /usr/local/Advantech/ros/ | + | <pre>$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash</pre> |
Step3. Setup Modbus-Master client: | Step3. Setup Modbus-Master client: | ||
− | <pre>$ source /usr/local/Advantech/ros/ | + | <pre>$ source /usr/local/Advantech/ros/${ROS_DISTRO}/sample_code/edge-data-client/install/local_setup.bash</pre> |
Step4. Run Python Modbus-Master client: | Step4. Run Python Modbus-Master client: | ||
Line 221: | Line 222: | ||
'''Steps - Subscribe Sensor''' | '''Steps - Subscribe Sensor''' | ||
− | Step1. Setup ROS2 | + | Step1. Setup ROS2 environmant variables, replace ${ROS_DISTRO} with your ROS2 distribution (foxy, humble) to run this command: |
− | <pre>$ source /opt/ros/ | + | <pre>$ source /opt/ros/${ROS_DISTRO}/setup.bash</pre> |
− | Step2. Setup | + | Step2. Setup Modbus-Master Node message: |
− | <pre>$ source /usr/local/Advantech/ros/ | + | <pre>$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash</pre> |
Step3. Setup Modbus-Master client: | Step3. Setup Modbus-Master client: | ||
− | <pre>$ source /usr/local/Advantech/ros/ | + | <pre>$ source /usr/local/Advantech/ros/${ROS_DISTRO}/sample_code/edge-data-client/install/local_setup.bash</pre> |
Step4. Run Python Modbus-Master client: | Step4. Run Python Modbus-Master client: | ||
Line 257: | Line 258: | ||
Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 | Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 | ||
</pre> | </pre> | ||
− | |||
− |
Latest revision as of 04:15, 5 March 2024
Contents
Brief
Modbus enables communication among many devices connected to the same network, for example, a system that measures temperature and humidity and communicates the results to a computer. Modbus is often used to connect a supervisory computer with a remote terminal unit (RTU) in supervisory control and data acquisition (SCADA) systems.
Many of the data types are named from its use in driving relays: a single-bit physical output is called a coil, and a single-bit physical input is called a discrete input or a contact. Modbus provide word data types for the number value are named register: a word value for read/write is called a holding register, and a word value for input is called a input register.
Modbus-Master Node is a ROS node, it can be set to access data form Modbus server and provide ROS2 DDS topic for user to subscribe, user can quickly receive Modbus data and do the post data process, for example data parse/store/analysis etc. Below chapter will introduce you about how to use Modbus-Master Node.
Topic definition
The topic of Modbus-Master data are defined as below:
/adv/modbusmaster
Message definition
The messages definition of SUSI node is defined in below link:
http://ess-wiki.advantech.com.tw/view/Advantech_Robotic_Suite/Advantech_ROS2_Data_Format
Configuration
To config Modbus settings, please refer the guide: http://ess-wiki.advantech.com.tw/view/Modbus_Master#Configuration
Message update
The message is updated periodically, you can use ROS2 utility to verify the data update:
Subscribe Sensor using ROS2 utility
Step1. Setup ROS2 environmant variables:
$ source /opt/ros/${ROS_DISTRO}/setup.bash
Step2. Setup ROS2 Modbus-master node message:
$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash
Step3. List all topics:
$ ros2 topic list
output:
/adv/parameter_events /adv/modbusmaster /parameter_events /rosout
Step4. Subscribe node data
$ ros2 topic echo /adv/modbusmaster
output:
--- sensor: Modbus-Master/Device/Sensor-Device-1/Sensor/Temperature type: v bv: false v: 16.0 sv: '' ts: 1677660801212 --- sensor: Modbus-Master/Device/Sensor-Device-1/Sensor/Door-Open type: bv bv: false v: 0.0 sv: '' ts: 1677660802511 --- sensor: Modbus-Master/Device/Sensor-Device-1/Sensor/FAN-Speed type: v bv: false v: 2636.0 sv: '' ts: 1677660803055 ---
Sample Client
This session describe how to subscribe Modbus-Master node data by node's topic.
Node.js
The program rclnodejs_edge_data_client is a node.js example for user to learning how to use rclnodejs client to subscribe Modbus-Master node's data. Please follow below steps to run the program, when the program launched, it will subscribe Modbus-Master node's sensor data and print the data in the console screen.
Steps - Subscribe Sensor
Step1. Setup ROS2 environmant variables, replace ${ROS_DISTRO} with your ROS2 distribution (foxy, humble) to run this command:
$ source /opt/ros/${ROS_DISTRO}/setup.bash
Step2. Setup Modbus-Master node message:
$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash
Step3. Go to node.js Modbus-Master node sample client path:
$ cd /usr/local/Advantech/ros/${ROS_DISTRO}/sample_code/edge-data-client/rclnodejs_edge_data_client/
Step4. Run node.js Modbus-Master client:
$ node example_SubscribeSensor.js "rclnodejs_ModbusMaster_subscriber" "/adv/modbusmaster"
Step5. Verify received data:
You have entered arguments: node name: rclnodejs_ModbusMaster_subscriber message topic: /adv/modbusmaster ---------------------------------------------- Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Temperature", v = 21.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Door-Open", v = 1.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/FAN-Speed", v = 2814.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Humidity", v = 44.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Light-Switch", v = 0.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00
Steps - Set sensor
This session describe how to set Modbus data by set action. To run the set sensor sample, your device need have writable sensor supported for Modbus driver.
Step1. Setup ROS2 environmant variables, replace ${ROS_DISTRO} with your ROS2 distribution (foxy, humble) to run this command:
$ source /opt/ros/${ROS_DISTRO}/setup.bash
Step2. Setup Modbus-Master node message:
$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash
Step3. Go to node.js Modbus-Master node sample client path:
$ cd /usr/local/Advantech/ros/${ROS_DISTRO}/sample_code/edge-data-client/rclnodejs_edge_data_client/
Step4. Run Modbus-Master node set sensor client:
Command:
node example_SetSensor.js [node name] [action] [sensor] [type] [value]
Example:
$ node example_SetSensor.js "rclnodejs_ModbusMaster_setter" "adv_modbusmaster_set" "Modbus-Master/Device/Sensor-Device-1/Sensor/FAN-Speed" "v" 3000
Step5. Received data:
[INFO] [1671431728.320213435] [adv.rclnodejs_ModbusMaster_setter]: Waiting for action server... [INFO] [1671431729.034446428] [adv.rclnodejs_ModbusMaster_setter]: Sending goal request... [INFO] [1671431729.384845693] [adv.rclnodejs_ModbusMaster_setter]: Goal accepted [INFO] [1671431729.774134098] [adv.rclnodejs_ModbusMaster_setter]: Goal suceeded with result: 202
Python
The program rclpy_edge_data_client is a Python client example for user to understand how to use rclpy to subscribe Modbus-Master node's data. Please follow below steps to run the program, when the program launched, it will subscribe Modbus-Master node's sensor and print the data in the console screen.
Steps - Subscribe Sensor
Step1. Setup ROS2 environmant variables, replace ${ROS_DISTRO} with your ROS2 distribution (foxy, humble) to run this command:
$ source /opt/ros/${ROS_DISTRO}/setup.bash
Step2. Setup Modbus-Master node message:
$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash
Step3. Setup Modbus-Master client:
$ source /usr/local/Advantech/ros/${ROS_DISTRO}/sample_code/edge-data-client/install/local_setup.bash
Step4. Run Python Modbus-Master client:
$ ros2 run rclpy_edge_data_client listener "rclpy_ModbusMaster_subscriber" "/adv/modbusmaster"
Step5. Verify received data:
You have entered arguments: node name: rclpy_ModbusMaster_subscriber message topic: /adv/modbusmaster ---------------------------------------------- Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Temperature", v = 21.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Door-Open", v = 1.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/FAN-Speed", v = 2814.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Humidity", v = 44.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Light-Switch", v = 0.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00
C++
The program rclcpp_susicontrol_client is a C++ example for user to understand how to use rclcpp to subscribe SUSI node's data. Please follow below steps to run the program, when the program launched, it will subscribe SUSI node's sensor and print the data in the console screen.
Steps - Subscribe Sensor
Step1. Setup ROS2 environmant variables, replace ${ROS_DISTRO} with your ROS2 distribution (foxy, humble) to run this command:
$ source /opt/ros/${ROS_DISTRO}/setup.bash
Step2. Setup Modbus-Master Node message:
$ source /usr/local/Advantech/ros/${ROS_DISTRO}/include/edge-converter-ros2/adv_msgs/install/local_setup.bash
Step3. Setup Modbus-Master client:
$ source /usr/local/Advantech/ros/${ROS_DISTRO}/sample_code/edge-data-client/install/local_setup.bash
Step4. Run Python Modbus-Master client:
$ ros2 run rclcpp_edge_data_client listener "rclcpp_ModbusMaster_subscriber" "/adv/modbusmaster"
Step5. Verify received data:
You have entered arguments: node name: rclcpp_ModbusMaster_subscriber message topic: /adv/modbusmaster ---------------------------------------------- Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Temperature", v = 21.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Door-Open", v = 1.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/FAN-Speed", v = 2814.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Humidity", v = 44.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00 Data: sensor = "Modbus-Master/Device/Sensor-Device-1/Sensor/Light-Switch", v = 0.00 Data: sensor = "Modbus-Master/Link/Net1/Message", sv = "Link connected" Data: sensor = "Modbus-Master/Link/Net1/Status", v = 1.00