Shop OBEX P1 Docs P2 Docs Learn Events
Help Starting Cog — Parallax Forums

Help Starting Cog

numminummi Posts: 4
edited 2011-01-03 14:42 in Propeller 1
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

  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-02 22:06
    It sounds like you've started a cog running Fusion and the cog number is #4 (cog == 5).

    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
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-01-02 22:17
    I'm curious about something: the program gets rolling with PRI and not a PUB Main, so won't it go into the first repeat loop it encounters and stay there forever? I didn't think SPIN would skip over the PRI tag and go to the first PUB, will it?
  • kuronekokuroneko Posts: 3,623
    edited 2011-01-02 22:22
    @ElectricAye: The first PUB method is executed regardless of location.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-01-02 22:25
    kuroneko wrote: »
    @ElectricAye: The first PUB method is executed regardless of location.

    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-03 04:55
        Long[pitch] := GetPitch(Long[accY1], Long[gyroZ1])
        Long[roll] :=  GetPitch(Long[accX1], Long[gyroY1])
        Long[bearing] += Long[gyroX1]
    

    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.
  • numminummi Posts: 4
    edited 2011-01-03 14:42
    Thanks all who replied. @MaglO2 Your right, i should append the 1. But they do need to be passed by reference because of a different snippet of code that i did not include that communicates between the cogs.

    @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

Sign In or Register to comment.