Servo Controller Searchlight
revised 04-13-11
Video of the searchlight scanning back & forth. Note that the angle of the searchlight changes at the end of each sweep.
<right click the box below and select Play for video>
|
The video shows the searchlight below. It
uses a bright 5mm LED with a reflector inside of a copper plumbing cap. The servo that can be seen on the vertical arm is a micro unit that adjust tilt. The controller board is to the left. Batteries for testing are below it.
Here the wires from the LED come through the copper cap. You can also see the control arm on the micro servo and the rod that connects the copper cap and the servo.
This view shows the larger servo that controls the rotation of the searchlight. It is attached below the black base.
This close-up shows how the servo is attached to the searchlight support rod.
|
' v 1.0 of random searchlight revision based on
2.9 '4-20-2011 ' v 2.9 working with new board 4-15-2011 ' d bodnar - 4-14-11 -most features working in version 2.7! '2016 / 2048 v2.8 DEFINE DEBUG_REG PORTA DEFINE DEBUG_BIT 0 ' PIN 13 on 16f684 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 1 ' Set debug mode: 0 = true, 1 = inverted Define PULSIN_MAX 1000 CMCON0 = 255 'set to 255 to get pins 8, 9, 10 to work as inputs- probably some other value is better ' Analog comparators on ANSEL = 0 ' Analog select set to digital, pg 69 data IRIn var porta.2 'pin 11 LED var porta.1 'pin 12 Trigger var porta.3 'pin 4 Servo1Pin var porta.4 'pin 3 Servo2Pin var porta.5 'pin 2 Revo3 var portc.0 'pin 10 Revo2 var portc.1 'pin 9 Revo1 var portc.2 'pin 8 Revo4 var portc.3 'pin 7 Revo5 var portc.4 'pin 6 Revo6 var portc.5 'pin 5 Temp var word Temp0 var word Servo1Temp var word Servo2Temp var word Temp2 var word Temp3 var word Temp4 var word TempByte var byte Count1 var byte 'notes if button held down Count3 var byte 'see above Count4 var byte Count6 var byte CWMin1 var word CCWMax1 var word Middle1 var word IRpulse_length var word(13) xx var Byte Command Var Byte RepeatCnt1 var byte repeatcnt1 = 30 'input as 0-->9 - just multiply by 10 RepeatCnt2 var byte repeatcnt2 = 30 'input as 0-->9 - just multiply by 10 Delay con 10 CCWMax1 = 2000 CWMin1 = 55 CWMin2 var word CCWMax2 var word CCWMax2 = 1400 ' CWMin2 = 400 ' Middle2 var word Middle1= (ccwmax1-cwmin1)/2 + cwmin1 Middle2= (ccwmax2-cwmin2)/2 + cwmin2 IRFlag var bit '=1 if IR hit on initialization ServoNumber var bit Servo1Behavior var bit '=0 if normal, =1 if immediate Servo2Behavior var bit '=0 if normal, =1 if immediate RemoteNum var byte 'temp for getting digit input DigitType var byte '1 =speed, 2=pause, 3=ADRate Digit var byte Value var byte FlashValue var byte VER_Whole var byte 'version whole number VER_Decimal var byte 'version decimal one con 128 two con 129 three con 130 four con 131 five con 132 six con 133 seven con 134 eight con 135 nine con 136 zero con 137 channelUP con 144 channelDOWN con 145 volumeUP con 146 volumeDOWN con 147 OK con 148 Mute con 148 Menu con 224 ENTER con 139 Retrn con 187 Power con 149 ver_whole =1 ver_decimal =0 trisc = %11111111 trisa = %11001100 data @0,0,55,7,208,0,55,7,208, 4,0,4,0,0,0,25,25 'cwmin1,cwmin1,ccwmax1,ccwmax1,cwmin2,cwmin2,ccwmax2,ccwmax2,middle1,middle2, servo1behavior,servo2behavior,repeatcnt1,repeatcnt2 gosub ReadVbbls CCWMax2 = 1400 ' CWMin2 = 400 ' Restart: 'debug "C ",bin portc,10,13:goto restart count1=0 Count3=0 low led 'DEBUG 13,10,13,10,"Revolution Servo Controller"',13,10,"TrainElectronics.com",13,10 'DEBUG " (C) 2011 - d. bodnar" DEBUG 13,10,13,10,"V ",dec ver_whole,".",dec ver_decimal,13,10,13,10 DEBUG 10,13,"Random Searchlight",10,13 gosub ShowVersion if irflag=1 then for temp=1 to 10:toggle led:pause 80:next temp low led goto Config: endif TiltStep con 400 PanStep con 4 TOP: debug "@ top",10,13 servonumber = 0 'Servo 1 is side to side for temp= cwmin1 to ccwmax1 step panstep gosub moveservos next temp servonumber = 1 'Servo2 is up / down temp3=temp3+tiltstep if temp3> ccwmax2 then temp3=cwmin2 endif debug "temp3=",#temp3,10,13 'for temp3=cwmin2 to ccwmax2 step 10 pause 500 for temp0= 1 to 10:gosub moveservos:next temp0 pause 500 'next temp3 servonumber = 0 for temp= ccwmax1 to cwmin1 step -panstep gosub moveservos next temp servonumber = 1 'Servo2 is up / down temp3=temp3+tiltstep if temp3> ccwmax2 then temp3=cwmin2 endif debug "temp3=",#temp3,10,13 'servonumber = 1 'for temp3= ccwmax2 to cwmin2 step -10 Pause 500 for temp0= 1 to 10:gosub moveservos:next temp0 pause 500 'next temp3 goto top MoveServos: if servonumber=0 then debug "Pos1= ",#temp,10,13 servo1pin = 1 ' Start servo pulse Pauseus 300 + temp servo1pin = 0 ' End servo pulse Pause 16 ' Servo update rate about 60Hz else debug "Pos2= ",#temp3,10,13 servo2pin = 1 ' Start servo pulse Pauseus 300 + temp3 servo2pin = 0 ' End servo pulse Pause 16 ' Servo update rate about 60Hz endif return Config: gosub GetIR: if command=0 then config if command < one or command > zero then restart: command=command-127 branch command,[nothing,button1, button2, button3, button4, button5, button6, behavior1, behavior2, time1,time2 ] Nothing:goto config goto config: GetButtonInfo: 'IN: Temp0, ServoNumber (0=1 or 1=2) 'OUT: Temp0 Button1_0: gosub GetIR:if command=0 then button1_0: if command=VolumeDown then if servonumber=0 then if temp0> 40 then temp0=temp0-10 else if temp3 > 40 then temp3=temp3-10 endif endif if command=volumeup then if servonumber=0 then if temp0 < 2000 then temp0=temp0+10 else if temp3 < 2000 then temp3=temp3+10 endif endif if servonumber = 0 then if temp<>temp0 then'or temp3<>temp0 then temp=temp0 ':temp3=temp0 gosub moveservos: endif else if temp<>temp3 then'or temp3<>temp0 then temp=temp3 ':temp3=temp0 gosub moveservos: endif endif return Button1: ServoNumber=0 DEBUG "@B1",10,13 temp0 = cwmin1 temp=temp0:for tempbyte=1 to 10:gosub moveservos:next tempbyte Button1_1: Gosub GetButtonInfo: temp=temp0 if command= menu then cwmin1=temp gosub writevbbls goto Restart endif goto Button1_1 Button2: ServoNumber=0 dEBUG "@B2",10,13 temp0=middle1 temp=temp0:for tempbyte=1 to 10:gosub moveservos:next tempbyte Button2_0: gosub getbuttoninfo: temp=temp0 if command= menu then middle1=temp gosub writevbbls goto Restart endif goto Button2_0 Button3: ServoNumber=0 DEBUG "@B3",10,13 temp0=ccwmax1 temp=temp0:for tempbyte=1 to 10:gosub moveservos:next tempbyte Button3_0: gosub getbuttoninfo: temp=temp0 if command= menu then ccwmax1=temp gosub writevbbls goto Restart endif goto Button3_0 Button4: ServoNumber=1 DEBUG "@B4",10,13 temp3 = cwmin2 temp=temp3:for tempbyte=1 to 10:gosub moveservos:next tempbyte Button4_1: Gosub GetButtonInfo: temp=temp3 if command= menu then cwmin2=temp gosub writevbbls goto Restart endif goto Button4_1 Button5: ServoNumber=1 DEBUG "@B5",10,13 temp3=middle2 temp=temp3:for tempbyte=1 to 10:gosub moveservos:next tempbyte Button5_0: gosub getbuttoninfo: temp=temp3 if command= menu then middle2=temp gosub writevbbls goto Restart endif goto Button5_0 Button6: ServoNumber=1 DEBUG "@B6",10,13 temp3=ccwmax2 temp=temp3:for tempbyte=1 to 10:gosub moveservos:next tempbyte Button6_0: gosub getbuttoninfo: temp=temp3 if command= menu then ccwmax2=temp gosub writevbbls goto Restart endif goto Button6_0 Behavior1: ' 1 = normal, 2 = immediate move DEBUG "@B7",10,13 B1: tempbyte=tempbyte+1 if tempbyte.bit4 =1 then toggle led gosub getir if command <one or command > two then b1 low led if command=one then Servo1Behavior=0 else Servo1Behavior=1 endif dEBUG "SB1=",#servo1behavior,10,13 gosub writevbbls goto Restart Behavior2: DEBUG "@B8",10,13 B2: tempbyte=tempbyte+1 if tempbyte.bit4 =1 then toggle led gosub getir if command <one or command > two then b2 low led if command=one then Servo2Behavior=0 else Servo2Behavior=1 endif gosub writevbbls goto Restart Time1: pause 500 dEBUG "@B9",10,13 T1: tempbyte=tempbyte+1 if tempbyte.bit4 =1 then toggle led gosub getir if command <one or command > zero then t1: low led command=command -127 if command=10 then repeatcnt1=255 else repeatcnt1=command*5 endif gosub writevbbls goto Restart Time2: pause 500 DEBUG "@B10",10,13 T2: tempbyte=tempbyte+1 if tempbyte.bit4 =1 then toggle led gosub getir if command <one or command > zero then T2: low led command=command -127 if command=10 then repeatcnt2=255 else repeatcnt2=command*5 endif gosub writevbbls goto Restart GetIR: command=0 Getstartbits: Pulsin IRin ,0,IRpulse_length(0) if IRpulse_length(0) < 200 then return Endif for xx=1 to 12 pulsin IRin,0,IRpulse_length(xx) next xx displaybits: if IRpulse_length(1) < 100 then Command.bit0 = 0 Else Command.bit0 = 1 endif if IRpulse_length(2) < 100 then Command.bit1 = 0 Else Command.bit1 = 1 endif if IRpulse_length(3) < 100 then Command.bit2 = 0 Else Command.bit2 = 1 endif if IRpulse_length(4) < 100 then Command.bit3 = 0 Else Command.bit3 = 1 endif if IRpulse_length(5) < 100 then Command.bit4 = 0 Else Command.bit4 = 1 endif if IRpulse_length(6) < 100 then Command.bit5 = 0 Else Command.bit5 = 1 endif if IRpulse_length(7) < 100 then Command.bit6 = 0 Else Command.bit6 = 1 endif if IRpulse_length(8) < 100 then Command.bit7 = 0 Else Command.bit7 = 1 Endif If Command.bit7 = 0 then 'Bit 7 is one of the device bits Command = Command + 1 Endif If Command = 10 then Command = 0 Endif ''@@@DEBUG 13,10,"command ", #command,13,10 return ShowVersion: IRFlag=0 for temp=1 to ver_whole gosub showver if irflag=1 then return next temp pause 500 if ver_decimal=0 then high led:pause 50:low led return endif for temp=1 to ver_decimal gosub showver if irflag=1 then return next temp pause 500 return ShowVer: high led: gosub irpause low led: gosub irpause return IRPause: for temp2=1 to 20 gosub getir: if command=retrn then IRFlag=1 return endif next temp2 return ReadVbbls: read 0,cwmin1.highbyte read 1,cwmin1.lowbyte read 2,ccwmax1.highbyte read 3,ccwmax1.lowbyte read 4,cwmin2.highbyte read 5,cwmin2.lowbyte read 6,ccwmax2.highbyte read 7,ccwmax2.lowbyte read 8,middle1.highbyte read 9,middle1.lowbyte read 10,middle2.highbyte read 11,middle2.lowbyte read 12, servo1behavior read 13, servo2behavior read 14, repeatcnt1 read 15, repeatcnt2 debug "vbbls ",#cwmin1," ",#ccwmax1," ",#cwmin2," ",#ccwmax2," ",#middle1," ",#middle2," ",#servo1behavior," ",#servo2behavior," ",#repeatcnt1," ",#repeatcnt2,10,13 return WriteVbbls: WRITE 0,cwmin1.highbyte WRITE 1,cwmin1.lowbyte WRITE 2,ccwmax1.highbyte WRITE 3,ccwmax1.lowbyte WRITE 4,cwmin2.highbyte WRITE 5,cwmin2.lowbyte WRITE 6,ccwmax2.highbyte WRITE 7,ccwmax2.lowbyte WRITE 8,middle1.highbyte WRITE 9,middle1.lowbyte WRITE 10,middle2.highbyte WRITE 11,middle2.lowbyte WRITE 12, servo1behavior WRITE 13, servo2behavior WRITE 14, repeatcnt1 WRITE 15, repeatcnt2 debug "vbbls ",#cwmin1," ",#ccwmax1," ",#cwmin2," ",#ccwmax2," ",#middle1," ",#middle2," ",#servo1behavior," ",#servo2behavior," ",#repeatcnt1," ",#repeatcnt2,10,13 return |