Need help with Arduino Sketch for Servos

I am totally new to Arduino and need help getting started with some code for a robot I am building. I am starting with 2 servos, both of which will stop at 4 positions, making a total of 16 target positions:

  1. Servo 1 0 degrees - Servo 2 0 degrees
  2. Servo 1 0 degrees - Servo 2 20 degrees
  3. Servo 1 0 degrees - Servo 2 40 degrees
  4. Servo 1 0 degrees - Servo 2 60 degrees
  5. Servo 1 20 degrees - Servo 2 0 degrees
  6. Servo 1 20 degrees - Servo 2 20 degrees
  7. Servo 1 20 degrees - Servo 2 40 degrees
  8. Servo 1 20 degrees - Servo 2 60 degrees
  9. Servo 1 40 degrees - Servo 2 0 degrees
  10. Servo 1 40 degrees - Servo 2 20 degrees
  11. Servo 1 40 degrees - Servo 2 40 degrees
  12. Servo 1 40 degrees - Servo 2 60 degrees
  13. Servo 1 60 degrees - Servo 2 0 degrees
  14. Servo 1 60 degrees - Servo 2 20 degrees
  15. Servo 1 60 degrees - Servo 2 40 degrees
  16. Servo 1 60 degrees - Servo 2 60 degrees

I need the servos to automatically go to one of the 16 target positions when booted. Then I need to instruct the servos to go to different targets, at different rates of speed and remain at each target location for various amounts of time, i.e.

  1. Go to target 1 on start up. Stay there for 10 seconds.
  2. Travel to target 12 in 1.5 seconds. Stay there for 5 seconds.
  3. Travel to target 16 in .8 seconds. Stay there for 2 seconds.
    etc.
    etc.

I will need to write a routine that will run about 4 or 5 minutes and then repeat. During that time there will be a couple of movements that will be repeating very frequently. It will be similar to a rapid hammering motion (target #15 to target #16 and also target #1 to target #2)

My thoughts are that because of the limited storage capacity of the chip and the need for a 5 minute routine, that the 16 positions could be set up as functions and then called as needed. Also, could the hammering motions also be set up as functions to be called and looped? Also, would it be best to use millis to keep all of the movements in sync?

I am totally lost. I have been trying to figure this out for 4 days and am no closer now than I was when I started.

Thank You
I really need help.

Don't forget that you can't control the speed of rotation of a servo. Any given servo will move to the commanded position at a certain rate, determined by the design of the servo and the mass of the load. But, you can send a series of small movement commands with delays in between them, to slow the servo down. You can't tell, from within your sketch code, how quickly the servo has responded.

So if you need fully controllable speed, you may have to use DC motors, stepper motors, or some other type of actuator.

Thank you. I did not know that. Like I said, I am totally new to this stuff. Now, at least I know what I will have to do to control the speed.

Can you or someone else help me with getting started on the sketch? Then I can manipulate the numbers in order to get the timing correct.

Thank You,
Gobbler

First step with servos is to get the Sweep example to work:

Then, try the Knob example:

Once that's working, read the code, understand how it works, make small changes, see what happens, build up from there.

Incidentally, the latest Make Magazine How-To Tuesday video is on servos:

http://blog.makezine.com/archive/2009/02/how-to_tuesday_arduino_101_potentio.html