Simple issues with passing variables.
Litefire
Posts: 108
i'm having trouble getting another cog to update a variable in the main program. A array of byte sized variables is created in the top object, whose pointer is passed to the sensor object. i was thinking that this would continuously update the variable in the main object. but all that i am getting in the top object is zeroes.
here's my top object code:
and here's my sensor object code:
but when i do this in the sensor object and run it stand-alone it gives me legible (while inverted... :-\) data:
i'm not sure what i'm doing wrong, hope it's something small and someone'll point it out right away.
Thanks!
~~Brian
Post Edited (Litefire) : 4/1/2007 3:09:40 AM GMT
here's my top object code:
OBJ motor : "SetMotor" bs2 : "BS2_Functions" 'remove when we're done sensor : "Sensors" encoder : "Encoder" free : "Free_cogs" VAR BYTE sensorvar[noparse][[/noparse] 8] word leftcase[noparse][[/noparse] 16], rightcase[noparse][[/noparse] 16] LONG encoderstack[noparse][[/noparse] 4] pub turnsetup | enc_old, delta, _freecogs, i, distance, index, x ' runs stand-alone bs2.start(31,30) sensor.init(@sensorvar) bs2.debug_str(string("Starting", cr)) repeat bs2.debug_str(string(cr,"Range Left: ")) bs2.debug_dec(sensorvar[noparse][[/noparse] _Range_Left]) bs2.debug_str(string(cr, "Range Front: ")) bs2.debug_dec(sensorvar[noparse][[/noparse] _Range_Front]) bs2.debug_str(string(cr, "Range Right: ")) bs2.debug_dec(sensorvar[noparse][[/noparse] _Range_Right]) bs2.debug_str(string(cr, "Bump Left: ")) bs2.debug_dec(sensorvar[noparse][[/noparse] _Bump_Left]) bs2.debug_str(string(cr, "Bump Right: ")) bs2.debug_dec(sensorvar[noparse][[/noparse] _Bump_Right]) bs2.debug_str(string(cr, "____________", cr, cr)) waitcnt(cnt + 80_000_000)
and here's my sensor object code:
var long sensor, Stack[noparse][[/noparse] 25] pub init(_array) dira[noparse][[/noparse] 7..14]~ sensor := _array cognew(sense, @stack) repeat pub sense repeat long[noparse][[/noparse] @sensor][noparse][[/noparse] _Range_Left] := INA[noparse][[/noparse] RF_Left] long[noparse][[/noparse] @sensor][noparse][[/noparse] _Range_Front] := INA[noparse][[/noparse] RF_Front] long[noparse][[/noparse] @sensor][noparse][[/noparse] _Range_Right] := INA[noparse][[/noparse] RF_Right] long[noparse][[/noparse] @sensor][noparse][[/noparse] _Range_compare] := INA[noparse][[/noparse] RF_Compare] long[noparse][[/noparse] @sensor][noparse][[/noparse] _Bump_Left] := INA[noparse][[/noparse] Bump_Left] long[noparse][[/noparse] @sensor][noparse][[/noparse] _Bump_Right] := INA[noparse][[/noparse] Bump_Right] long[noparse][[/noparse] @sensor][noparse][[/noparse] _UVtron] := INA[noparse][[/noparse] UVtron]
but when i do this in the sensor object and run it stand-alone it gives me legible (while inverted... :-\) data:
obj bs2 : "Bs2_functions" var long sensor, Stack[noparse][[/noparse]25] byte sensorvar[noparse][[/noparse]8] pub start bs2.start(31,30) cognew(sense, @stack) repeat bs2.debug_str(string(cr,"Range Left: ")) bs2.debug_dec(sensorvar[noparse][[/noparse]_Range_Left]) bs2.debug_str(string(cr, "Range Front: ")) bs2.debug_dec(sensorvar[noparse][[/noparse]_Range_Front]) bs2.debug_str(string(cr, "Range Right: ")) bs2.debug_dec(sensorvar[noparse][[/noparse]_Range_Right]) bs2.debug_str(string(cr, "Bump Left: ")) bs2.debug_dec(sensorvar[noparse][[/noparse]_Bump_Left]) bs2.debug_str(string(cr, "Bump Right: ")) bs2.debug_dec(sensorvar[noparse][[/noparse]_Bump_Right]) bs2.debug_str(string(cr, "____________", cr, cr)) waitcnt(cnt + 80_000_000) pub init(_array) dira[noparse][[/noparse]7..14]~ sensor := _array cognew(sense, @stack) repeat pub sense repeat sensorvar[noparse][[/noparse]_Range_Left] := INA[noparse][[/noparse]RF_Left] sensorvar[noparse][[/noparse]_Range_Front] := INA[noparse][[/noparse]RF_Front] sensorvar[noparse][[/noparse]_Range_Right] := INA[noparse][[/noparse]RF_Right] sensorvar[noparse][[/noparse]_Range_compare] := INA[noparse][[/noparse]RF_Compare] sensorvar[noparse][[/noparse]_Bump_Left] := INA[noparse][[/noparse]Bump_Left] sensorvar[noparse][[/noparse]_Bump_Right] := INA[noparse][[/noparse]Bump_Right] sensorvar[noparse][[/noparse]_UVtron] := INA[noparse][[/noparse]UVtron]
i'm not sure what i'm doing wrong, hope it's something small and someone'll point it out right away.
Thanks!
~~Brian
Post Edited (Litefire) : 4/1/2007 3:09:40 AM GMT
Comments
also when i removed the pointer symbol (@) from [noparse][[/noparse] @sensor] i was able to receive the value of [noparse][[/noparse] _range_left] but nothing else.
EDIT: all fixed. since i declared sensorvar[noparse][[/noparse] 8] as an array of BYTES, when i wrote to LONG[noparse][[/noparse]sensor][noparse][[/noparse]_range_left] it was overwriting everything.