Motor Control Programming - Getting Started

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:

  1. 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 ?)

  2. (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

Hello,

Have you seen the Orangutan motor driver app. note? I’m not sure which motors you’re using, but the ones that come with the Tamiya gearbox are not recommended for use with anything other than the Orangutan LV. The stock motors from Tamiya are made for 3V, and they are very electrically noisy. They will also draw more current than the Orangutan SV driver can deliver, and trying to switch direction at full speed will make things worse. I also don’t recommend doing that for the sake of everything else in your system.

- Jan

Hello,

We have two motor driving guides that might be of interest: the first is the 3pi user’s guide section on motors and gearboxes, and the second is our Orangutan motor driving application note. Switching motors from full forward to full reverse can draw up to twice the stall current for a brief moment. What kind of motors are you using and how are you powering the SV-328? For example, if your power supply cannot supply twice the stall current of your motors, then transitioning from full forward to full reverse can cause the supply voltage to drop precipitously, leading to a reset of the MCU.

The Orangutan motor driving application note has a section about dealing with motor noise with capacitors. It is likely that motor noise is causing some additional strain on your power supply.

- Ryan

Thanks jan and Ryan for the replies!
The app note and other references will help a lot. I’ll check them out.

I power the SV-328 with (6) ‘AA’ batteries to give me 9V.

It looks like I need to get a better match for the motors.
I had ordered the Chasis kit which came with the 70097 motor gear box and after closer reading see that they recommend it with the LV-328 controller.

Looks like I can replace these motors with 130 size, 6V, 11.5K RPM 800mA Stall motors (item #1117) and be in better shape for my SV-328. If you have any other comments or suggestions on motors (for a non-HW newbie) please let me know.

Thanks again for the help.