LV- code question

I am trying to run a small robot with the LV-168. I wan to do the follwoing while conserving as much power as possible:
Stop for some time;
Go foraward for some time;
make a left;
Go forward for some time;
make a left;
and repeat similar paths.

This is my initial code for the three first comands:
#include <pololu/orangutan.h>
int main()
{
delay_ms(1500); //wait for this long
set_motors(250, 250); // set speeds of motors 1 and 2 to go forward
delay_ms(4500); //for this long
set_motors(0, 0); //this is the only way I can stop before next command
delay_ms(10);
set_motors(-250, 250); // make a left
etc.

However, I would like to use just the delay (delay_ms(5000) for example) to make the robot stop before the left command instead of using the hard stop comand I have right now. But when I put the delay_ms(5000) for example the robot keeps on going.
Can someone help?

Hello.

The motors will keep going at their current speeds until you set them to new speeds. If you want to stop, you need to set their speeds to zero as you are already doing. Why do you want to avoid this step?

- Ben

Because I suspect it takes more current to ubruptly stop and restart rather then just stoping automatically when the delay time is reached:
Example:
set_motors(250, 250); // set speeds of motors 1 and 2 to go forward
delay_ms(4500); // for this long and then it should stop

I’m still not very clear on what you’re asking. Is your main objection the abruptness of the stop? What is the difference between stopping “abruptly” and stopping “automatically”? Do you want the motors drive for 4.5s and then coast to a stop (and if so, the 4.5s delay is pretty much irrelevant; why not just ask how to coast to a stop?)? Do you want the motors to spend the duration 4.5s period gradually slowing down? Stopping abruptly is a passive process that does not draw power from your batteries; power is only being drawn from your batteries while you are trying to drive the motors.

- Ben

I want to go forward for 4.5s, then make a left and continue forward. I just wonder why the controller does not stop the motors after the time delay of 4.5s unless I tell it to stop. When using another controller, I was able to control the duration of my comands through the delay_ms after the comand.

In the Pololu AVR library, the motor commands are independent of the delay functions. The motor commands set the motor speed and the delay functions delay program execution; you need to string them together in order to get the sequences you desire. When you want the motors to stop, you need to command them to stop by setting their speeds to zero. By the way, if you want to transition from forward into a turn, you don’t need to stop first. You can just set the motor speeds to those needed to achieve a turn after the appropriate delay.

- Ben