Cognew issues
Litefire
Posts: 108
hey, i'm having trouble launching cogs. for example, when i do this:
the chip locks up and the motors never start but this:
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
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
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.
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