FIXED: irin resets servo?
November 11, 2010
I've attached an IR receiver to a servo to use as an IR beacon detector. I'm trying to have the servo sweep through its travel to look for an infrared signal using the "irin" command on a 28X2. I want it to start the servo all the way to the right and pause for an IR signal check. If no signal then increment to the left a little bit, look for IR signal, if no signal, blah blah blah...
My (original) code snippet:
let servo_pos = 70
let servo_pos = servo_pos + 5 'increments servopos value
if servo_pos > 225 then goto main 'if servo is full left then stop IR search
servopos 7, servo_pos 'starts servo full left
irin [550,ir_wide_scan], A.1, ir_code 'look for IR signal
if ir_code > 0 then goto lock_on 'start maneuvers to home in on signal
My (post-CtC advice) code:
symbol pos = b1
symbol ir_code = b2
let b3=1:debug:wait 3
for pos = 75 to 255 step 5 'increments servopos value
let b3=2:debug:wait 3
servopos 7, pos 'starts servo full right
let b3=3:debug:wait 3
let ir_code = 0
let b3=4:debug:wait 3
let b3=7:debug:wait 3
let b3=100:debug:wait 3
let b3=5:debug:wait 3
irin [2000,ir_timeout],A.0,ir_code 'look for IR signal
let b3=99:debug:wait 3
if ir_code = 5 then goto lock_on
let b3=6:debug:wait 3
(The following is in regards to the original code. See the comments section for details on the modified code)
So what happens is the servo will go to position 75 and wait for .55 seconds while looking for the IR signal. After that, the servo backs up 75 "clicks" (to center/position 150 the first time through the loop) and then goes back down to 80. Then it waits for IR, it times out, the servo backs up 75 clicks (this time to 145), then goes to 85, and on and on it goes. When it eventually gets incremented to around 150, when it backs up its 75 clicks, it reaches the end of the servo's travel and it makes angry servo sounds as well. Very disconcerting.
If I leave out the irin command everything works as I expect.
Is this just the way it is or am I missing something? This thing is making me feel retarded.