Multi-Mode Packet Serial

General discussion of using Roboclaw motor controllers
Post Reply
Damien
Posts: 8
Joined: Sun Apr 21, 2019 3:08 pm
Multi-Mode Packet Serial

Post by Damien »

List of parts:
Two roboclaw 2x30A in multi-mode packet serial.
Arduino Mega as the MCU.
2 32 RPM Premium Planetary Gear Motors with Encoders.
Using a 12 V 30 A DC power supply in voltage clamp setting.

I'm having trouble getting the multi-mode to work correctly. My arduino code runs with one roboclaw (not in multimode but in packet serial mode) but when I go to tie the tx and rx together the code doesn't work.
Since the Arduino is being power via usb cable I don't suppose I need the 5V and GND attached to the roboclaw from the Arduino.


I saw in another post that the motors i'm using have issues with the encoders so my team and I are hard-coding in time-delays for positioning which is unfortunate but it will suffice.

A brief over view of this code, we are using an x-y lead screw rail with a lidar and separate turntable to try and do 3D scanning of an object. The serial monitor returns lidar distance(z axis), x position(horizontal motor), y position (vertical motor), and phase (turntable position).

This code works for the positioning system(which is M1 and M2 for address)
but when I go to set the multimode on both roboclaws, with baud rate of 38400 on everything and I uncommect the turntable in the void loop the positioning system ceases to move.


Any suggestions?

Code: Select all

/* Planar Positioning System with Lidar*/

#include "RoboClaw.h"
#include <Wire.h>
#include <LIDARLite.h>

// Globals
LIDARLite lidarLite;
int cal_cnt = 0;
int dist = 0; 

// Roboclaw object
RoboClaw roboclaw(&Serial2,10000); //Connecting TX, RX to roboclaw object

#define address   0x80 //address to roboclaw positioning system
#define address2  0x81 //address to roboclaw turntable

int NUM_ROWS = 25; //Number of rows
int NUM_COLUMNS = 10; //Number of columns

int x_position; //Hold coordinate of x position
int x_position_2;
int y_position; //Hold coordinate of y position
int phase = 0;   //Hold coordinate of turntable

int endLoop = 0; //counter to run once

const int buttonPin = 8; //pushbutton pin, connect ground to pin
int buttonState = 0; // either HIGH OR LOW, LOW initially

void setup() {
  pinMode(buttonPin, INPUT);
  
  //Open roboclaw serial ports
  Serial.begin(38400);
  
  lidarLite.begin(0, true); // Set configuration to default and I2C to 400kHz
  lidarLite.configure(0); // Change this number to try out a iternate configurations
  
  Serial3.begin(38400);
  roboclaw.begin(38400); //communication with roboclaw, baud rate set the same inside Motion Studio
}

void lidar()
{
  
    dist = lidarLite.distance();
  
}
 void turntable(){
      roboclaw.ForwardM1(address2, 127);
      delay(2920);
      roboclaw.ForwardM1(address2, 0);
      roboclaw.ForwardM1(address2, 0);
      roboclaw.ForwardM1(address2, 0);
      roboclaw.ForwardM1(address2, 0);
      phase = phase + 90;
      delay(100);
 }
/*Loop Algorithm*/
void handlePosition(){
  
  
  for(y_position = 0; y_position < NUM_COLUMNS ; y_position++){
   // Serial.print("HELLO");
    if(y_position % 2 == 0){
      for(x_position = 0; x_position <= NUM_ROWS; x_position++){
      
        roboclaw.BackwardM2(address, 0);
        lidar();
        Serial.print(dist);
        Serial.print(" ");
        Serial.print(x_position);
        Serial.print(" ");
        Serial.print(y_position);
        Serial.print(" ");
        Serial.println(phase);
        delay(100);
        roboclaw.ForwardM1(address,127); //start Motor1 forward at half speed
      }
       if(x_position == NUM_ROWS){
          roboclaw.ForwardM1(address, 0);
          //x_position = 0;
          }
    }
      
      else{ 
        for(x_position_2 = NUM_ROWS; x_position_2 > 0; x_position_2--){
         // Serial.print("HI");
          roboclaw.BackwardM2(address, 0);
          lidar();
          Serial.print(dist);
          Serial.print(" ");
          Serial.print(x_position_2);
          Serial.print(" ");
          Serial.print(y_position);
          Serial.print(" ");
          Serial.println(phase);
          delay(100);
          roboclaw.BackwardM1(address,127); //start Motor1 forward at half speed
        }
        if(x_position_2 == 0){
          //Serial.print("YO");
          roboclaw.BackwardM1(address, 0);
          //x_position = 0;
          
          }
   
        
      }
  
    lidar();
    Serial.print(dist);
    Serial.print(" ");
    Serial.print(x_position);
    Serial.print(" ");
    Serial.print(y_position);
    Serial.print(" ");
    Serial.println(phase);
    delay(100);
    roboclaw.BackwardM2(address,127); //start Motor1 forward at full speed
    delay(1000);
    roboclaw.BackwardM2(address, 0); //stop Motor 1 forward 
    }
roboclaw.BackwardM1(address, 0);
roboclaw.BackwardM2(address, 0);
}

void loop() {
  buttonState = digitalRead(buttonPin);

  if(buttonState == HIGH){
    while(phase < 360){
      handlePosition();
//      turntable();
    } 
  }
}
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Multi-Mode Packet Serial

Post by Basicmicro Support »

Maybe Im misunderstanding you, but you do not tie TX and RX together. You tie both TX pins tigether and Both RX pins together. Then both TX pins(S2 pins) from the Roboclaw go to the RX pin of the Arduino and a pullup resistor must be added to that pin. Then the RX pins(S1 pins) from the Roboclaw go to the TX pin of the arduino(no pullup required on this pin).

You defintiely need the GND connected between the Roboclaw and the Arduino. Without that there is no common reference between the boards.

You optionally can power the Arduino from the Roboclaw but you should not connect 5V between the boards it you are powering the Arduino seperately.

The encoder problems are noise related. These motors(they are sold all over the place) have the snubber circuit built into the logic board for the encoders. This allows A/C noise from the motor switching and PWM switching to get onto the encoder signal lines. There are two fixes.

Option 1. Add .01uf(or there abouts) from each signal line to ground. This will reduce the noise enough to allow good readings. I also recommend a similar .01uf from the 5v of the encoder to ground as well because noise can feedback into the roboclaw on the 5v line as well.

Option 2. Remove the snubber circuit on the motors encoder board. This usually entails removing one or two capacitors that are connected to the motor power lines. Use a multimeter to find them(continuity mode). Then install an external .1uf capacitor across the motor leads instead of on the board(a through hole style cap works well for this). Removing the snubber on the logic pcb ellimantes all the noise getting on the encoder signal lines and 5v power rail and the external cap is the new snubber.

I prefer option 2 when I can use it. Some motors its difficult to get at the snubber cap(s) though. And if you are not confortable with a soldering iron use option 1 instead.
Basicmicro Tech
Posts: 13
Joined: Wed Feb 13, 2019 2:56 pm
Re: Multi-Mode Packet Serial

Post by Basicmicro Tech »

We have an application note that covers using multiple RoboClaws with an Arduino in packet serial mode. Here is the link to the app note: https://resources.basicmicro.com/using- ... h-arduino/
Damien
Posts: 8
Joined: Sun Apr 21, 2019 3:08 pm
Re: Multi-Mode Packet Serial

Post by Damien »

Thank you for the quick response!
It turns out that I mistakenly set up the same serial pins on the Arduino to both Roboclaws, in this case I was using pins 16 (Tx2) and 17(Rx2) on the Mega which were then jumped to a breadboard and I sent lines in parallel to the switch 1 and switch 2 for both roboclaws. This was a mistake since I was looking at the datasheet of the roboc(page 67) and mistook the diagram to say that I should do so. I realized my mistake when my fellow teammate though it was strange I wasn't using another serial for the second roboclaw. That fixed the issue. The grounds were connected.

As for the encoders, I will try the first method.
Oddly enough, ServoCity is quite aware of this problem, which I wish they would have specified seeing as how they promote the roboclaws on their website, not to say they aren't a good company, it's just disappointing.
They did however recommend other motors to use, from their sister company.
https://www.gobilda.com/5202-series-yel ... ar-motors/

I'm hoping that these motors they recommend will suffice but I'm skeptical now, do you recommend any motors similar in terms of specs or do you think that these new motors they recommend will also be sufficient?

Best regards,
Damien
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Multi-Mode Packet Serial

Post by Basicmicro Support »

Since Servocity doesnt manufacture those motors they really dont have much option. That hall sensor circuit and snubber design appears to be common on everyone of those motors with encoders. I've bought from a dozen different manufacturers and have only see two basic designs, a single cap design and double cap design.

Post Reply