Shop OBEX P1 Docs P2 Docs Learn Events
Using the SX28 to sync servo movements with music — Parallax Forums

Using the SX28 to sync servo movements with music

DosManDanDosManDan Posts: 179
edited 2007-03-22 19:57 in General Discussion
I've searched the boards and haven't found any messages that talk about how to sync servo movements with music. Thought·I would post the question and ask if anyone has found any articles covering this topic.

I'm using an SX28 to controll the servos, the movements will be stored using 24LC16B EEPROM chips. I will be using a separate SX28 to sync the different characters·using 433 Mhz wireless communications.

My initial thought is to divide the movements into 1/2 second intervals and start the music and servo movements at the same time. Retrieve the next set of movements (for all servos) every 1/2 second.

Is there a better way to do this?

Thanks again,
Dan

Comments

  • PJMontyPJMonty Posts: 983
    edited 2007-03-22 16:44
    Dan,

    There are better (e.g. more complicated) ways of doing this, but your basic approach is sound. The more complicated approaches involve timecode, either SMPTE or MIDI, and slaving both the music and the animation to the timecode. This is a ton of work.

    Your approach is to basically trust that since you're running the servos from a crystal based CPU and the sound card has a crystal based CPU, that the two devices will remain in sync. If your animations aren't too long, you should have no problem. If they go on too long (a few minutes? Ten minutes?), then you run the risk of drift due to the two crystal timebases not being perfect.

    I use this basic technique for my Halloween animatronics. Here's the website:

    www.SoCalHalloween.com

    You can check out the video page to see the results in action:

    www.socalhalloween.com/html/videos.html

    Bear in mind that I am running my animations at 24 frames per second, as opposed to your proposed 2 frames a second. As a result, my animations are very fluid and smooth. Sync won't be an issue, but don't expect similar smoothness at the low update rate your are planning. Other than that caveat, your approach is good.

    Thanks,
    PeterM
  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-03-22 16:48
    That's actually a very complex topic and one that interests me as well. For my May Nuts & Volts column I built a board with an SX28 that will take a control stream from a PC to move servos an control eight digital outputs for solenoids. My will use a PC to play sound and send the control values. Ultimately, I will move the control values into an EEPROM (24LC1025) using some kind of RLE to compress as much data into the EE as possible. The audio will be moved to a digital audio player like the Rogue uMP3.

    I've attached a picture of my article project (SX28 slave; no EE).

    And yes, my project was inspired by PJMonty's work -- I've seen his (incredibly cool) animation system up close as I live just a couple miles from him.
    640 x 480 - 383K
  • DosManDanDosManDan Posts: 179
    edited 2007-03-22 17:01
    I've been to your site before and·your work is·impressive! I saw the software you wrote and I'm guessing you are using a multi channel approach with one channel controlling your servos.

    I'll speed up the servo sampling then, to smooth out the animation. The sync between the different characters is coming over a wireless connection because of the distance between the two (30 ft). I'm doing a small battle scene where a smoke cannon is fired from one position at another. Then, the other position fires back. A sync signal will be sent when one cannon fires, this will account for any lag loading the cannnon (smoke machine, trigger mechanism, etc.).

    Thanks for your input, I really appreciate it. And, to anyone that hasn't seen the SoCal website...go look!

    Dan
  • PJMontyPJMonty Posts: 983
    edited 2007-03-22 17:14
    Dan,

    Glad you liked it. As for increasing your framerate, it sounds like you only need to increase it enough to let you hit musical beats. 4 or 8 frames per second should be sufficient resolution to let you hit your beats.

    In my system, the software on the PC streams 8 channels of servo data at 24 FPS and feeds the servo controller hardware. I also double buffer so that I'm playing back one section on animation while pre-loading the next. This is important in my system since multiple devices are sharing the same RS-485 serial network, and I can't afford to have the animation have glitches or hiccups if data doesn't arrive in time.

    On your system, it sounds like you're pre-storing your animation in the EEPROM. It also sounds like you only have discrete events (fire the cannon, etc), so smooth animation isn't the issue as much as sync. In that case, I would use a fixed framerate (4, 8, 10 FPS) and store the data as the number of frames at that rate. Store the data as two sequential bytes. The first byte is the number of frames to wait, and the second number is treated as a binary representation of the trigger outputs.
    4   %00000000
    8   %00000100
    20  %00000000
    6   %00000001
    67  %10000001
    5   %00000000
    
    



    IN this case, the first number is shown in decimal and says how many frames to wait. The second number if shown in binary so you can more easily see the bits turn on and off. Note that in the 4th event, we turn on bit, but another event triggers 67 frames later so we make sure that bit 3 is still turned on there as well. finally, on the last event, we turn both triggers off. You can also wait zero frames and have something trigger right away.

    Thanks,
    PeterM
  • DosManDanDosManDan Posts: 179
    edited 2007-03-22 17:31
    I've read a ton of your posts Jonny, and I can't tell you how much help they have been.

    I'm trying to avoid using a PC for the sound control and I'm trying several other approaches. First, each character will be using a WinBond ISD4004 chip to store their voices. It holds about 16 min of sound. I'll be wiring one up this weekend to check the sound quality.

    You are correct, I'm going to trust that the clocks stay in sync during the two minute scene. If not, I'll have to work out a different approach. I was toying with the idea of having a master DS1307 clock, and sending out a sync pulse at the start of the sequence. Any thoughts?

    Because of the distance between the characters, I'll be using 433Mhz wireless for communications. I already have this wired up and it's working.

    As a side note, I'm starting to wonder how much I can tax one single SX28 before I have it doing too much. So far, I haven't hit that wall yet. I have one chip, in my master controller, running an LCD panel, 433Mhz Receiver, transmitter and keypad.

    Thanks for posting the pic too, very clean design! Are you making your own pc boards at home? I've seen several kits online and was debating on trying them.

    Dan
  • DosManDanDosManDan Posts: 179
    edited 2007-03-22 17:57
    Thanks for the info on the frame data, that was what I needed. I was close to the solution, but your note cleared it all up for me. I'll be storing servo position data as well.

    You are correct, I'm pre-storing the movement data on the EEPROMs; since I don't want to use a PC if I can avoid it. As a way of keeping things in sync, I intend to retrieve the same memory address on each controller at the same time. Basically, I'm using the memory addresses as the Frame #.

    Servo data is 2 bytes: Servo# and Servo Pos

    So, frame calculations would be:

    ·Base Address + ((# of servos· x 2) x Frame Number)

    I cases where there is no movement, the memory address will simply contain zeros. This approach definitely doesn't win any awards for efficiency of memory use....but, memory is cheap...hehe.

    The servo positions are loaded into an array, and the array is scanned and the positions are updated at regular intervals.

    I appreciate you spending time answering my posts, I know how busy you must be,
    Dan
  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-03-22 18:23
    Dan,

    My project is moving in stages so I will, ultimately, move the control into a board (like the EFX-TEK Prop-SX) that has an EEPROM. Since servos need to be refreshed every 20 ms I have an ISR in my code that handles that. In my EEPROM approach I'm going to use an 10-byte record:

    DigOuts - Svo1 - Svo2 - Svo3 - Svo4 - Svo5 - Svo6 - Svo7 - Svo8 - Repeats

    The foreground program will load the first nine bytes into the control array used by the ISR for servo position refreshing. The final byte, repeats, will be used to decrement a frame rate timer. This is a very simple compression scheme that saves me from filling the EEPROM with redundant records when nothing is changing frame-to-frame. I'm thinking 20 ms frame rate to keep things simple as I have that in the ISR already, but I've seen Peter's system running at 24 FPS and it is spectacular. Using a lower frame rate means I can pack more animation into the same EEPROM.

    What I'm wanting to do is create a piece of open-source software (that way I can get others involved) that will let me create the animations and then dump the output of the into the EEPROM of my controller. As I stated earlier, the controller will send a start signal to the audio player before moving the servos and setting the digital outputs. In the end, really, my project is a home-brew version of Brookshire's VSA and RAPU.

    The PCB was for my Nuts & Volts column; I've attached the ExpressPCB files so you can see how simple my hardware actually is. I haven't etched a board at home since I was a kid (that was a while ago) and with the low cost and high quality of the ExpressPCB MiniBoard service I wonder if I ever will again....
  • DosManDanDosManDan Posts: 179
    edited 2007-03-22 18:59
    Thanks! I'll have to look those over at home. I had considered the RAPU, but I wanted to see if I could make one myself. If not, that will be my fallback plan.

    One of the EFX guys posted some ISR code and I'm looking over it deciding if I can use some portions of it on my controller.

    I'd be willing to work with you on the software you mentioned. I'm a Sr. Software Engineer, with about 20yrs experience. I realize I'm going to need a way to record all the movements and transfer them to the EEPROMs. Considered building a small controller with a ZIF socket, a rotary selection dial and slider switch. I can·select the servo number using the rotary dial, then set the position with the slider and save all servo positions·to the EEPROM when I push a button. Of course, I can eliminate the rotary dial and just use 6 sliders instead. Or, we can write software and make this waaay easier· ;-)

    Is the EFX SX prop controller out yet? I checked a while back and they said it was comming soon.

    I've looked at Express PCB, if you are happy with them, guess I can give them a try too.

    Thanks again,
    Dan
  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-03-22 19:29
    Dan,

    I'm that EFX guy... JonnyMac is Jon Williams (my professional name for acting is Jon McPhalen, hence the JonnyMac moniker).

    No, the Prop-SX is not out yet; should be soon. After some feedback from the first run of Prop-2s (which use the same PCB, just populated a bit differently) we're making a couple small adjustments (e.g., we're adding a resistor on the EEPROM SCL line that is not required by the BS2, but will be needed for the SX/B I2C routines).

    I've attached a screen shot of my article PC control program. Perhaps you can do something like that using a small controller/EEPROM programmer on the end of the serial port. The sliders would let you set you servo positions and a record button could dump those values into your EEPROM. In my project the slider and digital control button values are simply streamed out to the controller every 20 ms when the selected serial port is opened.

    ExpressPCB works for what I do -- for me the $60 price of three boards is worth it; I could save a few bucks etching my own boards but the time involved would cost me more than the ExpressPCB boards. I like that I can enter a schematic in ExpressSCH and then link it to the board file; this helps me get all the connects right the first time.
    363 x 489 - 133K
  • DosManDanDosManDan Posts: 179
    edited 2007-03-22 19:57
    How funny, sorry that I didn't make the connection that you were the same person. Nice code! Ok, now I feel like a total dork....

    Your picture is exactly what I had in mind. At least it looks like I'm on the right path. I'll definitely buy one of the EFX boards and give it a try. I'm impressed that you took the time to answer my questions, it shows your dedication for the product.

    I'll post a few pics when I get things looking good!

    Thanks again for you help,
    Dan
Sign In or Register to comment.