Reading Encoder Value Fails with Multiple Motors

Hi everyone! I've been a long-time lurker, but here is my 1st post as I've had difficulty finding a thread discussing a similar problem to the one I have been running into. I have built a tensegrity robot that requires 24 motors (Pololu #4753) to control, which are connected to 12 Roboclaw 2x7A motor controllers. These motor controllers are connected to an Arduino Due using the Hardware Serial ports. Currently, 8 of these motor controllers are connected to Serial 1, and the remaining are connected to Serial 2.

The problem I am running into is that when I try to read the speed or position from the motors, only a value of 0 is returned. After checking my code, my first thought was that it may be a hardware issue. I tested the code using spare components not mounted on the robot, and it worked!

Going back to the robot, I checked all the wiring, and everything looked good. This was also supported by the fact that I could send position commands to each motor, and they behaved as expected, though I still got a value of 0 when trying to call values from the encoder to the Arduino. This led me to wonder if the number of components was causing issues. When I disconnected all but one Roboclaw controller and ran the code, I was finally able to read the encoder values from the robot.

My attempt to fix this was to add an external power source to the Arduino in the form of a 9V battery connected using the barrel jack, with the reasoning that the power drawn by all the connected components was greater than what the USB could provide. That did not change anything.

I was wondering if anyone had any suggestions on what I could try next? When I look online, I suspect it may be how I have the motor controllers connected to the Hardware Serial and ground. I have all the motor controllers connected to a screw terminal block, which then has a set of wires connected to the Serial Ports. Is this appropriate, or do I need something like an I/O expanded? I am unsure since the motor controllers seem to be properly receiving commands from the Arduino.

I appreciate any advice anyone might have.

How do you address each distinct motor?

1 Like

The the answer is simple, you need some,or maybe a lot of power supply decoupling.
This link tells you all about it.

De-coupling tutorial

1 Like

An as-built schematic (what you have in front of you, not a screenshot of someone else's project) would be nice.

1 Like

Hi DrDiettrich, here is how I define the controller addresses in my code:

#include <RoboClaw.h>
#include <Wire.h>
#include <SparkFun_ISM330DHCX.h>
#include <SparkFun_MMC5983MA_Arduino_Library.h>
#include <DueTimer.h>

// 1st Serial Connections (Serial1)
#define CONTROLLER1 128
#define CONTROLLER2 129
#define CONTROLLER3 130
#define CONTROLLER4 131
#define CONTROLLER5 132
#define CONTROLLER6 133
#define CONTROLLER7 134
#define CONTROLLER8 135

// 2nd Serial Connections (Serial2)

#define CONTROLLER9 128
#define CONTROLLER10 129
#define CONTROLLER11 130
#define CONTROLLER12 131

#define baudrate  115200  // Serial Baudrate
 
int timeout = 10000;    // Serial Timeout (ms) 
int initialEnc = 0;     // Initial Count Encoder 1
int delayShort = 500;   // Short Time Delay (ms)
int delayLong = 4000;   // Long Time Delay (ms)
int MotorSpeed = 10000; // Motor Speed (quadrature pulses per second [~11500 Max])
int MotorAccel = 6000; // Motor Accleration (See BasicMotion Studio for specific value for Motor)
int MotorDecel = 6000; // Motor Deceleration (See BasicMotion Studio for specific value for Motor)
int Lengthen = 8000;    // Desired Encoder Value for Lengthened Cable
int Shorten = -8000;    // Desired Encoder Value for Shortened Cable
String readString;       // defining the string
byte Motor_Sequence;     // defining a variable that will be used to decide to which sequence to run
volatile bool newDataAvailable = true;

// Define Variables for Magnetometer (Interger)
uint32_t rawValueX = 0;
uint32_t rawValueY = 0;
uint32_t rawValueZ = 0; 

// Structs for IMU data (Float)
sfe_ism_data_t accelData; 
sfe_ism_data_t gyroData;  

RoboClaw roboclaw(&Serial1,timeout);
RoboClaw roboclaw2(&Serial2,timeout);

// Initialize Sensor Object 
SFE_MMC5983MA myMag;       // Magnetometer
SparkFun_ISM330DHCX myISM; // IMU

The Roboclaw controllers come with Basicmicro Motion Studio, which has an option to configure the address of each controller. There is a total of 8 addresses that a controller can be configured to, which is why I have up to 8 motor controllers to connected to one Serial port.

I should clearly state that this picture is from the basic motion manual. Here the baudrate shows as 38400 while I have set it to 115200. That is the only difference in my configuration settings from this image.

Hi Grumpy_Mike, this makes sense to me. I have seen PSU decoupling mentioned in my research but did not think of it here. This project is the first time I have needed to build hardware, and I have quickly gained an appreciation for the added complexity of demonstrating something physically rather than in simulations.

I will go through your tutorial and let you know how it goes!

1 Like

Hi dougp, thanks for your suggestion. I am not allowed to take pictures in the lab, but I am working to make a schematic of my setup. I will edit this post when I finish it.

1 Like

Serial is a point-to-point connection, not a bus or network system. Connecting multiple controllers will short circuit their TX pins. This may be the reason why you read all zeroes from the controllers.

1 Like

Hello, everyone, I appreciate the feedback I have received. I wanted to let everyone know that I have solved the problem I was experiencing!

DrDiettrich, your comment was the one that led me down the rabbit hole where I discovered my problem. I have heard about the limitations of serial connections before, but I was sure the way I connected everything was recommended by the manufacturer of the Roboclaw controllers. When I started this project, I used online tutorials to learn how to connect everything. The one I followed to base the connections of my system was titled " Using Multiple RoboClaws with Arduino," found at this link:

Using Multiple RoboClaws with Arduino - Resources Basicmicro

In a separate form post I found using Google, I saw the manufacturer gave this information on using multiple controllers with a serial connection; "Multi-unit mode makes the TX(S2 pins) of the Roboclaws Open Drain so they will not conflict with each other". In my specific case, I forgot to enable multi-unit mode on my controllers. I also discovered that when using 12 controllers, I needed a 1 K-Ohm resistor per serial connection instead of the 4.7 K-Ohm recommended in the tutorial. Once this was corrected, my code worked as intended.

dougp, as I have found a solution, I will refrain from posting a schematic of my system. I understand this is valuable information when asking for help on this form in the future. To anyone looking at this post, ensure you have the correct pull-up resistor to the TX connections from your Roboclaw controllers. With 12 connections, the 4.7 K-Ohm used in the tutorial gave me an encoder reading of 0, while a split-cable with 1K-Ohm per serial connection had the system behaving as expected. Also, make sure the 'multi-unit mode' is active in the firmware.

Grumpy_mike, your tutorial on Power De-coupling taught me some important things to remember when developing large-scale systems. With my intermediate knowledge of Arduino, I can only assume the manufacturer of these Roboclaw controllers found a way to address this concern with the design of the Integrated Circuit used in each controller.

I want to thank everyone who responded to my post. It is difficult at times to work on this project alone. As a graduate student, I am constantly told I am the expert on my project, even if I have so many of my own questions. It is nice to get any kind of technical feedback from others. I hope I explained what solved my issues for anyone in a similar situation. Best of luck!

Thanks for getting back to us. But I do think that

So I think @DrDiettrich is the post where you should place your Solution tick. Yes I know you had to do some work to find and confirm the solution, but you would not have got there without DrDiettrich.

1 Like

Hi, Grumpy_Mike. That is an excellent point. I have updated the solution tick. Thanks again, @DrDiettrich, @Grumpy_Mike, and @dougp, for your help!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.