Can't pass global variable after cognew command
lardom
Posts: 1,659
My challenge is to control two steppers with IR distance detection. I designed it so that the top object initializes three cogs, one for each of the two steppers and an IR control. The idea is that the main method in the IR control (which includes two extra methods for global variables 'A' and 'B') copies the value from from the IR detector and passes it to the two global variables, 'A' and 'B'.
The left stepper then calls method 'A' and the right stepper calls method 'B' to get the corresponding value/s. The problem is that once I issue a cognew command to the IR control object I can no longer get those global values. I'm debugging with the PST using 'copy' and 'paste'. I'm stumped.
The left stepper then calls method 'A' and the right stepper calls method 'B' to get the corresponding value/s. The problem is that once I issue a cognew command to the IR control object I can no longer get those global values. I'm debugging with the PST using 'copy' and 'paste'. I'm stumped.
{ works with cognew command to pst }
CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x
OBJ
ir : "IrDetectorV6"
pst : "Parallax Serial Terminal"
VAR
byte cogT
long indexA, indexB, A_Side, B_Side, stack[20]
{PUB Start : success
Stop
success := cogT := cognew(Main_Sensor, @stack) + 1
PUB Stop
If cogT
cogstop(cogT~ - 1) }
PUB Main_Sensor | dist ' : result
pst.StartRxTx(31, 30, 0, 115_200)
ir.init(26, 27, 25)
repeat
dist := ir.distance
A_Side := B_Side := dist
' waitcnt(clkfreq/100 + cnt)
pst.Str(string(pst#PX, 11))
pst.Dec(dist)
' waitcnt(clkfreq/3 + cnt)
' Foward_a
PUB Foward_a : result 'left wheel
result := A_Side
pst.Str(string(pst#PX, 11))
' dist := ir.Distance
pst.Dec(result)
' pst.Str(string("/100", pst#CE))
waitcnt(clkfreq/3 + cnt)
PUB Foward_b : result 'right wheel
result := B_Side

Comments