I posted this in the Storage section a few days ago because at the time I was trying to figure out if what I wanted to do would work with an SD Card. The answer was yes. So now I'm moving on to the actual programming aspect of the same thing. The idea is as follows:
I have two servos that will function as a pan and tilt system. I'm going to cue them with music. I have several cue points during the audio piece where I need the servos to do something. Taking a page from a similar broadcast system, I thought I could have a single text file with commands listed in it like so:
angle_pan speed_pan angle_tilt speed_tilt pause
90 2 90 2 5
45 4 90 0 2
135 4 90 0 5
Which I would read in as:
- move the pan servo to 90 degrees with speed = 2, move the tilt servo to 90 degrees with speed = 2, wait for 5 seconds.
- after 5 seconds, move the pan servo to 45 degrees with speed = 4, leave the tilt servo at 90 degrees, wait for 2 seconds.
- after 2 seconds, move the pan servo to 135 degrees with speed = 4, leave the tilt servo at 90 degrees, wait 5 seconds.
Etc., etc. (speed will be somewhere between 2 (fast) and 10 (slow))
The controller's code will then open the SD card, and read the file in bit by bit as it needs to and move the servos as needed.
I choose this method primarily because then I don't have to do anything with the actual code on the controller, just the text file that's on the SD card. The controller simply reads it in as needed. When I need to change what the servos do, I simply update the SD card with a new file (for a different piece of music), and off I go.
My question is, is this the best way of doing this. Will I have to content with a lot of lag between the time it takes for the data to be read from the SD card each time? I don't plan on reading the whole thing in at the beginning of the program, it will be too big to fit in memory. So I'll constantly be reading from the card and pass instructions to the servos.
Does anyone have suggestions on how to improve this system, or even come up with a different design perhaps? I suppose I can always add a DataFlash chip on the controller board. The controller then reads the whole file from SD card into memory for faster access. I don't know if that would really make much of a difference though.
Ideas/suggestions anyone?