Coder Social home page Coder Social logo

serial_motor_demo's Introduction

ROS/Arduino Serial Motor Demo

This is demonstration of a ROS 2 interface to an Arduino running differential-drive motor control code.

The corresponding Arduino code can be found here, which is itself a fork of this repo, which also contains a similar implementation for the ROS/Python/Client side (ROS 1 though).

Components

The serial_motor_demo package consists of two nodes, driver.py and gui.py. The idea is that the driver can be run on an onboard PC inside a robot (e.g. a Raspberry Pi), interfacing with the lower-level hardware. The driver exposes motor control through ROS topics (see below), which are to be published by the user's software.

The GUI provides a simple interface for development and testing of such a system. It publishes and subscribes to the appropriate topics.

Driver configuration & usage

The driver has a few parameters:

  • encoder_cpr - Encoder counts per revolution
  • loop_rate - Execution rate of the Arduino code (see Arduino side documentation for details)
  • serial_port - Serial port to connect to (default /dev/ttyUSB0)
  • baud_rate - Serial baud rate (default 57600)
  • serial_debug - Enables debugging of serial commands (default false)

To run, e.g.

ros2 run serial_motor_demo driver --ros-args -p encoder_cpr:=3440 -p loop_rate:=30 -p serial_port:=/dev/ttyUSB0 -p baud_rate:=57600

It makes use of the following topics

  • motor_command - Subscribes a MotorCommand, in rads/sec for each of the two motors
  • motor_vels - Publishes a MotorVels, motor velocities in rads/sec
  • encoder_vals - Publishes an EncoderVals, raw encoder counts for each motor

Test from terminals Terminal 1 : ros2 topic echo /encoder_vals Terminal 2 : ros2 topic pub /motor_command serial_motor_demo_msgs/msg/MotorCommand "{mot_1_req_rad_sec: 1.0}"

GUI Usage

ros2 run serial_motor_demo gui

Has two modes, one for raw PWM input (-255 to 255) and one for closed-loop control. In this mode you must first set the limits for the sliders.

USB permission

sudo chown username /dev/ttyUSB0

USB serial converter conflicts

https://bugs.launchpad.net/ubuntu/+source/brltty/+bug/1990189

  • sudo systemctl stop brltty-udev.service
  • sudo systemctl mask brltty-udev.service
  • sudo systemctl stop brltty.service
  • sudo systemctl disable brltty.service

TODO

  • Add service for encoder reset
  • Add service for updating PID parameters
  • Stability improvements
  • More parameterisation

serial_motor_demo's People

Contributors

joshnewans avatar gbarbarov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.