Function Confusion
ajward
Posts: 1,130
Hi All...
I know there's probably a simple answer, but I'll be darned if I can find it!
After getting my tracked vehicle running with the Stingray demo code, I've started using Kye's "PWM2C_HBDEngine" from the OBEX for more control. My code (See below) has functions to ramp up, ramp down and run forward and pivot turn to the right. Running the first three functions on the MSR1 board, Ted ramps up, runs forward for a bit, ramps down and stops. However, when I add the fourth function "pivot_rt", he ramps up runs forward, ramps down, but the vehicle never stops pivoting. What am I missing here?
Any wisdom appreciated!!!
Amanda
PS- Happy Monday!
I know there's probably a simple answer, but I'll be darned if I can find it!
After getting my tracked vehicle running with the Stingray demo code, I've started using Kye's "PWM2C_HBDEngine" from the OBEX for more control. My code (See below) has functions to ramp up, ramp down and run forward and pivot turn to the right. Running the first three functions on the MSR1 board, Ted ramps up, runs forward for a bit, ramps down and stops. However, when I add the fourth function "pivot_rt", he ramps up runs forward, ramps down, but the vehicle never stops pivoting. What am I missing here?
Any wisdom appreciated!!!
Amanda
PS- Happy Monday!
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 _leftFW = 25 _leftBW = 24 _rightFW = 26 _rightBW = 27 _timeStepInMilliseconds = 20 _updateFrequencyInHertz = 8_000 OBJ hbd: "PWM2C_HBDEngine.spin" Pub Main ramp_up waiTcnt(clkfreq + cnt) run_fwd waitcnt(clkfreq + cnt) ramp_dn waitcnt(clkfreq + cnt) pivot_rt waitcnt(clkfreq + cnt) PUB ramp_up | timeCounter, frequencyCounter ifnot(hbd.HBDEngineStart(_leftFW, _leftBW, _rightFW, _rightBW, _updateFrequencyInHertz)) reboot timeCounter := ((clkfreq / 1_000) * _timeStepInMilliseconds) repeat frequencyCounter from 0 to 1000 step 50 hbd.leftDuty(frequencyCounter) hbd.rightDuty(frequencyCounter) waitcnt(timeCounter + cnt) return PUB run_fwd | timeCounter, frequencyCounter ifnot(hbd.HBDEngineStart(_leftFW, _leftBW, _rightFW, _rightBW, _updateFrequencyInHertz)) reboot timeCounter := ((clkfreq / 1_000) * _timeStepInMilliseconds) repeat 2 frequencyCounter := 1000 hbd.leftDuty(frequencyCounter) hbd.rightDuty(frequencyCounter) waitcnt(timeCounter + cnt) return PUB ramp_dn | timeCounter, frequencyCounter ifnot(hbd.HBDEngineStart(_leftFW, _leftBW, _rightFW, _rightBW, _updateFrequencyInHertz)) reboot timeCounter := ((clkfreq / 1_000) * _timeStepInMilliseconds) repeat frequencyCounter from 1000 to 0 step 50 hbd.leftDuty(frequencyCounter) hbd.rightDuty(frequencyCounter) waitcnt(timeCounter + cnt) return PUB pivot_rt | timeCounter, frequencyCounter ifnot(hbd.HBDEngineStart(_leftFW, _leftBW, _rightFW, _rightBW, _updateFrequencyInHertz)) reboot timeCounter := ((clkfreq / 1_000) * _timeStepInMilliseconds) repeat 2 frequencyCounter := 1000 hbd.leftDuty(frequencyCounter) hbd.rightDuty(-frequencyCounter) waitcnt(timeCounter + cnt) return
Comments
I suspect you aren't allowed a negative rightDuty value?
need to write return in each one unless there is a variable you would like to return.
Thanks for your reply Mark!
Yeah... I guess that has to be it. I've used that obex module before and I could swear I've sent negative values to the function before. Of course, I can't find my previous code to verify. <grumble>
Anyhow... thanks again!!!!
Amanda
Amanda
I'm pretty sure you're right about negative values being valid. I think negative values put the motor in reverse.
It would be easier if you attached the code as an archive and then we could also see the child object.
Edit: Duane is right you have to put a negative # to go one way and a positive # to go the other with 0 being stop.