Explaination of COG operation needed
T Chap
Posts: 4,223
It just occurred to me the first time this week that I have been doing something all along that logically doesn't make sense.
The main COG launches other cogs. As an example, the main cog launches a PID object(PIDENGINE.spin) in a new cog. The PID object has a loop that never stops, taking in the new position and constantly trying the fix the error between newpos and the real position from the encoders. But, there are several other methods that get called from the main cog, like for example pid.resetencoder or pid.clearallvalues. These methods are definitely working to reset the encoder and clear the pid values to zero. So how is it that this is happening when the cog is running the main PID loop at all times and there is no method for the main PID loop to depart and go to the other methods mentioned and return, the other methods are simply calls from the main cog? pid.clearallvalues affects the main PID loop, so on the surface, it looks like the main PID loop never even stops to allow the other things to happen. The only conclusion is that these other methods are NOT really occurring in the PID cog, but are occurring in the main cog.
Post Edited (Todd Chapman) : 6/22/2010 6:10:02 PM GMT
The main COG launches other cogs. As an example, the main cog launches a PID object(PIDENGINE.spin) in a new cog. The PID object has a loop that never stops, taking in the new position and constantly trying the fix the error between newpos and the real position from the encoders. But, there are several other methods that get called from the main cog, like for example pid.resetencoder or pid.clearallvalues. These methods are definitely working to reset the encoder and clear the pid values to zero. So how is it that this is happening when the cog is running the main PID loop at all times and there is no method for the main PID loop to depart and go to the other methods mentioned and return, the other methods are simply calls from the main cog? pid.clearallvalues affects the main PID loop, so on the surface, it looks like the main PID loop never even stops to allow the other things to happen. The only conclusion is that these other methods are NOT really occurring in the PID cog, but are occurring in the main cog.
Post Edited (Todd Chapman) : 6/22/2010 6:10:02 PM GMT
Comments
[noparse][[/noparse]COG0]: routinex setting value y to 1
[noparse][[/noparse]COG1]: clearing value y
...
If you call other functions from your main COG, then these functions are really running in the main COG.
It makes no difference if we talk about functions in the same *.spin-file or in an object.
Both things (the looping COG and the function call in the main COG) happen independent from each other. So, depending on the problem you wanna solve with the program, there might be a need to synchronize. For example if you reset the PID you better might want to wait with setting the input values of the loop until a calculation is done. Because otherwise it can happen that old and new values are mixed as a cause of this independency. This can lead to wrong results.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum