Odd exit from
souplogic
Posts: 8
I am having a problem in the runCog method below where under certain circumstances (they seem electrical, like if I try to force the servo head to turn), the loop is exited, possibly the cog shut down, but everything else (including the servo code) continues to operate.
This is not a reset, as all other functionality (i.e. the servo stays fixed) continues, but the ping stops working, as well as my debug output (using a simple seven segment driver which was only added _after_ the problem started).
Are there any glaring mistakes I have made here? I tried to follow the examples in the book to create an object with runnable routines.
Thanks for your help
-Adam
Post Edited (souplogic) : 5/3/2008 8:01:56 PM GMT
This is not a reset, as all other functionality (i.e. the servo stays fixed) continues, but the ping stops working, as well as my debug output (using a simple seven segment driver which was only added _after_ the problem started).
Are there any glaring mistakes I have made here? I tried to follow the examples in the book to create an object with runnable routines.
Thanks for your help
-Adam
CON PIN_HEAD_PING = 13 PIN_HEAD_SERVO = 08 LOOK_RGT = 1000 LOOK_FWD = 1900 OBJ ping: "Ping" servo: "Servo32v3" ss: "AT_SevenSeg" VAR long stack[noparse][[/noparse]20] 'Stack space for new cog byte cog 'Hold ID of cog in use, if any long headPos 'current position of head in pulse width long headPing 'last head ping distance in cm PUB init headPos := LOOK_FWD servo.set(PIN_HEAD_SERVO,headPos) 'Note: Servo pins that will be used must be preset before running "SERVO.Start". ' This is because the I/O direction is set here and is only executed ' at the beginning of "SERVO.Start". Servo pins that aren't used will remain ' in their original direction state. servo.start start PUB start: success {{Start runcog process in new cog; return True if successful.}} stop success := (cog := cognew(runCog, @stack) + 1)'plus 1 to adjust indexing PUB stop {{Stop toggling process, if any.}} if cog cogstop(cog~ - 1) 'clear Cog var after using as param for cogstop PUB active: yesNo {{Return TRUE if process is active, FALSE otherwise.}} yesNo := cog > 0 PUB runCog | headSample, i repeat headPing := ping.centimeters(PIN_HEAD_PING) i := servo.set(PIN_HEAD_SERVO,headPos) waitcnt (clkfreq/4+cnt) ss.pointToggle cog~ 'Exit: Clear Cog ID variable before execution falls through PUB lookRgt headPos := LOOK_RGT servo.set(PIN_HEAD_SERVO,headPos) PUB lookFwd headPos := LOOK_FWD servo.set(PIN_HEAD_SERVO,headPos) PUB getHeadPing : result result := headPing
Post Edited (souplogic) : 5/3/2008 8:01:56 PM GMT
Comments
I can't see anything wrong but I would make the stack bigger. Something like 40. Also, how is everything wired up? Is everything hooked up to the right pins? How do you know that the ping isn't working?
Im fairly certain the connections are all right, and furthermore the issue seems to battery related, as when things are all plugged in the problem does not happen as often, or possibly not at all. That said, even a fresh lantern battery (used because it was 6 volts, and a good bit of current and staying power) seemed to cause the problem.
It could well be an issue with the ping or servo electronics as they are not new, but I would like to know if anyone sees anything in the code thats a red flag.
Thanks a lot.
Adam