cog-to-cog communication
omgitsaliv55
Posts: 24
I'm planning on building a complex robot with many servos and don't wont to have to use a separate servo controller (for the sake of simplicity), so I figured I would write my own servo controller that would run on another cog, and the main cog would send data to the other cog. but I don't see anything in the propeller manual about "talking" cogs. I know there's an object that demo's this, but I've been kind of busy lately and don't have much time to go through and dissect the code. what I would really like to know is if this is even possible. Ideally, I'd like to just be able to tap into the other cog's ram, but if I have to I guess I could use serial commands.
thanks
-Patrick
thanks
-Patrick
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Stan Dobrowski
There are two completely independent ways of organizing your programs: 1) You can separate your program into objects which have their own private name spaces and the variables in one object cannot be directly accessed by another object. This is used primarily for creating abstractions, usually for device I/O drivers. 2) You can run bits of your program in separate processors (cogs) simultaneously. The smallest "bit" is a procedure or function which is called a "method" in Spin.
If you have two or more cogs running and their code is all in one object, they both have complete access to global variables in the object.
There already exist two objects in the Parallax Object Exchange for controlling servos. One is written partly in Spin and partly in assembly and can control up to 32 servos. The other is written completely in Spin and can control up to 4 servos and has additional provisions for ramping position. In both cases, the part that actually controls the servos executes in its own cog. The other part is the set of interface routines that one actually calls from ones program.
If you only need access to one variable, you can pass the pointer to it in the cognew statement:·cognew(pasm_start, @long_var)
and access it using the PAR reserved variable in PASM:· RDLONG temp2, PAR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (Ken Peterson) : 4/28/2008 1:30:07 PM GMT
I guess the root of my question: What all is restricted from a new cog when its created?
Right now I have a problem where I have code that runs fine when just called from the main obect. But when I cognew on the function to seperate it... nothing happens or the prop locks up like:
PUB insideMain
secondObject.someMethodInObject2()
But when inside the secondobject I do
long stack[noparse][[/noparse]32]
PUB insideSecondObject
okay := cog := cognew(someMethodInObject2,@stack)
PUB someMethodInObject2
nothing runs in here or it freezes up
Post Edited (Dizzy) : 5/6/2008 3:14:43 AM GMT