[Solved] cant read back data from Roboclaw with packet serial

General discussion of using Roboclaw motor controllers
Post Reply
TedRobotBuilder
Posts: 12
Joined: Mon Aug 31, 2015 8:00 am
[Solved] cant read back data from Roboclaw with packet serial

Post by TedRobotBuilder »

I am sending control commands just fine to the Roboclaw 2x5A from an Arduino Mega. I can get the motors to start, change speed and stop just fine with packet serial using the example code provided with the library called PacketSerialEncoderSpeed. The speeds and encoder values look fine in the Windows Roboclaw configuration software but not when reading back the values (like the encoder’s value) from the Roboclaw using 2-way serial from Arduino. I am using the example code provided with the library called PacketSerialEncoderSpeed. When I use a command like ReadEncM1, the valid parameter is only valid about 1 in 1000 times and even then I get a crazy large value like 6003453798787634 with the motors running slowly. It is like this for every parameter I try to read from the Roboclaw. Writing all commands works just fine.

I need some help getting good parameter reads back from the Roboclaw please.

Setup:
-Arduino Mega, serial pins connected to 15 and 14.
-I ran the Roboclaw setup program and set the modes to packet serial, 9600 baud.
-Successfully ran calibrations and saved.
-Windows config software says version 1.5 and I used it to update the firmware on the RoboClaw.
Last edited by TedRobotBuilder on Mon Aug 31, 2015 9:51 am, edited 1 time in total.
TedRobotBuilder
Posts: 12
Joined: Mon Aug 31, 2015 8:00 am
Re: cant read back data from Roboclaw with packet serial

Post by TedRobotBuilder »

Solved both problems

#1) Not able to read data solved by using this library which uses hardware UART instead of software serial.

http://forums.basicmicro.co.uk/topic997 ... 048518b33f

#2) Junk 10 digit numbers were negative numbers that the unsigned integer variables in the example code could not handle. This is a bug in the example code someone should fix.
Last edited by TedRobotBuilder on Mon Aug 31, 2015 3:31 pm, edited 1 time in total.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: [Solved] cant read back data from Roboclaw with packet serial

Post by Basicmicro Support »

Thanks for the update.

I've changed the uin32_t types to int32_t types. That will print signed values for encoder positions and speeds in the updated examples.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: [Solved] cant read back data from Roboclaw with packet serial

Post by Basicmicro Support »

The current version works with the Mega arduinos. However you have to make sure you use supported pins. Unlike the Uno arduino not all the Mega pins support on change interrupts so alot of pins cannot be used for receiving serial data. Look at the list of pins that work at the top of each example in the roboclaw library.

The Mega chips do have 4 uarts so I usually recommend using one of those. Again you have to make sure you tell the roboclaw library the correct pins to use(see the roboclaw constuctor near the begining of the examples). The first argument is the RX pin number, the second argument is the TX pin number.
jwatte
Posts: 45
Joined: Thu Apr 02, 2015 11:55 am
Re: [Solved] cant read back data from Roboclaw with packet serial

Post by jwatte »

Here's a patch that allows you to use RoboClaw with a real HardwareSerial port instance:
http://watte.net/RoboClaw-HWSerial-20160223.zip
It also fixes some compiler warnings/errors about unused variables and wrong usage of va_start()/va_arg().
Note: I ended up not using this version, and instead writing my own library, so this patch is not heavily tested.
I place it in the public domain, so do what you want with it.

It should be fully compatible with existing code, using BMSerial by default.

Usage:

Code: Select all

#include <RoboClaw.h>

RoboClaw rc(11, 12, 100); // uses BMSerial
RoboClawHW rc3(Serial3, 100); // uses the given port

Post Reply