arduino
sudo apt-get remove brltty
/* * rosserial Publisher Example * Prints "hello world!" */ #include <ros.h> #include <std_msgs/String.h> ros::NodeHandle nh; std_msgs::String str_msg; ros::Publisher chatter("chatter", &str_msg); char hello[13] = "hello world!"; void setup() { nh.initNode(); nh.advertise(chatter); } void loop() { str_msg.data = hello; chatter.publish( &str_msg ); nh.spinOnce(); delay(1000); }
#include <ros.h> #include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg; ros::Publisher chatter("chatter", &str_msg);
void setup() { nh.initNode(); nh.advertise(chatter); }
void loop() { str_msg.data = hello; chatter.publish( &str_msg ); nh.spinOnce(); delay(1000); }
最后在loop函数中,节点在chatter话题上发布了消息“hello world”,并且调用了ros::spinOnce(),也就是说所有ROS通信的回调都被处理。
在arduino IDE中,点击upload运行程序。接着运行roscore:
roscore
rosrun rosserial_python serial_node.py /dev/ttyACM0
rostopic echo chatter