Synconizing multiple Baby Os with a Mega

Hey Everyone,

I’m working on a project that uses a Mega as the main micocontroller and has 3 Baby Os to output a PWM. The problem is that I need to sync up the pwm so that the legs on our robot are synced. I came up with an idea using an input and output on the Baby O and 3 Inputs and 3 outputs on the Mega. I am worried that I might experience a deadlock or that there is an easier way to accomplish this. If there’s an available example, please show me.

Here is my psuedo code:

MEGA
while(){
   //Turn on Mega's pins
   pin1=pin2=pin3='on'
   
   //do normal stuff

   //wait for Baby O to finish
   while(!pinA || !pinB || !pinC) {}
   pin1=pin2=pin3='off'

   //Wait for Baby O pins to turn off
   while(pinA||pinB||pinC) {}

}
BABY O
while(){
   //wait for Mega's signal
   while(!pin1) {}

   //Do normal stuff (drive motor)

   //Set output to high to tell Mega that the Baby O is finished
   pinA = 'on'

   //Wait til Mega goes low to finish
   while(pin1) {}
   pinA= 'off'
}

Thank you guys for your help and insight!
-Seth

Hi, Seth.

It sounds like you are doing something kind of weird. Is there a reason you cannot use motor drivers for the three legs? Are you trying to maintain synchronization without closed-loop feedback control? I think you are likely to find it hard to keep the legs in sync without some kind of feedback. Right now, it seems like you want the subordinate controllers to be partially in control of what is going on. Is there a reason for this? Are the Baby Orangutans doing something that does not take a deterministic amount of time to complete? If it is deterministic, I think you’d probably be better off getting rid of the the signal from the Baby Os to the Mega and just having the Mega be completely in control.

- Ryan

Hey Ryan,

Let me give you a little more indepth explanation of what we’re trying to do. We’re making a rHex (it’s a 6 legged robot). We have a Wifly module hooked up to the Mega which is communicating with the 3 Baby Os(a single Baby O outputs two PWMs) over a serial port. Each leg has its own control law to follow. We drive the motor with a pwm with a width that corresponds to the control law. One of the factors of the control is an encoder line from the motors since the law depends on the position of the leg. The Mega that we’re using (the 2560) has enough PWMs but we don’t think it will be able to handle all 6 control laws and the data from our wireless card. We’re using the Baby Os just to implement the control law and the Mega will be the liaison between the wireless card and the Baby Os.
As for the Baby Os wanting to be in control of what’s going on, we just want them to know when to stop and when to go forwards/backwards.
With all of that said, do you think it would be best to keep our current set up or should have the Mega handle the control laws and wireless communication?

Thanks again for the help!

I don’t know the answer to your last question; it would require a lot of specific calculations and information to answer. However, your explanation has given me a better understanding of what you are doing now and it sounds like an okay idea. If all you need is for the Baby O’s to know when to stop, go forwards and go backwards, why do they need to communicate back to the Mega?

- Ryan