Cogs launching Cogs, is it necessary?
I've been trying to wrap my mind around this for hours (coding, reading and looking through the forum) and I'm still stumped, so sorry if it's an obvious question. I want two processes to operate independently (In their own cogs?) that need to launch their own cogs and update global variables that can be read by the top object.
For example, I would like an independent scan routine for two servos (with Ping modules) to continuously scan and update a set of variables. For this to be completely asynchronous to the main program I was going to assign a cog to each servo. I was also going to use PWM_32_v2 as the servo controller, but since the method is in assembly, I'm under the assumption that it needs to be launched in its own cog. Is that correct.
To do this will I have to launch a cog that does the scan routines and have that launch a cog that runs the PWM_32 code, taking up 4 cogs?
Thanks in advance,
Todd
For example, I would like an independent scan routine for two servos (with Ping modules) to continuously scan and update a set of variables. For this to be completely asynchronous to the main program I was going to assign a cog to each servo. I was also going to use PWM_32_v2 as the servo controller, but since the method is in assembly, I'm under the assumption that it needs to be launched in its own cog. Is that correct.
To do this will I have to launch a cog that does the scan routines and have that launch a cog that runs the PWM_32 code, taking up 4 cogs?
Thanks in advance,
Todd
Comments
Like the name says it CAN handle up to 32 servos.
It is in assembler too. As long as code is in ONE spin-file (let*s call it FILE_A.spin all global variables of this SPIN-code-file is accessible. Even ACROSS cogs.
Only global variables that are in another SPIN-file (let's call it FILE_B.spin) are not directly accessible from File_A.spin.
In this case you have to define methods that give back the values of variables as the result
MyMethod1_get_var
and to set variables methods
MyMethod1_Set_var
So it will be enough to start the Servo32v7-object ONCE
and then start two methods for two scan-routines and your main-program summing up in three cogs.
best regards
Stefan
Thanks so much for the response, I'll try it as soon as I get home this evening. I had an equally hard time figuring out how to double dereference a C pointer 30 years ago.
Todd C
Thanks for the reply. I'm mostly doing this to stay out of my comfort zone. I learned everything I know about the SX (even a little interrupt programming) by reading your columns and doing some of the projects.
I almost hated to ask the question because it seems like a huge advantage of the Propeller would be the ability to launch a cog running PWM that can handle 32 channels, thereby taking care of differential motor drive control as well as all servo control and being able to easily use that from any of the other cogs independently. Something that obviously useful seems like it would be very straightforward so it was just a little frustrating not to "just get it."
Thanks again and keep up the good work with The Spin Zone.
Todd C.
I should listen to myself. I just read your January Spin Zone article and I had my "Aha!" moment. Best description of how variable scope/multiple COGs works that I've found. Now I have to wait until I get home to play (I need a demo board for my desk!)
Todd C.