ROS中使用catkin_make编译和上传arduino程序

17 篇文章 0 订阅
9 篇文章 2 订阅

步骤一:下载rosserial_arduino功能包

sudo apt-get install ros-melodic-rosserial-arduino

步骤二:下载和编译安装aduino-cmake (Tips:如果安装了rosserial就不用安装arduino-cmake了)

1、创建arduino_upload_ws工作空间:
cd ~
mkdir arduino_upload_ws/src -p
2、下载:
cd arduino_upload_ws
git clone https://github.com/queezythegreat/arduino-cmake.git
3、编译:
cd arduino-cmake
mkdir build
cmake ..
make

步骤三:为串口添加权限

cd /dev
sudo chmod 777 ttyACM*

步骤四:测试

cd ~/arduino_upload_ws/src
catkin_init_workspace
catkin_create_pkg helloworld rosserial_arduino rosserial_client std_msgs
cd helloworld
mkdir firmware
cd firemware
vim chatter.cpp

输入以下内容:

#include <ros.h>
#include <std_msgs/String.h>
//Arduino.h头文件,它包含了所有的Arduino函数(digitalRead, analogRead, delay, etc.)
#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);
}

接着创建CMakeLists.txt:

vim CMakeLists.txt

输入以下内容:

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 mega2560
  PORT /dev/ttyACM0
)

回到上一级目录,添加CMakeLists.txt:

cd ..
mv CMakeLists.txt CMakeLists.back
vim CMakeLists.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)
  • 1、编译:
cd ~/arduino_upload_ws
catkin_make helloworld_firmware_hello

在这里插入图片描述

  • 2、上传:
cd ~/arduino_upload_ws
catkin_make helloworld_firmware_hello-upload

在这里插入图片描述
成功!

---------------------------------------------------分界线-----------------------------------------------

*可能遇到的问题

1、{nullptr} was not declared in this scope

这个问题为开始一直搞不明白,后来发现三c++11的规则,所以只需要在对应包中加入c++11规则就可以了

例如helloworld这个功能包,需要改的地方就是firmware里的CMakeLists.txt:
原内容:

```bash
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 mega2560
  PORT /dev/ttyACM0
)

修改后:

cmake_minimum_required(VERSION 2.8.3)

include_directories(${ROS_LIB_DIR})
 #添加c++11的支持
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

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

generate_arduino_firmware(art_table_arduino
  SRCS Art_table_rosserial.cpp ${ROS_LIB_DIR}/time.cpp
  BOARD mega2560
  PORT /dev/ttyACM0
)

编译的时候最好是对单个烧写程序进行编译!所以我们这时编译使用的命令应该是:

catkin_make helloworld_firmware_hello

成功!

2、有可能遇到的rosserial问题

创建的工作空间在有rosserial功能包的情况下最好先单独编译rosserial然后再单独编译arduino烧写程序!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JR_Sim

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值