# Servo Replay

i just learned how to control a servo using a potentiometer. how to record a series of motion and replay it??. like i want to record a pot controlled servo motion sequence and then reproduce that previous motion again without turning the pots.. Thanx... :) :) :)

Don't forget memory is very limited. How long is the sequence you want to record?

Yes. But is it possible?? for 30 sec atleast..

ATmega328 chips used in the UNO boards have only 2 Kbytes of RAM, but ATmega2560 chips used in the Mega boards have 8 KB of RAM.

Servos are normally updated every 20-msec or 50/sec, so for the 328 chip, if you read the pot voltage at that rate and store as integer, it saves 100 bytes/sec. So, 2 KB would last for 20 sec.

OTOH, you could probably get by with reading the pot only every 40 or 80 msec, and extend the storage time by 2X or 4X. Due to mechanical inertia, etc, servos don't move very far in just 20-msec, so the slower readings probably won't matter at all.

Another thing you could do is save the pot readings as 8-bit values, v=0..255, and then scale by 4 to get the servo pulsewidths, ie pw = 1000 + (4 * v) usec, and this would double your time again. Again, you'll likely not notice any difference from using 10-bit values, since 90deg * 4usec/1000usec = only 0.36deg.

I haven't thought this through, so the following might be absolute cr@p, but how about recording only important way-points? (Much like on a GPS on a trip, you can hit a button to record certain points rather than recording the whole trip metre by metre....)

If I use the pot to drive my servo from where it is to a certain point, say centre (90) to one side (180), if (and I repeat the if) I don't need to to know that it was at 100 at a certain time, and 110 a tiny bit later, then I could hit a "store" button when it's at the destination to put 180 into an eeprom location (or even just into an array for testing purposes).

Later, when I replay, it would go to 180...

As I say I haven't thought this through but food for thought for a rainy Johannesburg weekend...

One disadvantage with the waypoint scheme is, the servo will slew over to the new positions at maximum speed, whereas with the scheme following the pot values more closely, the servo velocity is controlled by the pot movement.

This is also a problem for servo control in general. Dedicated servo controller chips [ie, good ones] allow you to set the velocity in addition to the target position, and take care of interpolating the points inbetween start and target positions. On an Arduino, you can only get controlled velocities if you specifically include code for this. Otherwise, the servos move at max speed.

One disadvantage with the waypoint scheme is, the servo will slew over to the new positions
at maximum speed

Yep, that is indeed true.

Also, and maybe even more important, the waypoint idea might miss crucial waypoints…

Let’s say it goes from 90 to 180 and back to 175. We could miss the 180 point, and capture the 175. So on replay it would go from 150 to 175, but it might have been important that it go via 180… like that was the point where the gripper opened so we drop a virus sample on the floor instead of in the medical waste… YMMV.