BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Sun Nov 19, 2017 11:37 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: ReadCurrents Function
PostPosted: Fri Jan 04, 2013 11:31 pm 
Offline
New User

Joined: Fri Jan 04, 2013 10:57 pm
Posts: 4
Has anyone had any success with the ReadCurrents() function provided with the RoboClaw arduino library? I am successfully reading back data from the roboclaw using a mega2560, but even when I scope the serial lines, and load up the motors, I always get [0,0,0,0,49]. I am using a 2x15A with firmware version 2.1.6. I had to modify the roboclaw functions to get it to work on hardware serial, and added some delays to wait for return data. I am also puzzled because it looks like the code to read currents in Roboclaw uses the Read2 command, which gets two values, and checks the CRC, but the output from the roboclaw serial looks like it uses a [CH1H,CH1L,CH2H,CH2L,CRC] format.
Any advice relevant to reading current from roboclaws is much appreciated!
I have attached the logic analyzer output.
Thanks!
Cedric


Attachments:
File comment: Logic analyzer on roboclaw S1 and S2 lines.
LogicPort-RoboClawComm.pdf [10.27 KiB]
Downloaded 293 times
Top
 Profile  
 
 Post subject: Re: ReadCurrents Function
PostPosted: Wed Jan 09, 2013 10:59 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
I can confirm you should be reading back 4 bytes + crc. 2 bytes per current reading.

Also this command has only been in the firmware for some versions. It should be available in 2.1.5 and newer but I dont think it was there before that. Also the returned value I beleive is amps, not milliamps. So until you hit atleast 1 amp you will get 0s. Also this is the instant reading, not an average. By instant I means it is the last reading taken which is taken every 125th of a second.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ReadCurrents Function
PostPosted: Tue Jan 15, 2013 5:19 am 
Offline
New User

Joined: Fri Jan 04, 2013 10:57 pm
Posts: 4
Thanks for the reply. I fixed the code, and I am reading reasonable values now. My problem is that I get values that do not appear to be in Amps. I get values around 75.0 when I am reading 10A from an amp-clamp around my motor leads. I have a 1 second moving average filter applied to the data. Can you confirm the scale of the data? Is it in 0.1 A increments? Also, is this the same for all roboclaw sizes? I plan to use this function for the 2x5A roboclaw as well as the 2x15A.
Thanks!
Cedric


Top
 Profile  
 
 Post subject: Re: ReadCurrents Function
PostPosted: Tue Jan 15, 2013 8:51 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
Hmm. I beleive you are currect. The return value is in .1 increments not 1 increments.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ReadCurrents Function
PostPosted: Sun Jan 20, 2013 10:52 am 
Offline
New User

Joined: Sun Jan 20, 2013 10:49 am
Posts: 1
Yes of course The return is 1 I have try this


Top
 Profile  
 
 Post subject: Re: ReadCurrents Function
PostPosted: Sat Oct 26, 2013 6:30 am 
Offline
Citizen

Joined: Sun Oct 20, 2013 5:22 am
Posts: 16
I'm also trying to use the supplied Arduino Library to read the motor currents. I believe I've downloaded the most recent library which defines ReadCurrent as follows:

Code:
bool RoboClaw::ReadCurrents(uint8_t address, uint8_t &current1, uint8_t &current2){
   bool valid;
   uint16_t value = Read2(address,GETCURRENTS,&valid);
   if(valid){
      current1 = value>>8;
      current2 = value;
   }
   return valid;
}


The documentation seems to suggest that command 49 should be reading 4 bytes, 2 for each channel yet the above code seems to be treating the variables current1 & 2 as uint_8 rather than uint_16

When I use the code 'as is' with an Arduino sketch, I end up with '255' as my decimal value irrespective of motor speed/load except when off and then it read 0. Should this code instead be set up roughly as follows?? (doubled size of all ints and shifted by 16 instead of 8. I'm not sure I implemented status correctly)

Code:
bool RoboClaw::ReadCurrents(uint8_t address, uint16_t &current1,uint16_t &current2){
   bool valid;
        uint_8_t status
   uint32_t value = Read4_1(address,GETCURRENTS,&status,&valid);
   if(valid){
      current1 = value>>16;
      current2 = value;
   }
   return valid;
}


I tried it as such but didn't get much better results. ??? Or am I just doing it wrong ??

In my Arduino code using the default library, I'm essentially doing:

Code:
  uint8_t current1;
  uint8_t current2;
  roboclaw.ReadCurrents(address, current1, current2);
  terminal.println(current1);


Sorry to revive an old thread, but I though it best to put all the questions about "ReadCurrents" together for future searching.


Top
 Profile  
 
 Post subject: Re: ReadCurrents Function
PostPosted: Tue Nov 05, 2013 8:37 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
The read currents command returns 2 bytes per motor(eg a 16bit value).

Since neither way you described is working for you the first place to start is with what version Roboclaw you have and what firmware version is on it. If you can read the version from the board then you know your communications are working correctly since it requires sending and receiving to read the version information.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: ReadCurrents Function
PostPosted: Mon Sep 08, 2014 4:07 am 
Offline
Citizen

Joined: Sun Oct 20, 2013 5:22 am
Posts: 16
Hi, reopening thread in order to keep everything in one place.

I'm also having problems with ReadCurrents. I added the following to the Arduino Library given that the method should return 4 bytes rather than 2 as defined in the regular "ReadCurrents";

Code:
bool RoboClaw::ReadCurrents16(uint8_t address, uint16_t &current1,uint16_t &current2){
    bool valid;
    uint8_t status;
    uint32_t value = Read4_1(address,GETCURRENTS,&status,&valid);
    if(valid){
        current1 = value>>16;
        current2 = value;
    }
    return valid;
}


My firmware is "USB Roboclaw 2x15a v4.0.0"

In my arduino code I'm doing something like:

Code:
while (millis()-startTime < 3000) {
    rc.SpeedM1M2(address,3500,3500);
 //   displayspeed();
 //   delay(2);
    displayCurrents();
  }   

void displayCurrents() {
  rc.ReadCurrents16(address,M1_current,M2_current);
  ter.print("M1 current=");
  ter.print(M1_current,DEC);
  ter.print(" M2 current=");
  ter.println(M2_current,DEC);
}


While the motors spin (at about 50% duty cycle), I'm always getting a reading of [0,0] for the two motor. The motors are rated at 6A stall, but also show 0,0 if I stall them while the controller is running. Perhaps my modified ReadCurrents16 method is incorrect?? Any thoughts?


Top
 Profile  
 
 Post subject: Re: ReadCurrents Function
PostPosted: Tue Sep 23, 2014 4:17 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
The current roboclaw firmware version is 4.1.3. Please download IonMotion and update your firmware. That is at least part of the problem you are having. The current commands in 4.0.0 only returned a very granular current reading. We've since updated the filtering in the current sense code to give more accurate readings(into the 10s of milliamps).

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO