Hi,
I want to synchronise 2 of DC brushed motors with roboclaw 2x30A, thus I have two quadrature encoders and my microprocessor is Arduino Mega2560. I can read to speeds of the motors and encoder values on arduino terminal. But i don’t know exactly that how to calculate the difference and then speed up/down to motor ? I’m looking at the roboclaw user manual for a while but there are many methods which are about accel, speed, distance… I confused because of that. I’m adding my code here which is incomplete.
#include "Arduino.h"
#include <RoboClaw.h>
#include <BMSerial.h>
RoboClaw roboclaw(10, 11, 10000);
#define RoboClawAddress 0x80
#define Kp 0x00010000
#define Ki 0x00008000
#define Kd 0x00004000
#define qpps 44000
void setup() {
roboclaw.begin(38400);
Serial.begin(38400);
roboclaw.SetM1VelocityPID(RoboClawAddress, Kp, Ki, Kd, qpps);
roboclaw.SetM2VelocityPID(RoboClawAddress, Kp, Ki, Kd, qpps);
}
void loop() {
}
void displayspeed(void){
uint8_t status1, status2, status3, status4;
bool valid1, valid2, valid3, valid4;
uint32_t enc1= roboclaw.ReadEncM1(RoboClawAddress, &status1, &valid1);
uint32_t enc2 = roboclaw.ReadEncM2(RoboClawAddress, &status2, &valid2);
uint32_t speed1 = roboclaw.ReadSpeedM1(RoboClawAddress, &status3, &valid3);
uint32_t speed2 = roboclaw.ReadSpeedM2(RoboClawAddress, &status4, &valid4);
if(valid1){
Serial.print("Encoder1:");
Serial.print(enc1);
Serial.print(" ");
Serial.print(status1, HEX);
Serial.print(" ");
}
if(valid2){
Serial.print(" Encoder2:");
Serial.print(enc2);
Serial.print(" ");
Serial.print(status2, HEX);
Serial.print(" ");
}
if(valid3){
Serial.print(" Speed1:");
Serial.print(speed1, DEC);
Serial.print(" ");
}
if(valid4){
Serial.print(" Speed2:");
Serial.print(speed2, DEC);
Serial.print(" ");
}
Serial.println();
}
Can anybody help me, what should i do next ?
Thanks in advance