Stopping a cog that started in another object
xanadu
Posts: 3,347
"It is possible for any cog to start and stop any other cog, but in practice it is not done outside of the logical object except in extreme cases." -http://www.parallax.com/portals/0/help/P8X32A/QnaMobile/Advanced/Content/QnaTopics/QnaCogs.htm
Can anyone tell me how that is done, if I were to have an extreme case? If I had a bunch of objects and they're all launching cogs and I don't understand the objects enough to modify them to include stopping is there really a way to shut them all down from the top object?
This is in regard to Servo32v6 and its Servo32_Ramp_v1 object.
Below is my altitude hold, using an XBee to switch between regular TX controls and altitude hold mode. I can get either one to work, but toggling between the two is glitchy, and I know it is because I'm not stopping the right cogs.
Thanks.
Can anyone tell me how that is done, if I were to have an extreme case? If I had a bunch of objects and they're all launching cogs and I don't understand the objects enough to modify them to include stopping is there really a way to shut them all down from the top object?
This is in regard to Servo32v6 and its Servo32_Ramp_v1 object.
Below is my altitude hold, using an XBee to switch between regular TX controls and altitude hold mode. I can get either one to work, but toggling between the two is glitchy, and I know it is because I'm not stopping the right cogs.
'' Altitude Hold V0.8 Main OBJ RX : "RX" servo : "Servo32v6" alt : "29124_altimeter" xbee : "xbee_object_2" var long start_alt long elevservo[20] long balt, getalti[20] long pulsewidth[60] long txstack[30] long servostack[30] long altstack[30] CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 servoPin = 7 ' Servo signal to this I/O pin-change if needed XBR = 15 ' XBee Dout XBT = 14 ' XBee Din PUB Main | c xbee.start(XBR, XBT, %0000, 9_600) ' start XBee coms 9600 baud waitcnt(clkfreq * 1 + cnt) xbee.at_init xbee.cr ' initialize xbee xbee.str(string("Roboglider Modem Online")) ' indicate sys reboot xbee.cr xbee.rxflush ' clear trash from xbee repeat c := xbee.rxtime(250) case c "h", "H": xbee.str(string(" ALT HOLD MODE")) xbee.cr coginit(3,getalt,@altstack) coginit(6,servoc,@servostack) "n", "N": xbee.str(string(" TX MODE")) xbee.cr coginit(5,txmode, @txstack) PUB getalt | a start_alt := 10 ' Setup up altitude to match servo center * gain alt.start(alt#QUICKSTART, alt#BACKGROUND) ' Start altimeter for QuickStart with background processing. alt.set_resolution(alt#HIGHEST) ' Set to highest resolution. alt.set_altitude(alt.m_from_ft(START_ALT * 100)) ' Set the starting altitude, based on average local pressure. repeat a := alt.altitude(alt.average_press) ' Get altitude data balt := a * 5 ' Copy to VAR w/ gain PUB Servoc | tInc, tc, tHa, t ctra[30..26] := %00100 ' Configure Counter A to NCO ctra[8..0] := servoPin frqa := 1 dira[servoPin]~~ ' Set up cycle and high times tInc := clkfreq/1_000_000 tC := tInc * 21_500 tHa := tInc * 1500 t := cnt ' Mark counter time repeat ' Repeat PWM signal tHa := tInc * balt ' Sync servo position/altimeter phsa := -tHa ' Set up the pulse + Gain t += tC ' Calculate next cycle repeat waitcnt(t) ' Wait for next cycle PUB txmode servo.start Rxinput PUB RXinput | i, pulse[6] RX.start(@pins,@pulseWidth) waitcnt(clkfreq/2 + cnt) repeat repeat i from 0 to 5 pulse[i] := pulsewidth[i] ' capture pulse values from pins 1 out(i + 7, pulse[i]) ' send servo pulses to pins 7 PUB out(_pin, _pulse) servo.set(_pin, _pulse) DAT pins LONG 1 {{ +------------------------------------------------------------------------------------------------------------------------------+ ¦ TERMS OF USE: MIT License ¦ +------------------------------------------------------------------------------------------------------------------------------¦ ¦Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation ¦ ¦files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, ¦ ¦modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software¦ ¦is furnished to do so, subject to the following conditions: ¦ ¦ ¦ ¦The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.¦ ¦ ¦ ¦THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ¦ ¦WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ¦ ¦COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ¦ ¦ARISING FROM, OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ¦ +------------------------------------------------------------------------------------------------------------------------------+ }}
Thanks.
Comments
-Phil
I guess I need to brush up on manipulating cog ID's. I went through this all I think around a year ago and seem to have completely forgot. The example in the PE book (page 79) is easy to understand when launching identical cogs from the same line of code.
Another question I have is both RX and ALT objects have stop methods, if I call them from my top object that should shut them both down properly, and any cogs they launched as well correct?
I also decided to stop trying to stop the objects cogs, let them run and just switch between them by changing the repeat loop that copies the variable from either TX mode or ALT hold to the servo. Then all I need to do is reset the altitude VAR to select a new cruise altitude. I'm not sure why my initial approach was to turn everything on and off, but then again I hadn't realised at the time each object needs x amount of time to get up and running properly.