I am using an SVP-1248 and I can get the examples to run, but when i try my own I can only get the motors to work when the speed is 100 or less.
Here is the sample program that works just fine all the way from -255 to +255:
#include <pololu/orangutan.h>
#include <avr/interrupt.h>
int m1_speed = 0;
int m2_speed = 0;
void motor_test()
{
static char m1_back = 0, m2_back = 0;
if(button_is_pressed(TOP_BUTTON))
{
if(m2_speed == 0)
{
delay_ms(200);
// If the button is pressed quickly when the motor is off,
// reverse direction.
if(!button_is_pressed(TOP_BUTTON))
m2_back = !m2_back;
}
m2_speed += 10;
}
else
m2_speed -= 20;
if(button_is_pressed(BOTTOM_BUTTON))
{
if(m1_speed == 0)
{
delay_ms(200);
// If the button is pressed quickly when the motor is off,
// reverse direction.
if(!button_is_pressed(BOTTOM_BUTTON))
m1_back = !m1_back;
}
m1_speed += 10;
}
else
m1_speed -= 20;
if(m1_speed < 0)
m1_speed = 0;
if(m1_speed > 255)
m1_speed = 255;
if(m2_speed < 0)
m2_speed = 0;
if(m2_speed > 255)
m2_speed = 255;
set_motors(m1_speed * (m1_back ? -1 : 1), m2_speed * (m2_back ? -1 : 1));
delay_ms(50);
}
int main()
{
while(1)
{
motor_test();
}
}
Here is my code that wont work if the speed is over -/+100:
#include <pololu/orangutan.h>
#include <avr/interrupt.h>
void stop_robot()
{
int m1_speed = 0;
int m2_speed = 0;
//start motors
set_motors(m1_speed, m2_speed);
}
void move_robot_forward()
{
int m1_speed = 200;
int m2_speed = 200;
//start motors
set_motors(m1_speed,m2_speed);
}
void move_robot_backward()
{
int m1_speed = 200;
int m2_speed = 200;
//start motors
set_motors(-m1_speed,-m2_speed);
}
int main()
{
while(1)
{
if (button_is_pressed(TOP_BUTTON))
{
move_robot_forward();
}
if (button_is_pressed(MIDDLE_BUTTON))
{
stop_robot();
}
if (button_is_pressed(BOTTOM_BUTTON))
{
move_robot_backward();
}
}
}
I am kinda new to c/c++ its been awhile so I figure that I am coding something wrong. But I just cannot see it.
If anyone can spot my problem, that would be cool.
Thanks,
John