Skip to content

ccresta1386/roboclaw

 
 

Repository files navigation

roboclaw

This is a small C library for communication with Roboclaw motor controllers

Platforms

Library works on Unix platforms (e.g. Linux) including desktop computers and SBCs like RaspberryPi, BeagleBone or LegoMindstorms EV3 (with ev3dev OS).

Hardware

You need to connect Roboclaw (or multiple Roboclaws) via USB or uart

Why another library

After shallow code inspection of available C/C++ libraries I made decission to write my own correctly.

Library What I would do differently Why did they do it this way
https://github.com/SorcererX/RoboClaw byte-by-byte IO, busy waiting arduino library port
https://github.com/ColinHeffernan/roboclaw byte-by-byte IO, ROS serial dependence, hardcoded 100 ms timeout arduino library port
https://bitbucket.org/vo/libroboclaw/ limited baudrate, command ACK not read, ACK-purge race, garbage on timeout old firmare didn't have ACK

byte-by-byte IO - unnecessary system calls for each byte read/written costly by itself and may result in unnecessary context changes when process is put to sleep on IO

busy waiting - waiting for available bytes on read spinning CPU at 100% until IO or timeout

ACK-purge race - Roboclaw ACK byte not read, on commands tty buffers flushed resulting in race when command is followed by read command (ACK not read, buffers flushed but after or before receiving ACK?)

garbage on timeout - when read times out library returns garbage values and there is no way to check if it was timeout

Scope

The library implements only a subset of commands that I use and I have no plans to implement all possible Roboclaw commands.

Currently implemented:

  • roboclaw_duty_m1m2
  • roboclaw_speed_m1m2
  • roboclaw_speed_accel_m1m2
  • roboclaw_main_battery_voltage
  • roboclaw_encoders

Building Instructions

Compilers and make

$ sudo apt-get update
$ sudo apt-get install build-essential 

Getting git

sudo apt-get install git

Cloning the repository

git clone https://github.com/bmegli/roboclaw.git

Building the examples

cd roboclaw
make all

Testing

Run as sudo or add your user to dialout group:

usermod -a -G dialout your_user

Run roboclaw-test with your device, baudrate (as set on Roboclaw) and address (from 0x80 to 0x87)

Controller Device (typically)
USB (any controller) /dev/ttyACM0
RasberryPi /dev/ttyAMA0
BeagleBoneBlack /dev/ttyO1, /dev/ttyO2, /dev/ttyO4
LegoMindstorms EV3 /dev/tty_in1, /dev/tty_in2, /dev/tty_in3, /dev/tty_in4
./roboclaw-test /dev/ttyACM0 115200 0x80

Using

See examples directory for more complete and commented examples with error handling.

	struct roboclaw *rc;
	int16_t voltage;

	rc=roboclaw_init("/dev/ttyACM0", 115200);

	roboclaw_main_battery_voltage(rc, 0x80, &voltage)	

	roboclaw_speed_m1m2(rc, 0x80, 1000, 1000);

	sleep(1)

	roboclaw_speed_m1m2(rc, 0x80, 0, 0);

	roboclaw_close(rc);

Note - configure motors and encoders correctly in IONStudio before running speed commands

Compiling your code

C

gcc roboclaw.c your_program.c -o your-program

C++

gcc -c roboclaw.c
g++ -c your_program.cpp
g++ roboclaw.o your_program.o -o your-program

License

Library is licensed under Mozilla Public License, v. 2.0.

This is similiar to LGPL but more permissive:

  • you can use it as LGPL in prioprietrary software
  • unlike LGPL you may compile it statically with your code

Like in LGPL, if you modify this library, you have to make your changes publicly available. Making a github fork of the library with your changes satisfies those requirements perfectly.

Additional information

Building with CMake

Alternatively build examples and library with Cmake

sudo apt-get install cmake
cd roboclaw
mkdir build
cd build
cmake ..
make

About

C library for ION MC Roboclaw

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 87.2%
  • C++ 9.5%
  • Makefile 2.2%
  • CMake 1.1%