Any suggestions for how to make one cog wait for another to finish?
Matthewjgingerich
Posts: 1
I'm building a stepper motor controller, and each motor runs in its own cog. Cog zero launches a motor controller in cog one that moves a motor to a specified position and speed. Cog one then finishes and shuts down, and is relaunched when I send a new command to the motor. The problem is that cog zero must wait for cog one to finish moving the motor and shut down before it sends the next command, otherwise the motor gets multiple instructions at once. I tried to use variables and results but couldn't get it right. Any ideas?
Comments
Have the first cog set a variable to zero. The first cog then launches the second cog which knows the address of the variable. The first cog then spins in a repeat loop until the variable becomes not zero. The second cog sets the variable to not zero when finished.
Thanks,
Welcome to the forum!
I feel compelled to ask: why use separate cogs when their operation appears to be sequential? Is there a way that you can combine the command receipt and execution into a single cog? Then you would not have to worry about launching a new cog and waiting for it to finish.
-Phil
I suspect because, as stated by the OP, there are multiple motors with a cog for each - the controlling code runs in a separate cog so it can run all the motors at once - we can presume this is some sort of positioning system or CNC application. Another common reason for inter-cog communication is because one cog is Spin and the other is in PASM.