Unable to read Encoder via Packet Serial
Posted: Mon Aug 31, 2020 2:57 pm
Hello,
I have a 2x7A motor controller connected via serial to a Teensy 3.2.
I have now tries 2 controller, V5B and V5C and they are both not giving me encoder counts.
both boards are running FW version 4.1.34.
The motor does follow the commands given and it moves per the position s given below, but I dont get encoder reading.
When I use the Motion Studio, I can see the encoder counts, so the encoder is working.
Here is my code:
I have a 2x7A motor controller connected via serial to a Teensy 3.2.
I have now tries 2 controller, V5B and V5C and they are both not giving me encoder counts.
both boards are running FW version 4.1.34.
The motor does follow the commands given and it moves per the position s given below, but I dont get encoder reading.
When I use the Motion Studio, I can see the encoder counts, so the encoder is working.
Here is my code:
Code: Select all
#include "RoboClaw.h"
RoboClaw roboclaw(&Serial1, 10000);
#define address 0x80
//Velocity PID coefficients.
#define Kp 100
#define Ki 1.7
#define Kd 520
#define KiM 772
#define Dz 0
#define Min 0
#define Max 500000
long enc1;
void setup() {
//Open Serial and roboclaw serial ports
Serial.begin(38400);
roboclaw.begin(115200);
//Set PID Coefficients
roboclaw.SetM1PositionPID(address, Kp, Ki, Kd, KiM, Dz, Min, Max);
roboclaw.ResetEncoders(address);
Serial.print("Encoder1 reset:");
Serial.print(enc1);
Serial.print("\n");
Serial.println("<Arduino is ready - Serial0>");
delay(1000);
}
void loop() {
roboclaw.SpeedAccelDeccelPositionM1(address, 0, 60000, 0, 100000, 0);
delay(2000);
enc1 = roboclaw.ReadEncM1(address);
Serial.print("E1:");
Serial.print(enc1);
Serial.println("\n");
roboclaw.SpeedAccelDeccelPositionM1(address, 0, 60000, 0, 0, 0);
delay(2000);
enc1 = roboclaw.ReadEncM1(address);
Serial.print("E2:");
Serial.print(enc1);
Serial.println("\n");
}