Use Service to play ROS-Serial communication
Continue for this blog :ROS 进阶学习笔记(12) - Communication with ROS through USART Serial Port
In that blog above, we discussed ROS-Serial communication through r2serial_driver node (C++). There is a problem that the r2serial made too much cpu expenses. Like below:
Kevin mentioned a question: "Interesting, but a lot of my serial stuff is send a message and receive a response back. Instead of separate publish/subscribes. have you tried a service? That seems like it would work nicely for this."
I also noticed a problem: MY Linux's System RAM and CPU seems to be much costed by r2serial_driver when it is running.
This time, we'll see how to use Kevin's service to play ROS serial communication.
Use Service to play ROS-Serial communication
=============
-- Check out and compile this package --
Use this commands to check out the rosbuild package (rather than catkin package), androsmakethem:
exbot@my_robot:~/rosbuild_ws$ cd sandbox/ exbot@my_robot:~/rosbuild_ws/sandbox$ git clone https://github.com/walchko/serial_node exbot@my_robot:~/rosbuild_ws/sandbox$ cd serial_node/ exbot@my_robot:~/rosbuild_ws/sandbox/serial_node$ rosmake ... ... [ rosmake ] /home/exbot/.ros/rosmake/rosmake_output-20160511-173021 exbot@my_robot:~/rosbuild_ws/sandbox/serial_node$ rospack find serial_node /home/exbot/rosbuild_ws/sandbox/serial_node exbot@my_robot:~/rosbuild_ws/sandbox/serial_node$roscore && rosrun serial_node serial_node 0 /dev/ttyUSB0 9600 true [ INFO] [1462959095.157208573]: Service uc0_serial on /dev/ttyUSB0 @ 9600 baud
We can see the expense of serial_node by command "top": [ The expenses has been very small. ]
====================================================================================
-- How to use this service for our works --
1. Understand what is ros service:
- Here, I recommend the newer of ROS to read four links carefully and understand them as deep as you can:
- http://wiki.ros.org/ROS/Tutorials/UnderstandingServicesParams#Using_rosservice
Above, you need to understand the service_node need a request and will give back a response.
http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv#Using_srv
Above, you need to understand the .srv file defines the data type of req. and rep.
http://wiki.ros.org/ROS/Tutorials/WritingServiceClient%28c%2B%2B%29
Above, you need to understand the key points of a source code for an ROS Service node.
http://wiki.ros.org/ROS/Tutorials/ExaminingServiceClient
Above, describes the source code for client to examine if the service node works fine.
2. Read the source code of "serial_node_service.cpp" and use "rosservice call" command to test it
run the service by:
> $ rosrun seal_node serial_node 0 /dev/ttyUSB0 9600 true
call this service by (open another terminal):
> $ rosservi