Ping sensor in New Cog
Botdocter
Posts: 271
My bot uses scripts that make my ping sensor pause for the duration of those functions. So i want to run the ping in a new cog. It runs for about 15 secons then gets stuck. The robot is all over the place (going left right backwards and god know where else!) for the same 15 seconds and then the program gets stuck.
what did i do wrong?
This is what i tried:
[noparse][[/noparse]code]cognew(PingCog(@distance), @PingStack)[noparse][[/noparse]/code]
and then...
[noparse][[/noparse]code]PUB PingCog(distance)
'Get Ping))) reading at all times.
······· repeat····
········· distance := ping.Centimeters(PING_Pin)············································ 'Get Range In Millimeters
········ long[noparse][[/noparse]distance] *= long[noparse][[/noparse]range]································ ' Ping value, store back
········ waitcnt(clkfreq + cnt)[noparse][[/noparse]/code]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
what did i do wrong?
This is what i tried:
[noparse][[/noparse]code]cognew(PingCog(@distance), @PingStack)[noparse][[/noparse]/code]
and then...
[noparse][[/noparse]code]PUB PingCog(distance)
'Get Ping))) reading at all times.
······· repeat····
········· distance := ping.Centimeters(PING_Pin)············································ 'Get Range In Millimeters
········ long[noparse][[/noparse]distance] *= long[noparse][[/noparse]range]································ ' Ping value, store back
········ waitcnt(clkfreq + cnt)[noparse][[/noparse]/code]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
Comments
Do you really intend to overwrite the address of your distance variable with the range? And where/how is range (another address) defined?
example: IF range < 30
Turnleft
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
will that solve my problem or is this another problem i have?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
repeat
range := ping.Centimeters(PING_Pin) 'Get Range In Centimeters
So what do i need to wrap around this code to make it run in a new cog and what value's do i need to use for calling the new cog in the main script?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
Post Edited (kuroneko) : 5/4/2010 2:40:12 AM GMT
I use a ring buffer so that if I ignore the measurements for a long time I just discard the old ones and I do not run out of memory.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Robots
That is great since that's just what i whas looking for.
But still my question raises..
Can you give me an example of how to run this in a sepparate cog?
I use the ping sensor for more tasks then one. So i want it to ping constantly ( every second or 0.5 second) and then the sensor values will be available even when the main script would stop reading because of other functions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!
And is that per cog or for all cogs together?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 Parallax Propeller Robot Control Board
1 Memsic MX2125 accelerometer/ tilt
1 Parallax Ping))) ultrasonic sensor
a few motors and a whole lot of chaos!