IMG_20150606_155132.jpg (1567209Bytes)
IMG_20150606_155412.jpg (1711662Bytes)
Hey All,
So I’ve been building a rover using a (Dagu) Rover 5 Chassis, a Rover 5 Driver Board and an Arduino Uno.
It’s wired up fine and I can send instructions back and fourth to the motors no problem but what seems to be an issue is the speeds which the motors are turning at. If I can set the speed at 100 (i.e. full) then I would assume that setting it at 50 would make a wheel turn at half the speed it it would at 100, likewise 10 would turn at a 10th of the speed and so on.
I’m setting the wheels just by calling:
digitalWrite(WHEEL_1_DIR, wheel_1_dir);
Where “wheel_1_dir” is an integer between 0 and 100. As implied by the using of an Arduino Uno, I am only issuing commands to two wheels at once (the ‘back’ wheels relative to the direction of forward motion).
Unfortunately this doesn’t seem to be the case. If I set the wheel PWMs to 100 and 50 they move at the same rate. To illustrate this, if I attach some tape onto the caterpillar tracks at the same position:
Then set the wheels running for a few seconds (one at 100, one at 50) the tape on the 100 wheel should move twice as far as the 50 (or at least noticeably further). Instead they seem to travel the same distance:
If you leave it running for a while, one of the bits of tape eventually starts to overtake the other, but what this implies is that while one is slower than the other, it isn’t nearly as slower as you would expect given the scale of the settings.
Wiring wise, the board is set up according to this:
Code I’m using in the Arduino package is as follows
#include
// General Constants
#define HEARTBEAT_MS 1000
#define LED_PIN 13
// Right Wheel Constants
#define WHEEL_1_PWM 12
#define WHEEL_1_DIR 11
// Left Wheel Constants
#define WHEEL_2_PWM 8
#define WHEEL_2_DIR 7
// Wheel Encoders
Encoder wheel_1_encoder(3, 10);
Encoder wheel_2_encoder(2, 6);
// General Variables
static char buf[100];
static char buflength = 0;
static unsigned long last_heartbeat;
int led_status;
int i, j, k, l, m;
// Wheel Variables
static float wheel_1_pwm;
static int wheel_1_dir;
static int wheel_1_count;
static int new_1_count;
static float wheel_2_pwm;
static int wheel_2_dir;
static int wheel_2_count;
static int new_2_count;
// Navigation Variables
static float targetDist;
static float targetAngle;
static float currentDist;
static float currentAngle;
static boolean return_home;
void setup()
{
pinMode(LED_PIN, OUTPUT);
// It should be noted that wheels are paired - 1 & 4 and 2 & 3
pinMode(WHEEL_1_PWM, OUTPUT);
pinMode(WHEEL_1_DIR, OUTPUT);
pinMode(WHEEL_2_PWM, OUTPUT);
pinMode(WHEEL_2_DIR, OUTPUT);
Serial.begin(115200);
last_heartbeat = millis();
}
void loop()
{
// Check if it’s time to send a heartbeat
if (last_heartbeat + HEARTBEAT_MS <= millis())
{
sendHeartbeat();
last_heartbeat = millis();
}
// Read from encoders
new_1_count = wheel_1_encoder.read();
new_2_count = wheel_2_encoder.read();
// Update counts
if( new_1_count != wheel_1_count || new_2_count != wheel_2_count)
{
Serial.print("w4 = ");
Serial.print( new_1_count );
// wheel 3's encoder inverted (it thinks forward is backward and vice versa)
Serial.print(", w3 = ");
Serial.print( new_2_count );
Serial.println();
wheel_1_count = new_1_count;
wheel_2_count = new_2_count;
}
// Read in from the input (if there is any)
if (Serial.peek() != -1)
{
delay(5);
do
{
if (buflength >= 100)
{
buflength = 0;
}
buf[buflength++] = (char) Serial.read();
}
while (Serial.peek() != -1);
// Process the buffer
process_buf();
}
}
void sendHeartbeat()
{
Serial.print("w1: “);
Serial.print(wheel_1_pwm);
Serial.print(”, ");
Serial.print(wheel_1_dir);
Serial.print(" w2: ");
Serial.print(wheel_2_pwm);
Serial.print(", ");
Serial.print(wheel_2_dir);
Serial.print(" delta: ");
Serial.print(currentDist);
Serial.print(", ");
Serial.println(currentAngle);
}
bool process_buf()
{
// Check there hasn’t been some error
if (buflength == 0)
{
return false;
}
// Input should be of the form "l <w1 speed>, <w1 dir> r <w2 speed>, <w2 dir> n"
for (i = 0; i < buflength; ++i)
{
// If we find an 'l'
if (buf[i] == 'l')
{
// Extract <w1 speed>
for (j = i + 1; j < buflength; ++j)
{
if (buf[j] == ',') break;
}
// If ',' wasn't found, the message improperly formed
if (j == buflength)
{
return false;
}
// make the ',' whitespace so atoi will stop at it
buf[j] = (char) 0;
wheel_1_pwm = atof(buf+i+1);
digitalWrite(WHEEL_1_PWM, wheel_1_pwm);
// Extract <w1 dir>
for (k = j + 1; k < buflength; ++k)
{
if (buf[k] == 'r') break;
}
if (k == buflength)
{
return false;
}
buf[k] = (char) 0;
wheel_1_dir = atoi(buf+j+1);
digitalWrite(WHEEL_1_DIR, wheel_1_dir);
// Extract <w2 pwm>
for (l = k + 1; l < buflength; ++l)
{
if (buf[l] == ',') break;
}
if (l == buflength)
{
return false;
}
buf[l] = (char) 0;
wheel_2_pwm = atof(buf+k+1);
digitalWrite(WHEEL_2_PWM, wheel_2_pwm);
// Extract <w2 dir>
for (m = l + 1; m < buflength; ++m)
{
if (buf[m] == 'n') break;
}
if (m == buflength)
{
return false;
}
buf[m] = (char) 0;
wheel_2_dir = atoi(buf+l+1);
digitalWrite(WHEEL_2_DIR, wheel_2_dir);
delay(10);
i = k;
}
}
buflength = 0;
return true;
}
Can anyone provide some advice as to what is causing this?