标签:out topic cmd from pre should pytho stop tno
从ROS端如果要发送消息给mbed, 聪明的我知道了, 估计要用订阅者, 让mbed去订阅一个制定的topic, 问题来了, 能否订阅两个topic? 稍后再试.
mbed上面是这样的:
#include "mbed.h" #include <ros.h> #include <std_msgs/UInt16.h> ros::NodeHandle nh; //Servo servo(D8); DigitalOut myled(LED1); void servo_cb( const std_msgs::UInt16& cmd_msg) { //servo.position(cmd_msg.data); //set servo angle, should be from 0-180 myled = !myled; //toggle led } ros::Subscriber<std_msgs::UInt16> sub("servo", servo_cb); int main() { nh.initNode(); nh.subscribe(sub); while (1) { nh.spinOnce(); wait_ms(1); } }
ros这边:
$ roscore $ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0 $ rostopic pub servo std_msgs/UInt16 <angle>
测试了一下, 多个订阅者也是ok的, 不过会不会在ROS端看起来比较乱?
标签:out topic cmd from pre should pytho stop tno
原文地址:http://www.cnblogs.com/Montauk/p/6962485.html