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

Pololu Forum

Command set_motor not work


#1

hi
i use mcu svp1284 to program line following . In void calibrat() I command motor to sweep
but it not work.what happend.
this is my code

void calibrat()
{
	clear();
	print("calibrat");
   set_motors(0, 0);
	// Wait 1 second and then begin automatic sensor calibration
	// by rotating in place to sweep the sensors over the line
	delay(3000);
	for(uint16_t i = 0; i < 100; i++)
	{
		if (i > 25 && i <= 75)
		{
			 set_motors(-100, 100);			
		}
		else		{
			 set_motors(100, -100);
		}
		calibrate_line_sensors();
	}
	print("stop");
				 set_motors(0, 0);
	delay(3000);
	
}

#2

Hello.

I added code tags to your post to make the code more readable. Please remember to format your code in future posts. For details, click on the pencil icon in the upper right-hand corner of the edited post and view the raw source to see the modification.

Edit: Sorry, this paragraph is wrong, please see my post below.
I looked at your code and noticed you are using delay(), which is not a function in the AVR delay library and can cause your program to freeze. You should use delay_ms() or delay_us(). See the documentation for those functions here for more details.

If that does not resolve the problem, can you elaborate what you mean by the code not working (e.g. the motors do not sweep left)? It might be helpful for you to look at the 3pi’s line follower code (in test.c) to get an idea of how the 3pi sweeps across a line while auto-calibrating its sensors.

- Amanda


#3

hi amandaS
i have check my code and add delay_ms(20); in each step so motor can run.
this is my code
void calibrat()
{
clear();
print(“calibrat”);
set_motors(0, 0);
// Wait 1 second and then begin automatic sensor calibration
// by rotating in place to sweep the sensors over the line
delay_ms(3000);
for(uint16_t i = 0; i < 100; i++)
{
if (i > 25 && i <= 75)
{
set_motors(-100, 100);delay_ms(20);
}
else
{
set_motors(100, -100);delay_ms(20);
}
calibrate_line_sensors();
}
print(“stop”);
set_motors(0, 0);
delay_ms(3000);
}

next step i like to show bargraph but it can not show
this is my code

void showReadings()
{
clear();
print(“show reading”);
delay_ms(3000);
unsigned char button = wait_for_button_press(TOP_BUTTON | BOTTOM_BUTTON);
while(!button == TOP_BUTTON)
{
qtr_calibrate(QTR_EMITTERS_ON);
lcd_goto_xy(0, 0);
for (uint8_t i = 0; i < NUM_SENSORS; i++)
{
uint8_t barHeight = map(1000-lineSensorValues[i], 0, 1000, 0, 8);
printBar(barHeight);
}
}
}

i dont know how to fix it .

when i compile .it have 0 error 4 warnning

Severity Code Description Project File Line
Warning unused variable ‘button’ [-Wunused-variable] orangutan_app34 C:\Users\asus1\Documents\Atmel Studio\7.0\orangutan_app34\orangutan_app34\main.c 144
Warning passing argument 1 of ‘print’ makes pointer from integer without a cast orangutan_app34 C:\Users\asus1\Documents\Atmel Studio\7.0\orangutan_app34\orangutan_app34\main.c 37
Warning implicit declaration of function ‘map’ [-Wimplicit-function-declaration] orangutan_app34 C:\Users\asus1\Documents\Atmel Studio\7.0\orangutan_app34\orangutan_app34\main.c 87
Warning implicit declaration of function ‘calibrate_line_sensors’ [-Wimplicit-function-declaration] orangutan_app34 C:\Users\asus1\Documents\Atmel Studio\7.0\orangutan_app34\orangutan_app34\main.c 60


#4

Sorry, I was confused about the delay functions. To clarify, delay(), delay_ms(), and delay_us() are defined in our AVR library and documented in the “Timing and Delays” section of the Pololu AVR Library Command Reference. They are different from the avr-libc delay functions that I linked to in my previous post. Calling delay() in your original code was fine and shouldn’t have caused any issues.

Did you fix your original issue with your motors? It is not clear from your post.

Can you post your entire Atmel Studio project so I can see how it is configured and your entire code?

By the way, you might find it helpful to look at the 3pi’s demo code, specifically ir_test() in the 3pi demo program, to see how it displays a bar graph on the 3pi’s LCD screen.

- Amanda