Unable to read Encoder via Packet Serial
Unable to read Encoder via Packet Serial
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");
}
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: Unable to read Encoder via Packet Serial
You should always start with the ReadVersion example. If you can't read the version string you wont be able to read anything else. Please test that and let me know the results.
Re: Unable to read Encoder via Packet Serial
I did try this already and also some of the examples, same result. cant read. I can write and also can see the data on the App.
Anything I should do on my code?
Anything I should do on my code?
Re: Unable to read Encoder via Packet Serial
Hi,
I have done further testing and have narrowed down the issue.
I can get the ReadVersion to work now. See below debug output;
my program runs until it hits this command and then the program does not go further and hangs.
not sure why the programs hangs on this and causes this issue. Here is my full test code. When I comment the line above, then the program will run, but I don't see the encoder values.
I have done further testing and have narrowed down the issue.
I can get the ReadVersion to work now. See below debug output;
Code: Select all
Port closed
Uploading to I/O board
Opening port
Port open
VMDPR_
<Arduino is ready - Serial0>
RoboClaw Version: USB Roboclaw 2x7a v4.1.34
Code: Select all
enc1=roboclaw.ReadEncM1(address); // Read encoder positon position
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
int enc1;
char version[32];
void setup() {
//Open Serial and roboclaw serial ports
Serial.begin(9600);
roboclaw.begin(115200);
//Set PID Coefficients
roboclaw.SetM1PositionPID(address, Kp, Ki, Kd, KiM, Dz, Min, Max);
roboclaw.ResetEncoders(address);
Serial.print("\n");
Serial.println("<Arduino is ready - Serial0>");
roboclaw.ReadVersion(address, version);
Serial.println("RoboClaw Version: " + String(version));
delay(2000);
}
void loop() {
roboclaw.SpeedAccelDeccelPositionM1(address, 0, 30000, 0, 25000, 0);
delay(2000);
enc1=roboclaw.ReadEncM1(address);
Serial.println("E1:" + String(enc1));
Serial.println("\n");
roboclaw.SpeedAccelDeccelPositionM1(address, 0, 30000, 0, 0, 0);
delay(2000);
enc1 = roboclaw.ReadEncM1(address);
Serial.println("E2:" + String(enc1));
Serial.println("\n");
}
Re: Unable to read Encoder via Packet Serial
Issue was resolved by reinstalling the library.
Thanks
Thanks
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: Unable to read Encoder via Packet Serial
Thank you for the heads up.