我使用的是Arduino Due, 板子插上后, 打开Arduino IDE, 提示需要安装Arduino Due的Library, 安装就可以了. 安装ros_lib到Arduino开发环境:
# cd <sketchbook>/libraries cd '/home/dq/Arduino/libraries' rm -rf ros_lib rosrun rosserial_arduino make_libraries.py .串口连接是需要许可的, 不然不能下载程序, 方法参考 Serial port permissions :
As normal user from terminal: ls -l /dev/ttyUSB* or ls -l /dev/ttyACM* You will get something like crw-rw---- 1 root uucp 188, 0 5 apr 23.01 ttyUSB0 or crw-rw---- 1 root dialout 188, 0 5 apr 23.01 ttyACM0 The “0” might be a different number, or multiple entries might be returned. In the first case the data we need is uucp, in the second dialout. (this is the group owner of the file) Now we just need to add our user to the group: usermod -a -G group-name username group-name is the data found before, and username is your Linux user name. You will need to log out and in again for this change to take effect.
我的是ttyACM0, 所以 sudo usermod -a -G dialout wf 就可以了(wf是我的用户名), 注销然后重新登录. Arduino ROS HelloWorld的代码:
#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); }这个不行的, 按照步骤走下去会报错:
Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
参考 rosserial arduino can’t connect 中的方法: 在 #include <ros.h> 前面加上 #define USE_USBCON 才可以. 工具中选择 开发板为Arduino Due, 端口选ttyACM0, 下载到Arduino板中. 三个终端分别输入下面3条命令:
roscore rosrun rosserial_python serial_node.py /dev/ttyACM0 rostopic echo chatter这样就好了: