Shop OBEX P1 Docs P2 Docs Learn Events
Cognew issues — Parallax Forums

Cognew issues

LitefireLitefire Posts: 108
edited 2007-03-25 02:25 in Propeller 1
hey, i'm having trouble launching cogs. for example, when i do this:

OBJ

  motor[noparse][[/noparse] 2] : "SetMotor"
  bs2      : "BS2_Functions"
  encoder  : "Encoder"
  
VAR

  ' Motor 1 
  BYTE  speed[noparse][[/noparse] 4]
  LONG  encoderstack, stack[noparse][[/noparse] 20]

pub encodertest        
  bs2.start(31,30)
  motor[noparse][[/noparse] right].init(_esc1PwmPin, _esc1DirPin, _esc1Freq, 0)   ' initialize SetMotor.spin 0
  motor[noparse][[/noparse] left].init(_esc2PwmPin, _esc2DirPin, _esc2Freq, 1)    ' initialize SetMotor.spin 1       
  cognew(encoder.start(0,2,0,@encoderstack), @stack)
  motor[noparse][[/noparse] right].setmotor(50, 1, 1)                             ' slowest speeds that motors can start at (lower speeds can be 
  motor[noparse][[/noparse] left].setmotor(50, 1, 1)                              ' achieved by lowering speed once moving)
  repeat 
    bs2.debug_str(string(cr, cr, "Right: "))                  
    bs2.debug_dec(encoderstack)
    'bs2.debug_char(13)
    bs2.debug_str(string(cr, cr, "_____________"))
    waitcnt (cnt + 80_000_000)




the chip locks up and the motors never start but this:

OBJ

  motor[noparse][[/noparse] 2] : "SetMotor"
  bs2      : "BS2_Functions"
  encoder  : "Encoder"
  
VAR

  ' Motor 1 
  BYTE  speed[noparse][[/noparse] 4]
  LONG  encoderstack, stack[noparse][[/noparse] 20]

pub encodertest        
  bs2.start(31,30)
  motor[noparse][[/noparse] right].init(_esc1PwmPin, _esc1DirPin, _esc1Freq, 0)   ' initialize SetMotor.spin 0
  motor[noparse][[/noparse] left].init(_esc2PwmPin, _esc2DirPin, _esc2Freq, 1)    ' initialize SetMotor.spin 1       
  'cognew(encoder.start(0,2,0,@encoderstack), @stack)
  motor[noparse][[/noparse] right].setmotor(50, 1, 1)                             ' slowest speeds that motors can start at (lower speeds can be 
  motor[noparse][[/noparse] left].setmotor(50, 1, 1)                              ' achieved by lowering speed once moving)
  repeat 
    bs2.debug_str(string(cr, cr, "Right: "))                  
    bs2.debug_dec(encoderstack)
    'bs2.debug_char(13)
    bs2.debug_str(string(cr, cr, "_____________"))
    waitcnt (cnt + 80_000_000)




makes it work smooth as butter. i shouldn't be running out of cogs, i've run through my code and i should have at least two left... i can post all of my objects if you'd like.

~~Brian

Comments

  • Jeff MartinJeff Martin Posts: 755
    edited 2007-03-25 02:23
    Litefire said...

    OBJ

    ··motor[noparse][[/noparse]·2]·:·"SetMotor"
    ··bs2······:·"BS2_Functions"
    ··encoder··:·"Encoder"

    VAR

    ··'·Motor·1
    ··BYTE··speed[noparse][[/noparse]·4]
    ··LONG··encoderstack,·stack[noparse][[/noparse]·20]

    pub·encodertest
    ··bs2.start(31,30)
    ··motor[noparse][[/noparse]·right].init(_esc1PwmPin,·_esc1DirPin,·_esc1Freq,·0)···'·initialize·SetMotor.spin·0
    ··motor[noparse][[/noparse]·left].init(_esc2PwmPin,·_esc2DirPin,·_esc2Freq,·1)····'·initialize·SetMotor.spin·1
    ··cognew(encoder.start(0,2,0,@encoderstack),·@stack)

    On the Propeller, launching another object's method into a new cog is highly "not recommended" and, in fact, not supported.· What happens when you perform the cognew that you wrote, is the first cog calls the encoder object's .start method, and waits for a return, then the retured value from .start is used as the address of code to launch into another cog... this usually results in strange behavior or no additional behavior at all.

    For cognew to work as you intend, you need to launch code that is only within the object that you are executing the cognew instruction from.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Jeff Martin

    · Sr. Software Engineer
    · Parallax, Inc.
  • LitefireLitefire Posts: 108
    edited 2007-03-25 02:25
    thanks muchly. i'll try that.

    EDIT: Worked like a charm. They should have the compiler flag that as an error, if that's possible... oh well. thanks!

    ~~Brian

    Post Edited (Litefire) : 3/25/2007 2:36:59 AM GMT
Sign In or Register to comment.