# ros2wd **Repository Path**: stefantasy/ros2wd ## Basic Information - **Project Name**: ros2wd - **Description**: ROS差速控制板源码,arduino代码+上位机ROS代码 ,硬件是Arduino nano+ tb6612电机驱动+AB相编码器电机 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2021-04-16 - **Last Updated**: 2024-12-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Ros Arduino Bridge -------- ### 系统支持 * 在ros indigo,ros kinetic,ros melodic都可以正常使用 ### 文件目录 - install_udev.sh 用来给usb设备 一键创建udev规则 - README_en.md 原版readme - README .md 中文简易readme - ros_arduino_bridge 空包 - ros_arduino_firmware 下位机arduino代码 - ros_arduino_msgs 消息和服务文件功能包 - ros_arduino_python 上位机功能包 ## 功能 - 上位机通过读取下位机编码器数值计算发布odom历程消息话题 ,订阅cmd _vel话题,解析成串口数据发给下位机。 - 可以通过服务控制arduino上的引脚的,输入输出,以及读取数字和模拟值 - 可以通过上位机控制底盘的舵机。 ## 安装 - 确保安装了python-serial串口通信包 $ sudo apt-get install python-serial - 给下位机下载固件 通过arduino IDE给arduino下载固件。 - 创建usb设备udev规则 - 插上arduino查看设备号 $ lsusb Bus 001 Device 006: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter - 创建一个 arduino.rules的文件,并编写udev规则如下 KERNEL=="ttyUSB*", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE:="0666", GROUP:="dialout", SYMLINK+="arduino" - 拷贝udev规则到对应目录 $ sudo cp arduino.rules /etc/udev/rules.d - 重启,使udev规则生效(笨办法) - 检查是否生效 ls /dev/arduino - 编译工作空间 - 创建工作空间 mkdir -p robot_ws/src - 进入src目录,拷贝代码到src目录 cd ~/robot_ws/src git clone https://gitee.com/stefantasy/ros2wd.git - 编译工作空间 cd ~/robot_ws/ catkin_make - 添加环境变量 $ echo "source ~/robot_ws/devel/setup.bash" >>.bashrc ### 配置参数 - 修改ros2wd/ros_arduino_bridge/ros_arduino_python/config/my_arduino_params.yaml文件,检查下面的参数 - port: /dev/arduino udev规则创建的别名 - baud: 57600 通信波特率和下位机代码的设置的保持一致 - timeout: 0.1 超时时间 - rate: 50 频率 - sensorstate_rate: 10 - use_base_controller: True 是否启动底盘 - base_controller_rate: 10 底盘控制频率 - base_frame: base_link 底盘tf坐标点 - wheel_diameter: 0.127 轮子的直径 - wheel_track: 0.284 轮距 - encoder_resolution: 1320 轮子一圈编码器数(4倍频)霍尔级数x减速比x4 - gear_reduction: 1.0 减速比 - motors_reversed: True 轮子转向是否反向 - Kp: 10 pid参数p - Kd: 12 - Ki: 0 - Ko: 50 - accel_limit: 1.0 加速度限制 ## 启动底盘 roslaunch ros_arduino_python arduino.launch ## 下位机串口控制指令列表
#define ANALOG_READ    'a'
#define GET_BAUDRATE   'b'
#define PIN_MODE       'c'
#define DIGITAL_READ   'd'
#define READ_ENCODERS  'e'
#define MOTOR_SPEEDS   'm'
#define PING           'p'
#define RESET_ENCODERS 'r'
#define SERVO_WRITE    's'
#define SERVO_READ     't'
#define UPDATE_PID     'u'
#define DIGITAL_WRITE  'w'
#define ANALOG_WRITE   'x'
下面的比较常用 例如 - 发送e 获取左右轮的编码器数值,要确保轮子向前转动时,编码器数值增大,反之减小。 - 发送r,清零编码器数值。 - 发送 m 20 20,左右轮向前走20个编码器数值 ## 查看传感器数值 To see the aggregated sensor data, echo the sensor state topic: $ rostopic echo /arduino/sensor_state To see the data on any particular sensor, echo its topic name: $ rostopic echo /arduino/sensor/sensor_name For example, if you have a sensor called ir\_front\_center, you can see its data using: $ rostopic echo /arduino/sensor/ir_front_center You can also graph the range data using rxplot: $ rxplot -p 60 /arduino/sensor/ir_front_center/range ROS 服务 ------------ The ros\_arduino\_python package also defines a few ROS services as follows: **digital\_set\_direction** - set the direction of a digital pin $ rosservice call /arduino/digital_set_direction pin direction where pin is the pin number and direction is 0 for input and 1 for output. **digital\_write** - send a LOW (0) or HIGH (1) signal to a digital pin $ rosservice call /arduino/digital_write pin value where pin is the pin number and value is 0 for LOW and 1 for HIGH. **servo\_write** - set the position of a servo $ rosservice call /arduino/servo_write id pos where id is the index of the servo as defined in the Arduino sketch (servos.h) and pos is the position in radians (0 - 3.14). **servo\_read** - read the position of a servo $ rosservice call /arduino/servo_read id where id is the index of the servo as defined in the Arduino sketch (servos.h)