Ubuntu16.04LTS 下ros(kinetic)的arduino应用(二)
来源:互联网 发布:centos 6.7安装mysql 编辑:程序博客网 时间:2024/05/01 01:25
Ubuntu 16.04下arduino示例ros_lib例程Hello world
介绍:
- 该文主要讲述如何通过rosserial创建publisher(发布者)
- 使用历程为应用(一)中Arduino IDE 文件->示例->ros_lib->HelloWorld
示例中的代码如下:
/* * rosserial Publisher Example * Prints "hello world!" */#include <ros.h> //包含了标准ROS类的声明#include <std_msgs/String.h> //包含消息头文件ros::NodeHandle nh; /*(节点句柄)对象是你的程序用于和ROS系统交互的主要机制。创建此对象会将你的程序注册为ROS节点管理器的节点。最简单的方法就是在整个程序中只创建一个NodeHandle对象*/std_msgs::String str_msg; //定义变量str_msg且消息类型为std_msgs::Stringros::Publisher chatter("chatter", &str_msg);/*实例化一个发布,名为chatter,赋值到变量str_msg*/char hello[13] = "hello world!"; //定义字符型数组void setup() //Arduino的Setup函数,用于初始化ROS节点处理,并宣告所有的发布或订阅{ nh.initNode(); nh.advertise(chatter);}void loop() //在Arduino的loop函数,定义发布的内容,并调用nh.spinOnce(),这样所有的ROS回调函数就会被处理。{ str_msg.data = hello; chatter.publish( &str_msg ); nh.spinOnce(); delay(1000);}
代码下载:
- 将arduino开发板通过串口与电脑连接,点击Arduino IDE 文件->下载
运行代码:
1.打开终端,输入如下:
$ roscore
2.打开另一个终端,输入如下:
$ rosrun rosserial_python serial_node.py /dev/ttyACM0
或
$ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0
3.打开另一个终端,输入如下代码,显示主题chatter,获取Arduino板反馈的信息
$ rostopic echo chatter
FAQ(常见问题)
运行代码:
$ rosrun rosserial_python serial_node.py /dev/ttyACM0
终端显示如下错误:
$ [INFO] [WallTime: 1399983521.604184] ROS Serial Python Node $ [INFO] [WallTime: 1399983521.617853] Connecting to /dev/ttyACM0 at 57600 baud $ [ERROR] [WallTime: 1399983538.726124] Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
解决办法如下:修改原程序
#define USE_USBCON#include <ros.h>
- 即在头文件前添加#define USE_USBCON;
- 原因如下:
打开sketchbook/libraries/ros_lib目录下的”Arduinohardware.h”
以下为该文件内容的部分截取,请见注释部分
#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__) #if defined(USE_TEENSY_HW_SERIAL) #define SERIAL_CLASS HardwareSerial // Teensy HW Serial #else #include <usb_serial.h> // Teensy 3.0 and 3.1 #define SERIAL_CLASS usb_serial_class #endif#elif defined(_SAM3XA_) #include <UARTClass.h> // Arduino Due #define SERIAL_CLASS UARTClass/*#elif defined(USE_USBCON) // Arduino Leonardo USB Serial Port #define SERIAL_CLASS Serial_*/#else #include <HardwareSerial.h> // Arduino AVR #define SERIAL_CLASS HardwareSerial#endif
- PS:我们可以自己根据硬件设备,指定对应的连接类型。我用的是Leonardo型的Arduino。
上述内容为本人参考下方链接并结合自身操作所遇问题,对前者进行了相关补充,由于编者水平有限,如有错误,还请指出。
参考链接:> http://www.ncnynl.com/archives/201610/919.html
阅读全文
1 0
- Ubuntu16.04LTS 下ros(kinetic)的arduino应用(二)
- Ubuntu16.04LTS 下ros(kinetic)的arduino应用(一)
- Ubuntu16.04LTS 下ros(kinetic)的arduino应用(三)
- Ubuntu16.04LTS 下ros(kinetic)的arduino应用(四)
- Ubuntu16.04LTS 下ros(kinetic)的arduino应用(五)
- Ubuntu16.04 LTS 安装 ros kinetic
- Ubuntu16.04--ROS--kinetic
- Ubuntu16.04安装ROS kinetic
- Ubuntu16.04安装ROS Kinetic
- ROS配置<一>:Ubuntu16.04下安装Kinetic
- Nvidia TX1安装 Ubuntu16.04LTS+ROS Kinetic版本+turtlebot 完整篇
- Ubuntu16.04 ROS kinetic 版本的rivz教程
- SLAM: Ubuntu16.04安装ROS-kinetic
- opencv2.4.13+ros kinetic +ubuntu16.04+iai_kinect2
- ROS Kinetic系统在ubuntu16.04配置
- ubuntu16.04 ROS-kinetic环境搭建
- Ubuntu16.04中安装ROS Kinetic
- ubuntu16.10上的ROS Kinetic和ubuntu14.04上的ROS Jade的通讯设置
- codeforces刷题方法
- 命令ps查看当前系统的进程状态
- React基本使用(引用版)
- Linux命令(31)——find命令
- 命令netstat查看网络状态
- Ubuntu16.04LTS 下ros(kinetic)的arduino应用(二)
- 日常运维-2
- 循环嵌套里关于赋值的小坑
- php数据类型
- 程序员工资多高才算高?
- CocoaPods删除已安装的库
- shiro 学习日记1
- 抓包工具
- 爬格子呀--一堆东西