ros 在 arduino 上的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010918541/article/details/84205033

安装

原文地址 http://wiki.ros.org/rosserial/
教程 http://wiki.ros.org/rosserial_arduino/Tutorials
$sudo apt-get install ros-indigo-rosserial-arduino
$sudo apt-get install ros-indigo-rosserial

1,下载 arduino for linux

https://www.arduino.cc/en/Main/Software

2,下载rosserial

cd /src
git clone https://github.com/ros-drivers/rosserial.git
cd
catkin_make

3,进入arduino 的examples 文件夹

执行以下命令
注意最后的" . "符号
$rosrun rosserial_arduino make_libraries.py .
这样子会生成例子

4,选择例子进行编译

如果编译不通过则再次安装roslib的库for Arduino
在arduino的菜单栏 选择工具 管理库
搜索rosserial 安装
然后安装成功,就可以编译了,编译之后下载

5 不使用arduino IDE 进行编译 直接使用catkin_make 进行编译下载

5.1 在工作空间创建ros包

$catkin_create_pkg helloworld rosserial_arduino rosserial_client std_msgs

5.2 在包里面创建 firmware 文件夹,并创建chatter.cpp

写入

#include <ros.h>
#include <std_msgs/String.h>

#include <Arduino.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);
}

5.3 编辑包下面的Cmakelist.txt

cmake_minimum_required(VERSION 2.8.3)
project(helloworld)

find_package(catkin REQUIRED COMPONENTS
 rosserial_arduino
 rosserial_client
)

catkin_package()

rosserial_generate_ros_lib(
 PACKAGE rosserial_arduino
 SCRIPT make_libraries.py
)

rosserial_configure_client(
 DIRECTORY firmware
 TOOLCHAIN_FILE ${ROSSERIAL_ARDUINO_TOOLCHAIN}
)

rosserial_add_client_target(firmware hello ALL)
rosserial_add_client_target(firmware hello-upload)

然后在firmware 中也创建一个Cmakelist.txt
写入,这里可以更改成为其他的 比如 mega2560 和串口也可以更改

cmake_minimum_required(VERSION 2.8.3)

include_directories(${ROS_LIB_DIR})

#Remove this if using an Arduino without native USB (eg, other than Leonardo)
add_definitions(-DUSB_CON)

generate_arduino_firmware(hello
 SRCS chatter.cpp ${ROS_LIB_DIR}/time.cpp
 BOARD leonardo
 PORT /dev/ttyACM0
)

5.4 回到工作空间中 编译固件

$catkin_make helloworld_firmware_hello

5.5 上传固件

$catkin_make helloworld_firmware_hello-upload

5.6 测试

$roscore
$rosrun rosserial_python serial_node.py /dev/ttyACM0
$rostopic echo chatter

猜你喜欢

转载自blog.csdn.net/u010918541/article/details/84205033
今日推荐