BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 9:13 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Commands not recognized - Ardiuno
PostPosted: Wed Jan 11, 2012 3:15 pm 
Offline
New User

Joined: Wed Jan 11, 2012 2:57 pm
Posts: 2
Hello,

I am using RoboClaw with an Arduino Mega 2560.
When I call rc.ReadVersion(address, version) I get unpredictable results.
Sometimes I do get the correct version information on the output, but more times than not I get garbage and the call fails.
Here is my code:
if(rc.ReadVersion(address, version))
{
Serial.print("\r\nversion: ");
Serial.println(version);
cnt = 0;
}
else
{
cnt += 1;
Serial.print(".");
Serial.print(cnt);
// Serial.println("RoboClaw not found");
}
The cnt (counter) variable can get to 15 or more before a valid version is returned.
The correct command data is being sent, I think it has more to do with the RX portion.

Thanks for any help,
Sandy


Top
 Profile  
 
 Post subject: Re: Commands not recognized - Ardiuno
PostPosted: Thu Jan 12, 2012 3:53 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
What baudrate are you using? Try 2400 first to see if the problem goes away. This would indicate a timing issue(eg serial data is being read/written faster/slower than it should). If the problem is the same no matter the baudrate then double check your wiring. I'd suspect a loose wire/ground or noise from somewhere(possibly a power supply or the motors).

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Commands not recognized - Ardiuno
PostPosted: Fri Jan 20, 2012 12:07 pm 
Offline
New User

Joined: Wed Jan 11, 2012 2:57 pm
Posts: 2
Still not working.

I have used a scope to look at the RX signal and it is clean. It is a 3.3v output so I added a level converter (a 4050) to bring it to a 5.0v signal with no difference. I tried a different serial port, no change. Even tried a different Arduino board, no change. Have tried different serial port speeds, 2400 - 19200 with no difference. Currently set to 9600, 8N1. Using an external terminal, by connecting the rc.tx line thru a converter, still shows corrupted data being sent by the RC.

I am beginning to suspect I have a defective board, although I am still very much willing to try to "fix" the current one. I find it very odd that it receives packet data fine, and is quite capable of driving my motors on command. Since it can receive data, I do not see why it should not transmit data. NOTE: It TXs data, but the data is corrupted.

I have put serial.print statements throughout the RoboClaw.cpp file to trouble shoot. It appears that I am sending the correct address and cmd. To simplify things further I have replaced all the calls into BMSerial with calls to Serial2.
examples:
    Serial2.pint(address, BYTE)
    Serial2.read()

This eliminates BMSerial from being involved. This works because I am using a Mega. I know this works because the calls involved with motor commands are working fine. Also SimpleSerial mode on Serial2 works.

I have used Serial2 for other things and it worked perfectly. The Mega board is working OK.

Any help or suggestions?
Sandy


Top
 Profile  
 
 Post subject: Re: Commands not recognized - Ardiuno
PostPosted: Sat Jan 21, 2012 8:37 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
If all motor commands being sent to the roboclaw are working fine then I'm not really sure what could be the problem. Note we've not tested using a Mega Arduino, only a standard one so I couldn't say if there could be a bug in BMserial when used on the Mega. There shouldn't be because we based BMserial off the new software serial library but...

When you say you see corrupted data coming from the TX(S2 pin) what do you mean? Are you using a digital scope? If so can you capture a picture. If not how are you determining it's corrupt?

Have you tried other readback commands besides the version command, like the speed and enc position commands? Even if you have no encoder attached these commands will return values.

Worse case you can send the board back and we'll test it here. If there is a physical problem with it we'll replace it. We have regular Arduinos to test with.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Commands not recognized - Ardiuno
PostPosted: Fri Feb 03, 2012 11:35 pm 
Offline
Citizen

Joined: Wed Oct 13, 2010 6:10 pm
Posts: 7
I have the same problem. My code works on the Duemilano, but not on the MEGA 2560 or MEGA Pro Mini 3.3V (from Sparkfun). My code is shown below. I use a software serial port on the Duemilano and I tried that on the 2560 and Mini (after I tried a hardware serial port on each). The atmega2560 spec sheet says that a high is guaranteed to be recognized down to 0.6*Vcc, which is 0.6*5=3V on the 2560. The output from the Roboclaw is 3.24V. The Roboclaw blinks the "Stat 1" LED when communicating with the 2560, but not with the Duemilano or the Mini. I am able to get the Roboclaw to control a motor using Packet Serial sent from the 2560 and Mini; so it would seem that the serial communications are working from the 2560 to the Roboclaw.


Code:
#include "BMSerial.h"
#include "RoboClaw.h"

#define address 0x80

BMSerial terminalSerial(0,1); // Receive pin, Transmit pin
//RoboClaw rc(15,14); // Receive pin, Transmit pin
RoboClaw rc(4,5); // Receive pin, Transmit pin
unsigned int count=0;

void setup() {
  terminalSerial.begin(38400);
  rc.begin(2400);
}

void loop() {
  char version[32];

  if(rc.ReadVersion(address,version)){
    terminalSerial.println(version);
    terminalSerial.println(count);  // to see something changing in the terminal
  count++;
  }

  delay(2000);
}


Top
 Profile  
 
 Post subject: Re: Commands not recognized - Ardiuno
PostPosted: Sun Feb 05, 2012 11:14 pm 
Offline
Citizen

Joined: Wed Oct 13, 2010 6:10 pm
Posts: 7
I have worked out the issues with the Arduino Mega 2560; however, due to an encounter with magic smoke, I was only able to test the modified code with an older 2x25A RoboClaw. Once I get my hands on a new RoboClaw, I will test the MEGA Pro Mini 3.3V (from Sparkfun).

I was able to get all of the hardware serial ports to operate properly and I tested pins 52/53 as a software serial port. Below is some code that I used to test the operation of these ports. Also, I did not check every command because my older RoboClaw does not support certain commands; I'll test those commands after I get the new unit.

@ drsandyrae - Sandy, please see if these modifications fix your problems (see the attached files).

Code:
#include "BMSerial.h"
#include "RoboClaw.h"

#define address 0x80

#define Kp 200
#define Ki 100
#define Kd  80
#define qpps 51200

BMSerial terminal(0,1);
RoboClaw roboclaw(19,18);

void setup() {
  char version[32];
  uint16_t voltage;
  uint8_t status;
  bool valid;

  terminal.begin(38400);
  roboclaw.begin(2400);

  roboclaw.SetM1Constants(address,Kd,Kp,Ki,qpps);
  roboclaw.SetM2Constants(address,Kd,Kp,Ki,qpps);

  delay(5000);  // gives me time to start the terminal
  roboclaw.ReadVersion(address,version);
    terminal.print(version);
    terminal.println();
  voltage=roboclaw.ReadMainBatteryVoltage(address, &valid);
    terminal.print("Main Battery Voltage:");
    terminal.print(voltage);
    terminal.println();
}

void displayspeed(void)
{
  uint8_t status;
  bool valid;

  uint32_t enc1= roboclaw.ReadEncM1(address, &status, &valid);
  if(valid){
    terminal.print("Encoder1:");
    terminal.print(enc1,DEC);
    terminal.print(" ");
    terminal.print(status,HEX);
    terminal.print(" ");
  }
  uint32_t enc2 = roboclaw.ReadEncM2(address, &status, &valid);
  if(valid){
    terminal.print("Encoder2:");
    terminal.print(enc2,DEC);
    terminal.print(" ");
    terminal.print(status,HEX);
    terminal.print(" ");
  }
  uint32_t speed1 = roboclaw.ReadSpeedM1(address, &status, &valid);
  if(valid){
    terminal.print("Speed1:");
    terminal.print(speed1,DEC);
    terminal.print(" ");
  }
  uint32_t speed2 = roboclaw.ReadSpeedM2(address, &status, &valid);
  if(valid){
    terminal.print("Speed2:");
    terminal.print(speed2,DEC);
    terminal.print(" ");
  }
  terminal.println();
}

void loop() {
  uint16_t voltage;
  bool valid;
 
  roboclaw.SpeedAccelM1(address,40000,20000);
  roboclaw.SpeedAccelM2(address,40000,20000);
  for(uint8_t i = 0;i<20;i++)
    displayspeed();

  voltage=roboclaw.ReadMainBatteryVoltage(address, &valid);
    terminal.print("Main Battery Voltage:");
    terminal.print(voltage);
    terminal.println();

  roboclaw.SpeedAccelM1(address,40000,-20000);
  roboclaw.SpeedAccelM2(address,40000,-20000);
  for(uint8_t i = 0;i<20;i++)
    displayspeed();

  voltage=roboclaw.ReadMainBatteryVoltage(address, &valid);
    terminal.print("Main Battery Voltage:");
    terminal.print(voltage);
    terminal.println();
}


Top
 Profile  
 
 Post subject: Re: Commands not recognized - Ardiuno
PostPosted: Mon Feb 06, 2012 10:25 am 
Offline
Citizen

Joined: Wed Oct 13, 2010 6:10 pm
Posts: 7
Oops! I posted the wrong files. The previous RoboClaw.cpp did not have the delays at Read4_1 and Read2.


Attachments:
BMSerial.cpp [19.8 KiB]
Downloaded 19 times
RoboClaw.cpp [9.83 KiB]
Downloaded 22 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours [ 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