arduino - ROSSerial 无法与 ROS Noetic 上的 teensy 设备同步
问题描述
我在 RASPI4 上使用 teensy 和 rosserial + ROS Noetic/Ubuntu 20.04。teensy 代码是在 platformio ( https://platformio.org/lib/show/5526/... ) 上使用 ros_lib 实现的。该程序编译良好并在端口上成功上传/dev/ttyACM0
。但是,当我这样做时,我rosrun rossserial_python serial_node.py _port:=/dev/ttyACM0 _baud:=500000
会收到同步失败错误。
[错误] [1612795964.166906]:无法与设备同步;可能的链接问题或链接软件版本不匹配,例如 Hydro rosserial_python 与 groovy Arduino。
我已经尝试过的事情:
a) 设置正确的波特率Serial.begin(500000)
b) 禁用所有Serial.begin
和Serial.print
语句
nh.gethardware()->setbaud(500000)
c)之前设置ros节点的波特率nh.init()
d) 将 ros_lib 的 ros.h 中的默认缓冲区大小增加到 1024
typedef NodeHandle_<arduinohardware, 10,="" 10,="" 1024,="" 1024=""> NodeHandle;
e) 尝试了 Arduino 板而不是 Teensy,问题仍然存在。
然而,到目前为止,没有任何效果。
解决方案
rosserial 的默认波特率为 56700。要更改它,您需要执行以下操作
修改arduino代码中的include语句
#include <ros.h>
至
#include "ros.h"
在 .ino/.pde 文件旁边添加以下头文件
罗斯.h
#ifndef _ROS_H_
#define _ROS_H_
#include "ros/node_handle.h"
#include "ArduinoHardware.h"
namespace ros
{
typedef NodeHandle_<ArduinoHardware> NodeHandle;
}
#endif
ArduinoHardware.h
#ifndef ROS_ARDUINO_HARDWARE_H_
#define ROS_ARDUINO_HARDWARE_H_
#if ARDUINO>=100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <HardwareSerial.h>
#define SERIAL_CLASS HardwareSerial
class ArduinoHardware
{
public:
ArduinoHardware()
{
iostream = &Serial;
baud_ = 500000;
}
void setBaud(long baud)
{
this->baud_= baud;
}
int getBaud()
{
return baud_;
}
void init()
{
iostream->begin(baud_);
}
int read()
{
return iostream->read();
};
void write(uint8_t* data, int length)
{
for(int i=0; i<length; i++)
{
iostream->write(data[i]);
}
}
unsigned long time()
{
return millis();
}
protected:
SERIAL_CLASS* iostream;
long baud_;
};
#endif
在我们在上面定义的 iostream 的 ArduinoHeader.h 文件中,使用如下所示的构造函数设置要使用的波特率
ArduinoHardware()
{
iostream = &Serial;
baud_ = 500000;
}
当您使用 teensy 和 USB 时,iostream 将是Serial
. 如果您使用的是引脚而不是 USB,它会有所不同,Serial1
如此处Serial8
所述。通过将此处设置为 500000可以改变 teensy 的波特率。baud_
推荐阅读
- c# - [] 内的索引数量错误,预期为 5
- vue.js - OnChange 传递 item-text 和 item-value Vuetify
- webpack - Webpack 带有 babel 加载器的多个预设以及键值对
- c++ - 如何触发 EPOLLIN 和 EPOLLOUT 事件?
- python - 如何使用 docker SDK for python 获取 docker 容器的 IP 地址?
- kubernetes - 由于缺少服务令牌,kube-scheduler 的 CrashLoopBackOff
- javascript - 递归地将 JavaScript 对象拟合到特定结构
- spring-boot - 如何使用 Spring boot keycloak 适配器 + spring security 强制更新 oAuth 令牌(访问令牌 + 刷新令牌)。?
- excel - 如何获取 Excel 生成的电子邮件以使用单元格值自动填充主题?
- xcode - 在 UserDefaults 中存储/检索结构的可编码字典对我不起作用