ROS 进阶学习笔记(15) - Use Service to play ROS-Serial communication

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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值