Reading current with Roboclaw

General discussion of using Roboclaw motor controllers
Post Reply
MikeHalloway
Posts: 4
Joined: Thu Oct 22, 2015 11:59 pm
Reading current with Roboclaw

Post by MikeHalloway »

Hi,

I am new to using Roboclaw and Arduino and I am having some trouble reading the current using the ReadCurrents command.

So far I have got:

Code: Select all


#include "BMSerial.h"
#include "RoboClaw.h"


#define address 0x80

BMSerial terminalSerial(0,1);

RoboClaw roboclaw(5,6);


uint8_t currentFromMotorOne;
uint8_t currentFromMotorTwo;

void setup() {

terminalSerial.begin(9600);

roboclaw.begin(9600);

}

void loop() {

if(roboclaw.ReadCurrents(address, currentFromMotorOne, currentFromMotorTwo)){
    terminalSerial.println(currentFromMotorOne);  
  }


roboclaw.ForwardM1(address,127);

}


There might be somthing obvious I am overlooking here. The output I get is random digits between 0 and 255 were I would expect a current of approximately 2-3 amps.

Would really appreciate any help here :-)
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Reading current with Roboclaw

Post by Basicmicro Support »

Current readings are 16bit values not 8. So you are only seeing the low 8 bits. The 16bit value is in 10ma increments so to get amps you divide the returned value by 100. The readings in amps are fairly accurate but we include the noisy milliamp data so users can filter the data however they want if they really need sub amp resolution.
MikeHalloway
Posts: 4
Joined: Thu Oct 22, 2015 11:59 pm
Re: Reading current with Roboclaw

Post by MikeHalloway »

Hi,

Thanks for the answer, I updated the firmware/arduino library and it now works. Was using the old 8-bit version.

However, the actual Amp reading seem rather high, compared to what I get on my current clamp and old motor controller (other brand). For an example, I read approximately 14 A on the clamp and old controller and 34 A from roboclaw. The reading from the roboclaw is identical in the IonMotion software (34 A).

Am I missing something here? :-)
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Reading current with Roboclaw

Post by Basicmicro Support »

Are you reading the battery amps? Battery amps are not motor amps(which is what roboclaw reports). Battery amps are only the same as motor amps(assuming one motor is being used) when the motor is at 100% duty. Anything less and the amps will be some fraction of the motor amps based on the duty %. Eg 10% Duty with 10 battery amps is 100amps at the motor.

We use a precision .001 ohm 2watt(.0005ohm 4 watt on 60amp boards) current shunt resistor on each motor channel and read the voltage drop across it using a 12bit A/D converter(2v/4096 = .488millivolt resolution). We then filter the data(running average of 64 readings with 4 bit decimation, which is how we get sub amp readings) before you get what you get when using the ReadCurrent command.

You need to use a DC capable clamp. Most clamps are only A/C so double check that. We had to pay about double for the DC capable ones we use for testing. An error of 120% is excessive. It may indicate a problem with your setup.

Particularly noisy motors can cause current reading errors. Take readings at different PWM dutys to see if that may be a factor.

Also ground noise can cause problems. This is especially a problem if you are using excesively long Battery wires(more than 3 feet and/or too small a wire gauge(use thicker wire)). The inductance in the wire will cause large current/voltage ripple at the roboclaw which will cause invalid readings and in extreme situations can even damage the board.
MikeHalloway
Posts: 4
Joined: Thu Oct 22, 2015 11:59 pm
Re: Reading current with Roboclaw

Post by MikeHalloway »

Hi,

Thanks so much for you very quick and thorough reply. In regard to what you said:

The clamp is approved for DC. I am very certain of the amps I should be reading in this test case, since it is an industrial application and we have sold thousands of these units with other controllers. So the set up has been verified thoroughly in regards to how many amps it uses.

I have tested at different PWM dutys. At 100 % I read approximately 30 A from the Roboclaw and 20 A on the clamp/ old controller. At 50 % I read approx 34 A from the Roboclaw and 14 A from the clamp/ old controller.

All battery and motor wires are less than 2 feet and the normal gauge we use for this application. I am fairly sure, that this should be OK.

I tried switching Roboclaws, but get the same reading with the three different ones I tried.

I would really like to get this to work, since it is the last item on my list of things which I need to get to work before the Roboclaw controller performs as well or better than the controller we are using at present ... I would really appreciate any other suggestions, if you have any? :-)
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Reading current with Roboclaw

Post by Basicmicro Support »

Hmm. Is your load constant? If the load is constant I would expect the current to stay about the same or drop slightly under a constant load. The fact the roboclaw in this situation is showing a slightly higher current reading at lower duty points me to noise being the problem. You may have no way of stopping it though if its coming from the motors itself.

What are the specs of the motors(L and R and stall current rating)?

Also have you taken current readings with the clamp on both wires to the motors(eg one reading on one and then one on the other). What were the readings?

Errors in reading through a current shunt are almost entirely noise related. The shunt itself is temperature stable and only has a +-1% error. The rest is just I=V/R. Since the roboclaw does not have a hardware filter

Also which version(Model and V#) are you using? I looked back in the thread but I dont see it.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Reading current with Roboclaw

Post by Basicmicro Support »

Another thing that can affect the current reading is the drive method. Locked Antiphase tends to have more noise near full power while Sign magntiude tends to have it at the low power. The current reading is timed to take place in the middle of the high side pulses. For sign magnitude this means the reading can get swamped by switching noise at low power(when the high side pulse is very small) and with Locked Antiphase the reading can get swamped when near 100% power from the noise from the complementary channel switching.

Because we have a large over current range(double the rated amps) and because the current limit is only reduced based on board temperature(eg false high currents dont increase the board temp) the noise caused by the switching isnt a problem. Unless you are trying to use the current readings for high precision for some reason.
MikeHalloway
Posts: 4
Joined: Thu Oct 22, 2015 11:59 pm
Re: Reading current with Roboclaw

Post by MikeHalloway »

Thanks again for taking the time to write a thorough reply.

The stall current rating is approximately 30 amps. It is a 24 V motor.

The load is constant (mass being lifted).

I need to read the current, so that I can set it to cut off if a given mass (load) is exceeded.

I will try and look into the Sign magntiude/Locked Antiphase setting, and see if it makes any difference.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Reading current with Roboclaw

Post by Basicmicro Support »

If you just need to use it as a cutoff value then you should be able to calibrate the reading that matches your physically requirement. The reading should be consistent even if it is off by some offset or slope error.

Im guessing you have a Roboclaw 2x30A? Those have a peak current limit of 60amps and the limit is reduced as the temperature increases. So you should have plenty of margin even if you are getting error on the current reading. I recommend you calibrate the current reading based on a test weight equal to your cutoff weight.

Also let me know if the signmagnitude option helped with the readings.

One other thing to watch for is during power on the Roboclaw takes a reading from the A/D pins to the current shunts to get an offset error correction. If you are powering on from a power supply instead of a battery this could potentially introduce errors in the offset readings if it is a slow rise power supply.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Reading current with Roboclaw

Post by Basicmicro Support »

In the future do no hijack an old thread. Especially whne your problem isnt anything like the original customers problem. Your problem is a compile time error. His was a logic error.

Your coding mistake was using uint16_t for the current variables instead of int16_t.

Post Reply