Arduino - Speed controller issue

Please post all questions and answers in here. This way people can easily see if someone else has the same problem.

Moderators: BeligerAnt, petec, administrator

Post Reply
User avatar
malivoirec
Posts: 186
Joined: Fri Mar 09, 2007 9:38 pm
Location: Tunbridge Wells, Kent

Arduino - Speed controller issue

Post by malivoirec »

Hey guys, I am having an issue of one of my Uni projects that I hope I could get some help with. What I am trying to do is run a Barello ant 100 and a Sozbot ant controller being controlled by an Arduino Uno board to control some motors rather than a shield. I am using the code from this tutorial below used on a Sabertooth as a base.

http://www.instructables.com/id/Control ... ogramming/

The issue is that on the speed controllers that I am using, the failsafe are being triggered every time as it believes that there isn’t a signal. As I cannot turn off the failsafe on the boards, is there a way to get around this in the code? I would appreciate if someone can explain or even give me a code snippet of a solution.
Fortune cookie says: Pain is meerly a feeling;
unless its PERMANANT FOREVER.

Fortune cookie no.2 says: Take heed of
Last cookie
StuartL
Posts: 36
Joined: Sun Mar 24, 2013 12:38 pm
Location: Berkshire, UK

Re: Arduino - Speed controller issue

Post by StuartL »

That code looks overly complex to test a simple servo connection. I would strip it back to control a single speed controller, so one Servo object, no serial link and just hard-code a pulse-width to begin with. 1.5ms (1500us) is the mid-point so maybe code 1250us as your test value. That way your speed controller should slowly drive the motor forward or backward if you wire it up correctly.

Check your pin numbers, too.
User avatar
malivoirec
Posts: 186
Joined: Fri Mar 09, 2007 9:38 pm
Location: Tunbridge Wells, Kent

Re: Arduino - Speed controller issue

Post by malivoirec »

Thanks, I've check the PIN numbers and their all correct. I might be a bit of an ask but could you please show me how to implement this into the code
Fortune cookie says: Pain is meerly a feeling;
unless its PERMANANT FOREVER.

Fortune cookie no.2 says: Take heed of
Last cookie
StuartL
Posts: 36
Joined: Sun Mar 24, 2013 12:38 pm
Location: Berkshire, UK

Re: Arduino - Speed controller issue

Post by StuartL »

Disclaimer: I don't have an Arduino to test this on and haven't developed for Arduino before. The code below is based upon my interpretation of the reference guide I found here: http://arduino.cc/en/Reference/Servo

You run the code below at your own risk.

Something very basic might be:

Code: Select all

#include <Servo.h>
Servo myservo;
const int servopin = 9;

void setup() {
  myservo.attach(servopin);
  myservo.writeMicroseconds(1250);
}

void loop() {
}
This will set the speed controller to slowly go in one direction and then do nothing else.

If you want to see it change speed you could do something like...

Code: Select all

#include <Servo.h>
Servo myservo;
const int servopin = 9;
int delta = 100;
int start = 1000;
int end = 2000;
int current = start;

void setup() {
  myservo.attach(servopin);
}

void loop() {
  current += delta;
  if (current >= end) {
    delta = -delta;
    current = end;
  } else if (current <= start) {
    delta = -delta;
    current = start;
  }
  myservo.writeMicroseconds(current);
  delay(1000);
}
The above example will cycle the speed controller from full forward to full backward and back again, continuously.
User avatar
BeligerAnt
Posts: 1872
Joined: Wed May 15, 2002 12:00 am
Location: Brighton
Contact:

Re: Arduino - Speed controller issue

Post by BeligerAnt »

Stuart's code looks about right, it's very simple to do things like drive servos with the Arduino. :)

The second example will possibly trip the failsafe. If it does, it will be because the pulse width is too small (or possibly too big). In this case, change the value of "start" in line 5 and run the code again. Repeat until the failsafe stops falling over. If you get to 1200 or so and it still fails, try reducing the value of "end" in line 6.

Remember to save, build and download the code every time you change it! :)

If the failsafe still trips, check the supply voltage to the speed controller. Make sure you have a decent ground connection between the Arduino and the speed controller.
It might also be worth checking the Arduino with a standard servo.
Gary, Team BeligerAnt
User avatar
malivoirec
Posts: 186
Joined: Fri Mar 09, 2007 9:38 pm
Location: Tunbridge Wells, Kent

Re: Arduino - Speed controller issue

Post by malivoirec »

Thanks a lot its worrking now.
Fortune cookie says: Pain is meerly a feeling;
unless its PERMANANT FOREVER.

Fortune cookie no.2 says: Take heed of
Last cookie
Post Reply