RoboClaw Read Current Problem

Hey, I used the command 49 in the packet serial mode of roboclaw to read the motor current. However, it keeps returning 00049, which means the current is 0. This is my code. And I also tried other command like read main battery voltage and it works. It seems only the read current command works abnormally.

[code]static byte Input[5] = {};
static byte Input1[2]={128,49};
byte *Address = Input;
byte *CMD = &Input[1];
byte *DutyHigh = &Input[2];
byte *DutyLow = &Input[3];
byte *CheckSum = &Input[4];
byte buffer[5]={};

double TimeStep = 0.01;

void setup()
{
*Address = 128;
*CMD = 32;
Serial.begin(38400);
Serial1.begin(38400);

}

void loop()
{
int16_t Duty = 1000;
*DutyLow = Duty & 0x00FF;
*DutyHigh = (Duty & 0xFF00) >> 8;

     *CheckSum = ( *Address + *CMD + *DutyHigh + *DutyLow ) & 0x7F;
     Serial1.write(Input, sizeof(Input));
	 delay(1000);
	 Serial1.write(Input1, sizeof(Input1));
	 delay(1000);
	 Serial1.readBytes(buffer,sizeof(buffer));
	 delay(10);
	 Serial.print(buffer[0]);
	 Serial.print(buffer[1]);
	 Serial.print(buffer[2]);
	 Serial.print(buffer[3]);
	 Serial.print(buffer[4]);
	 
	 
	 delay(1000);


 }[/code]

Hello.

Which RoboClaw are you using? The “00049” value you are getting returned is not very clear to me; it is hard to tell which digits correspond to which byte, and I am not sure that the checksum you are getting back is correct. Could you try printing separators and maybe line breaks to make it more understandable? It might look something like this:

Serial.print(buffer[0]);
Serial.print(" ");
Serial.print(buffer[1]);
Serial.print(" ");
Serial.print(buffer[2]);
Serial.print(" ");
Serial.print(buffer[3]);
Serial.print(" ");
Serial.println(buffer[4]);

What motor and supply voltage are you using? Do you know your motor’s specifications? Also, do you know how much current you expect it to be drawing in your current setup?

-Brandon

Thank you for replying. I have changed the code to make every byte show in different line:
Serial.println(buffer[0]);
Serial.println(buffer[1]);
Serial.println(buffer[2]);
Serial.println(buffer[3]);
Serial.println(buffer[4]);

And the result is:

0
0
0
0
49

I think the checksum is right since the address is 128 and command is 49. With all the other bytes equal 0, the checksum should be (128+49) & 0x7f.

I am using Roboclaw 2×30A and the fireware version is 4.0x. The stall current of my dc motor is about 22A. I only connect one motor so the third and fourth output should be 0. I measured the actual current. It was 0.58A. So my expected result maybe
0
58
0
0
checksum

Thank you for the clarification. I agree that your checksum seems to match now. I did not notice anything obvious in your code that might cause this problem. You might try contacting the manufacturer, Orion Robotics, directly.

-Brandon