Hello,
just received my first SV-328 along with the Tamiya motor/gearbox and have some questions on getting started. I’ve installed the AVR-Studio software and have compiled and successfully run the demo examples. I created my own C code example (copying from the routines the demo examples use) to start at (0) then run the motors down (stepping by -1) to (-255) and then jump up to full forward (255) immediately.
I noticed some odd things happening. For example, the code steps the motors from 0 down to -255 but didn’t jump up to full forward (+255). In fact it exited the code and did some sort of reset on the program back to the beginning.
If I changed the code slightly to start at -20 and then ramp down to (-255) and then immediately jump up to (+20) it worked fine. It has me thinking there are some general guidelines that I am missing on how best to program the motors.
My Questions:
-
Is there a guide to using the motor drivers that I can reference that describes the best practices for acceration and/or braking ? (e.g. should the motors be able to switch from full reverse to full forward - or does the hardware not like that ?)
-
(I am not a real HW guy) The motors came with capacitors which I have not soldered on yet. I think they are to be simply soldered across both motor power leads - correct ? (would they have an effect on my simple loop behavior ?)
Thanks for any suggestions and help in getting me started.
(here is my source code - this one works)
#include <pololu/orangutan.h>
int main()
{
// Define variables.
int m1Speed = -20;
int m2Speed = -20;
int bat;
unsigned char button;
//Read the battery and print current miliVolts
bat = read_battery_millivolts_sv168();
lcd_goto_xy(0,0);
print_long(bat);
print("mV");
lcd_goto_xy(0,1);
print("Waiting");
button = wait_for_button_press(ALL_BUTTONS);
//button was pressed, clear the screen and start the pgm.
while(1)
{
set_motors(m1Speed, m2Speed);
//show the motor speed on the lcd display
clear();
lcd_goto_xy(0,0);
print("M1 ");
print_long(m1Speed);
lcd_goto_xy(0,1);
print("M2 ");
print_long(m2Speed);
// wait 1/4 second
delay_ms(200);
//change the motor speed
m1Speed++;
if (m1Speed == 255) m1Speed = -20;
m2Speed++;
if (m2Speed == 255) m2Speed = -20;
} //end while
} //end main