Help Starting Cog
nummi
Posts: 4
I have this code that is supposed to start a cog and run a loop. Alll of the functions called exists. The calls are identical to another cog i have set up that works fine. The start functions returns 5. I am baffled, but i am sure it is something simple. Thanks all
VAR long accX, accY, accZ, gyroX, gyroY, gyroZ, pitch, roll, bearing long stack[200] long cog, updated Pri Fusion(gyroX1, gyroY1, gyroZ1, accX1, accY1, accZ1, updated1, pitch1, roll1, bearing1) | b ' these are all pointers and must be addressed as such b := true long[updated1] := 25 repeat Long[pitch] := GetPitch(Long[accY1], Long[gyroZ1]) Long[roll] := GetPitch(Long[accX1], Long[gyroY1]) Long[bearing] += Long[gyroX1] b := !b if b outa[5] := %1 else outa[5] := %0 PUB Start : ok Stop updated := 1 mathlib.Start updated := 20 ok:= cog := cognew(Fusion(@gyroX, @gyroY, @gyroZ, @accX, @accY, @accZ, @updated, @pitch, @roll, @bearing), @stack) + 1 PUB Stop if(cog) cogstop(cog - 1)
Comments
If you're watching I/O pin #5, what's happening is that each cog has its own set of I/O registers and I don't see anywhere in Fusion where you've set DIRA[ 5 ] := 1
Thanks, I didn't know that. I'm so used to seeing everything start with PUB, and the Propeller Manual says that the PRI declaration is treated exactly like the PUB except for when it's accessed from outside the Object.
is wrong
You should use pitch1, roll1 and bearing1 as these contain the addresses of the variables.
If this is only a snippet of the real code then it's fine, otherwise I don't understand why to pass the addresses at all, as the function Fusion has direct access to all the variables.
pitch := GetPitch( accY, gyroZ )
would also work.
@Mike Green: Thanks for that piece of information. I did not know that.
It was a combination of misnaming variables and not knowing each cog has its own i/o registers that made it look like it was not running.
Thanks all
Julian