Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Motors wont go full speed


#1

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


#2

Hello,

Did you read my post on getting help? Most of the points in that post apply to your problem. In particular, you need to tell us in detail about every single thing that you have connected and consider removing each component to see if the problem goes away. You also need to tell us what the problem actually is. What happens with it does not work? Does behave better with the motors removed?

It is great that you show working and non-working code, but you could reveal more about the problem by making these two programs much simpler. For example, can you write a program that does not do anything with buttons, but just sets the motor speed to 100? Then make a non-working one that is exactly the same but with the speed set to 101?

Based on your description so far, I am guessing that your motors are just taking more current than what either your batteries or the SVP can provide, but it is hard to be sure.
-Paul