正在加载图片...
Ct+N Open. ⊙ 05e Ctrl+w 2Digtal Ctrl+S 3Analog Save As Ctl+Shit+S 4.Communication Ctr+U 5.Control Page Setup Curl+P 7.Diiplay Ctrl+Comma 8.Strnge Ctrl+Q Arduinoisp 月h-v(chater) ArduinoTest Suite oid lomp "button exam EEPROM ·o过6tet nce(): m 1y(1000]1 me test 代码如下。其中包含的头文件ros.h实际上是我们复制进去的rosserial类库。另外这个程 序里创建了一个名为chatter的类型为std msgs/String的topic #include <ros.h> #include <std_msgs/String.h> ros::NodeHandle nh; std msgs::String str_msg; ros::Publisher chatter("chatter",&str msg); char hello[19]="chapter4 tutorials"; void setup() nh.initNode(); nh.advertise(chatter): } void loop(){ str_msg.data=hello; chatter.publish(&str_msg ) nh.spinOnce(); delay(1000); } 现在我们可以创建一个node来监听这个串口端口,并且将Arduino发出的这个topic发送 到ROS的网络中。首先运行roscore,然后运行以下命令 S rosrun rosserial_python serial_node.py /dev/ttyUSBO 利用rostopic echot命令查看Arduino发出的名为chatter的topic S rostopic echo chatter 可以在终端中开发输出内容为 data:chapter4 tutorials 通过这个方法我们就可以将Ardunio中的数据,可以是其采集到的各种传感器数据等, 发送到ROS网络。 -9-- 9 - 代码如下。其中包含的头文件ros.h实际上是我们复制进去的rosserial类库。另外这个程 序里创建了一个名为chatter的类型为std_msgs/String的topic #include <ros.h> #include <std_msgs/String.h> ros::NodeHandle nh; std_msgs::String str_msg; ros::Publisher chatter("chatter", &str_msg); char hello[19] = "chapter4_tutorials"; void setup() { nh.initNode(); nh.advertise(chatter); } void loop() { str_msg.data = hello; chatter.publish( &str_msg ); nh.spinOnce(); delay(1000); } 现在我们可以创建一个node来监听这个串口端口,并且将Arduino发出的这个topic发送 到ROS的网络中。首先运行roscore,然后运行以下命令 $ rosrun rosserial_python serial_node.py /dev/ttyUSB0 利用rostopic echo命令查看Arduino发出的名为chatter的topic $ rostopic echo chatter
 可以在终端中开发输出内容为 data: chapter4_tutorials 通过这个方法我们就可以将Ardunio中的数据,可以是其采集到的各种传感器数据等, 发送到ROS网络
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有