/rosbot-firmware-pio

ROSbot firmware PlatformIO project. Written using C/C++ and Mbed Os 5.15

Primary LanguageC++GNU General Public License v3.0GPL-3.0

rosbot firmware pio

The ROSbot mobile platform's microcontroller firmware. Written in C++ using arm's Mbed OS framework.

______  _____  _____  _             _           __           
| ___ \|  _  |/  ___|| |           | |         / _|          
| |_/ /| | | |\ `--. | |__    ___  | |_       | |_ __      __
|    / | | | | `--. \| '_ \  / _ \ | __|      |  _|\ \ /\ / /
| |\ \ \ \_/ //\__/ /| |_) || (_) || |_       | |   \ V  V / 
\_| \_| \___/ \____/ |_.__/  \___/  \__|      |_|    \_/\_/  

Firmware version: xx.xx.xx

Prerequisites

You need to install following tools:

Required Visual Studio Code extensions

Loading dependencies

Unfortunately, PlatformIO has a bug: platformio/platform-ststm32#491 so we use git submodules instead.

Git submodules https://git-scm.com/book/en/v2/Git-Tools-Submodules

To import dependencies (not menaged by pio at the moment) run:

git submodule update --init --recursive

Speed up build process

https://docs.platformio.org/en/latest/frameworks/mbed.html#ignoring-particular-components

In directory ~/.platformio/packages/framework-mbed/features create file called .mbedignore with the following content:

cellular/*
cryptocell/*
deprecated_warnings/*
lorawan/*
lwipstack/*
nanostack/*
netsocket/*
nfc/*
unsupported/*

Build firmware

Use PlatformIO: Build task.

Uploading firmware

Uploading firmware using ST-Link

Use PlatformIO: Upload task.

Uploading firmware using core2-flasher

To create intel hex file use arm-none-eabi-objcopy:

$ arm-none-eabi-objcopy -O ihex firmware.elf firmware.hex 

You will find firmware.elf in ./pio/core2.

TODO: add core2-flasher to repository (download right version by detecting system type)

To flash firmware using core2-flasher run:

core2-flasher firmware.hex

Uploading firmware using stm32loader

https://github.com/husarion/stm32loader

This tool allows you to upload firmware using RPi connector.

If you have the bootloader the first two sectors are write protected. Before uploading new firmware you must unlock them (this will erase the bootloader):

$ sudo stm32loader -c <your_sbc> -u -W

To upload new firmware run:

$ sudo stm32loader -c <your_sbc> -e -v -w firmware.bin

where <your_sbc> :

  • tinker for Asus Tinker Board
  • upboard for Upboard
  • rpi for Raspberry Pi

You will find firmware.bin in ./pio/core2.

rosserial interface

To use this firmware you have to disable communication with Husarion Cloud. On your SBC run:

$ sudo systemctl disable husarnet-configurator
$ sudo reboot

To start rosserial communication run:

$ rosrun rosserial_node serial_node.py.py _port:=<SBC_port_name> _baud:=<port_baudrate>

<SBC_port_name>:

  • /dev/ttyS1 for Asus Tinker Board,
  • /dev/serial0 for Raspberry Pi
  • /dev/ttyS4 for UpBoard

<port_baudrate>:

  • 460800 for UpBoard
  • 500000 for Asus Tinker Board
  • 230400 for Raspberry Pi

The baudrate should be adjusted for SBC you use. The default value for this firmware is 500000 (ROSbot 2.0).

You can build firmware for the another baudrate changing only one line in mbed_app.json:

"rosserial-mbed.baudrate": 460800,

The following rosserial.launch file can be used to start roscore and rosserial_python communication:

<launch>
  <arg name="serial_port" default="/dev/ttyUSB0"/>
  <arg name="serial_baudrate" default="500000"/>
  <node pkg="rosserial_python" type="serial_node.py" name="serial_node" output="screen">
    <param name="port" value="$(arg serial_port)"/>
    <param name="baud" value="$(arg serial_baudrate)"/>
  </node>
</launch>

Usage for Asus Tinker Board:

$ roslaunch rosserial.launch serial_port:=/dev/ttyS1 serial_baudrate:=500000

ROS communication

ROSbot subscribes to:

  • /cmd_vel with message type geometry_msgs/Twist

  • /cmd_ser with message type std_msgs/UInt32 - control configured servo output. See CSER service command to learn how to configure servo outputs. Message format:

    MSB [ duty_cycle_us | output_id] LSB
            28bits           4bits
    

    Servos are numbered from 1 to 6, where 1 means hServo 1 output etc. To set SERVO 1 duty cycle to 1000us (0x3E8) run:

    $ rostopic pub /cmd_ser std_msgs/UInt32 "data: 0x3E81" --once 
    

ROSbot publishes to:

  • /velocity with message type geometry_msgs/Twist
  • /battery with message type sensor_msgs/BatteryState
  • /pose with message type geometry_msgs/Pose
  • /range/fl with message type sensor_msgs/Range
  • /range/fr with message type sensor_msgs/Range
  • /range/rl with message type sensor_msgs/Range
  • /range/rr with message type sensor_msgs/Range
  • /joint_states with message type sensor_msgs/JointState
  • /mpu9250 with custom message type rosbot_ekf/Imu
  • /buttons with message type std_msgs/UInt8

ROSbot provides service server:

  • /config with custom message type rosbot_ekf/Configuration
$ rossrv show rosbot_ekf/Configuration 
string command
string data
---
uint8 SUCCESS=0
uint8 FAILURE=1
uint8 COMMAND_NOT_FOUND=2
string data
uint8 result

At the moment following commands are available:

  • CSER - CONFIGURE SERVO

    Change a configuration of servo outputs. Can be repeated as many times as required to change several configuration parameter at once. The parameter name should be separated from the value with a full column : character. Available parameters:

    • S - select servo output, required with P and W options [1:6]
    • V - select voltage mode:
      • 0 - about 5V
      • 1 - about 6V
      • 2 - about 7.4V
      • 3 - about 8.6V
    • E - enable servo output [1,0]
    • P - set period in us
    • W - set duty cycle in us

    To set servo voltages to 5V and enable SERVO 1 output with period 20ms and width 1ms run:

    $ rosservice call /config "command: 'CSER'
    >data: 'V:0 S:1 E:1 P:20000 W:1000 '"

  • CPID - CONFIGURE PID

    Change the motor's pid configuration. This command is similar to CSER command. You can change multiple parameters at the same time. Available parameters:

    • kp - proportional gain (default: 0.8)
    • ki - integral gain (default: 0.2)
    • kd - derivative gain (default: 0.015)
    • out_max - upper limit of the pid output, represents pwm duty cycle (default: 0.80, max: 0.80)
    • out_min - lower limit of the pid output, represents pwm duty cycle when motor spins in opposite direction (default: -0.80, min: -0.80)
    • a_max - acceleration limit (default: 1.5e-4 m/s2)
    • speed_max - max motor speed (default: 1.0 m/s, max: 1.25 m/s)

    To limit pid outputs to 75% run:

    $ rosservice call /config "command: 'CPID'
    >data: 'out_max:0.75 out_min:-0.75'"
  • GPID - GET PID CONFIGURATION

    To get current PID configuration run:

    $ rosservice call /config "command: 'GPID'
    data: ''" 

    Response:

    data: "kp:0.800 ki:0.200 kd:0.015 out_max:1.000 out_min:-1.000 a_max:1. 500e-04 speed_max:\
      \ 1.500"
    result: 0
    
  • SLED - SET LED:

    To set LED2 on run:

    $ rosservice call /config "command: 'SLED'
    >data: '2 1'" 
  • EIMU - ENABLE/DISABLE IMU:

    To enable IMU MPU9250 run:

    $ rosservice call /config "command: 'EIMU'
    >data: '1'" 
    • data: '1' - enable
    • data: '0' - disable
  • RIMU - RESET IMU (for Kalman related odometry)

    To reset IMU MPU9250 run:

    $ rosservice call /config "command: 'RIMU'
    >data: ''"
  • EJSM - ENABLE/DISABLE JOINT STATES MESSAGES

    To enable JointStates messages run:

    $ rosservice call /config "command: `EJSM`
    >data: '1'"
    • data: '1' - enable
    • data: '0' - disable
  • RODOM - RESET ODOMETRY

    To reset odometry run:

    $ rosservice call /config "command: `RODOM`
    >data: ''"
    
  • CALI - ODOMETRY CALIBRATION (update coefficients)

    To update diameter_modificator and tyre_deflation run:

    $ rosservice call /config "command: `CALI`
    >data: 'X Y'"
    • X - diameter_modificator value
    • Y - tyre_deflation value
  • EMOT - ENABLE/DISABLE MOTORS

    To disable motors run:

    $ rosservice call /config "command 'EMOT'
    >data '0'
    • 0 - disconnect motors
    • 1 - connect motors
  • SANI - SET WS2812B LEDS ANIMATION

    To enable the ws2812b interface open the mbed_app.json file and change the line:

    "enable-ws2812b-signalization": 0

    to

    "enable-ws2812b-signalization": 1

    To set fading blue animation run:

    $ rosservice call /config "command: `SANI`
    >data: 'F #0000aa'"

    Available commands:

    • O - OFF
    • S <hex color code> - SOLID COLOR
    • F <hex color code> - FADE IN FADE OUT ANIMATION
    • B <hex color code> - BLINK FRONT/REAR ANIMATION
    • R - RAINBOW ANIMATION

ROS requirements - rosbot_ekf package

In order to use the service you have to download the package rosbot_ekf that can be found HERE. For installation details check the README.

The package incorporate a ready to use Extended Kalman Filter that combines both the imu and encoders measurements to better approximate the ROSbot position and orientation. The package also contains custom messages that are required by the new firmware.

To launch the rosserial communication and Kalman filter run:

$ roslaunch rosbot_ekf all.launch

For PRO version add parameter:

$ roslaunch rosbot_ekf all.launch rosbot_pro:=true

Versioning

The project uses SemVer for versioning. For the versions available, see the tags on this repository.

Changelog

See CHANGELOG.md.

Starting with Mbed OS

Documentation:

Important dev links (mbed + platformio)