Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''ROBO-RALPH 833
''Manual-mode(Yellow light):
'Moves forward when joystick is moved forward
'Rotates 90CW when joystick is moved right and 90CCW when moved to the left.
''Auto-mode(White light):
'Code moves into AutoMode.
'A new cog that runs the ping sensors is launched in background.
'Eddie roams around avoiding obsticles until the button is pushed again.
''Kinect-mode(Green light)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''INFO'''''''''''''''''''''''''''
'The range that the IR sensors yield is from about 2500(close) and about 200(far). 1500 = about
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''TO DO''''''''''''''''''''''''''
'Joystick control should be "continuous" instead of only forward, spin left, and spin right.
'Impliment encoders for AUTO-MODE
'Should always have start and stop methods
'Channel 7 of the ADC reads the current voltage of the battery
'All encompasing method for all movements. Forward, reverse, rotate etc
'Can use pin 13 with Simple_Serial object for recieving data from processing.
'Run pings and IR's in Track-mode.
'Implement speech in response to picture being taken and various other functions.
{{''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''MOTOR-PIN KEY'''''''''''''''''''''
pin 19 = Left reverse
pin 20 = PWM left
pin 21 = Left forward
pin 22 = Right reverse
pin 23 = PWM right
pin 24 = Right forward
}}
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
OBJ
XB : "XBee_Object"
pst : "Parallax_Serial_Terminal"
ping : "Ping"
encoder: "Quadrature Encoder"
ADC : "MCP3208"
Serial : "Extended_FDSerial"
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
XB_Baud = 9600'
'_______________________________________________________________________________________________
'________________________________________________________THESE ARE ALL OF THE PIN DESIGNATIONS__
ping_pin0 = 0 'Right front(From it's point of view)
ping_pin1 = 1 'Center front ''This is the one pointing down. (Doesn't work because sound bo
ping_pin2 = 2 'Left front (From it's point of view)
ping_pin3 = 3 'Rear
front_servo4 = 4 '
rear_servo5 = 5 '
'Pin 6 is for the XBee to send data to the board.
ping_pin7 = 7 'Rear/Top/It's left
ping_pin8 = 8 'Front/Top/It's left
page \ [page] of \ [pages]
\ [date]
long IR_range2
long IR_range3
long DataUD
long DataLR
word DataIn
long pos[3]
long stack[20]
long stack1[20]
long stack2[20]
long stack3[20]
long stack4[20]
long stack5[20]
long stack6[20]
long stack7[20]
long stack8[20]
long PingsCog
long PingsCog_k
long JoyStickValueUDCog
long JoyStickValueLRCog
long ServoCog
long XBCog
long EL_tapeCOG
long BeepCOG
long P_checkCOG
long K_LEDCOG
long Battery_CheckCOG
long K_DataIn_z
long K_DataIn_x
word K_Character
long K_CharIn
long Battery_Voltage
Pub Init
XB.start(XB_Rx, XB_Tx, 0, XB_Baud) 'Initialize comms for XBee
'pst.start(9600) 'Using this to print to serial monitor
ADC.start(chipDIO, chipCLK, chipSel, 255)
Serial.start(31, 30, 0, 9600) ' Either pst OR Serial, not both!! 'This
Battery_CheckCOG := cognew(Batt_RGB_LED, @Stack8)
Start
Pub Start
repeat
DataIn := XB.Rx 'IMPORTANT: XB.Rx can only receive one digit a
'This tells the motors what to do based on the tracked user's position.
repeat 'FIRST ADJUST X-POS THEN Z-POS.
if (K_DataIn_x < -K_Horiz_dist) AND (range0 > Ping_dist) AND (IR_range1 < IR_dist) AND (rang
K_CW
waitcnt(clkfreq/100 + cnt)
if (K_DataIn_x > K_Horiz_dist) AND (range2 > Ping_dist) AND (IR_range2 < IR_dist) AND (range
K_CCW
waitcnt(clkfreq/100 + cnt)
if (K_DataIn_z > K_Far_dist) AND (K_DataIn_z <> 0) AND (range0 > Ping_dist) AND (range1 > Pi
K_forward
waitcnt(clkfreq/100 + cnt)
if (K_DataIn_z < K_Near_dist) AND (K_DataIn_z <> 0) AND (range3 > Ping_dist) AND (IR_range3
K_reverse
waitcnt(clkfreq/100 + cnt)
DataIn := XB.Rx
if DataIn <> "k"
waitcnt(clkfreq + cnt)
Start
repeat
range0 := ping.Inches(ping_pin0) 'Front right
range1 := ping.Inches(ping_pin1) 'Front on servo
range2 := ping.Inches(ping_pin2) 'Front left
range3 := ping.Inches(ping_pin3) 'Back
range7 := ping.Inches(ping_pin7) 'Top/Rear/Left
range8 := ping.Inches(ping_pin8) 'Top/Front/Left
range9 := ping.Inches(ping_pin9) 'Top/Rear/Right
range10:= ping.Inches(ping_pin10) 'Top/Front/Right
DataIn := XB.Rx 'Having this cog check DataIn slows down the ping sen
repeat
Serial.RxFlush 'This needed to clear out the rx buffer. Will give inac
K_CharIn := Serial.Rx
PicIn := K_CharIn
if PicIn == "p"
waitcnt(clkfreq + cnt)
Speaker_4_Pic
K_DataIn_x := Serial.RxDec
repeat until K_CharIn == "z" '1700 is approximately 4' from kinect. Lar
Serial.RxFlush
K_CharIn := Serial.Rx
K_DataIn_z := Serial.RxDec
repeat
if K_CharIn == "x" OR K_CharIn == "z" AND K_DataIn_x <> 0 AND K_DataIn_z <> 0
DIRA[K_track_led] := OUTA[K_track_led] := 1
waitcnt(clkfreq/10+ cnt)
OUTA[K_track_led] := 0
waitcnt(clkfreq/10 + cnt)
{
repeat
Check := Serial.Rxcheck
if Check <> -1
DIRA[K_track_led] := OUTA[K_track_led] := 1
waitcnt(clkfreq/10+ cnt)
page \ [page] of \ [pages]
\ [date]
OUTA[K_track_led] := 0
waitcnt(clkfreq/10 +cnt)
}
DIRA[Battery_GreenLED] := 1
DIRA[Battery_BlueLED] := 0
DIRA[Battery_RedLED] := 0
repeat
Battery_Voltage := adc.in(7)
' pst.dec(Battery_Voltage)
' pst.Str(String(pst#NL))
' waitcnt(clkfreq/10 + cnt)
PUB Speaker_4_Pic | i, a
DIRA[Speaker_Pin] := OUTA[Speaker_Pin] := 1
repeat 2
repeat 300
!OUTA[Speaker_Pin]
waitcnt(clkfreq/(500) + cnt)
waitcnt(clkfreq/2+ cnt)
repeat 1
repeat 750
!OUTA[Speaker_Pin]
waitcnt(clkfreq/(900) + cnt)
waitcnt(clkfreq/2+ cnt)
DIRA[Speaker_Pin] := OUTA[Speaker_Pin] := 0
t := cnt
repeat 30
phsa := phsb := -(pulse_length) 'Why is this negative?
t += Frequency 'phsa is the length of the pulse duration
waitcnt(t)
If (DataIn == "y") AND (range0 > Ping_dist) AND (range1 > Ping_dist) AND (range2 > Ping_dis
waitcnt(clkfreq/2 + cnt)
EL_tapeCOG := cognew(EL_tape, @Stack2)
ServoCog := cognew(Servo(front_servo4), @stack1)
Forward("y")
If (DataIn == "y") AND ((range1 < Ping_dist) OR (IR_range0 > IR_dist_ground)) 'Center
waitcnt(clkfreq/2 + cnt)
BeepCog := cognew(Beep, @Stack3)
ServoCog := cognew(Servo(rear_servo5), @stack4)
Reverse(60)
If (DataIn == "y") AND ((range0 < Ping_dist) OR (range10 < Ping_dist) OR (IR_range1 > IR_dis
waitcnt(clkfreq/2 + cnt)
Rotate90CCW
If (DataIn == "y") AND ((range2 < Ping_dist) OR (range8 < Ping_dist) OR (IR_range2 > IR_dis
waitcnt(clkfreq/2 + cnt)
Rotate90cw
repeat
range0 := ping.Inches(ping_pin0) 'Front right
range1 := ping.Inches(ping_pin1) 'Front on servo
range2 := ping.Inches(ping_pin2) 'Front left
range3 := ping.Inches(ping_pin3) 'Back
range7 := ping.Inches(ping_pin7) 'Top/Rear/Left
range8 := ping.Inches(ping_pin8) 'Top/Front/Left
range9 := ping.Inches(ping_pin9) 'Top/Rear/Right
range10:= ping.Inches(ping_pin10) 'Top/Front/Right
DataIn := XB.Rx 'Having this cog check DataIn slows down the ping sen
if (DataIn <> "y") 'Can't stop a cog that has never started.
cogstop(El_tapeCog)
page \ [page] of \ [pages]
\ [date]
cogstop(PingsCog) 'This must be last or else any commands that follow will not be exe
cogstop(ServoCog)
ctra[5..0] := 20
ctrb[5..0] := 23
frqa := frqb := 1 'The frq register adds one to the current value of the p
dira[20]~~
dira[23]~~
Frequency := clkfreq/20_000 'This controls the frequency that the repeat loops cycle
Pulse_length := Frequency/Speed 'This controls the duration within a single cycle of the
'Would like to exit the loop when transmitter power is shut off, but I can't figure out how(N
repeat until (dataIn <> mode) or (range0 < Ping_dist) or (range1 < Ping_dist) or (range2 < P
t := cnt 'The reading of the current clock position mu
repeat 1_000 'Cannot check DataIn := XB.Rx while in the re
phsa := phsb:= -Pulse_length 'Why is this negative?
t += Frequency 'phsa is the length of the pulse duration.
waitcnt(t)
if EL_tapeCOG <> 0
cogstop(EL_tapeCOG)
if ServoCog <> 0
cogstop(ServoCog)
if dataIn == "y"
Auto_Mode
t := cnt
repeat while i > -15000 '27_000 seems to be the farthest right that the servo can pan.
i -= 3000
phsa := phsb := -(pulse_length + i) 'Why is this negative?
t += Frequency 'phsa is the length of the pulse duration
waitcnt(t)
PUB EL_tape
dira[EL_Pin]~~
repeat
!outa[EL_Pin]
waitcnt(clkfreq/5 + cnt)
PUB Encoder_Read
ctra[30..26] := %00100
ctrb[30..26] := %00100
ctra[5..0] := 20
ctrb[5..0] := 23
dira[20]~~
dira[23]~~
if (DataIn == "y") and (range3 > Ping_dist) and (IR_range3 < IR_dist) AND (range7 > Ping_dist)
repeat iterations
if (range3 > Ping_dist) AND (IR_range3 < IR_dist) AND (range7 > Ping_dist) AND (range9 > Pin
t := cnt 'The reading
repeat 1_000 'The number
phsa := phsb:= -Pulse_length
t += Frequency 'phsa is the
waitcnt(t)
cogstop(BeepCOG)
cogstop(servoCog)
PUB Beep
DIRA[Speaker_Pin] := OUTA[Speaker_Pin] := 1
repeat
repeat 350
!OUTA[Speaker_Pin]
waitcnt(clkfreq/500 + cnt)
waitcnt(clkfreq/2+ cnt)
ctra[30..26] := %00100
ctrb[30..26] := %00100
ctra[5..0] := 20
ctrb[5..0] := 23
dira[20]~~
dira[23]~~
ctra[30..26] := %00000
ctrb[30..26] := %00000
waitcnt(clkfreq/2 + cnt)
if (DataIn == "y")
Auto_Mode
' if(DataIn == "k")
' Track_Mode
PUB Rotate90CW | Frequency, Pulse_length, t 'Used for AUTO MODE.
ctra[30..26] := %00100
ctrb[30..26] := %00100
ctra[5..0] := 20
ctrb[5..0] := 23
page \ [page] of \ [pages]
\ [date]
frqa := frqb := 1 'The frq register adds one to the current value of the phs reg
dira[20]~~
dira[23]~~
Frequency := clkfreq/20_000 'This controls the frequency that the repeat loops cycles
Pulse_length := Frequency/Speed 'This controls the duration within a single cycle of the a
ctra[30..26] := %00000
ctrb[30..26] := %00000
waitcnt(clkfreq/2 + cnt)
if (DataIn == "y")
Auto_Mode
' if(DataIn == "k")
' Track_Mode
Pub Manualforward | Frequency, Pulse_length, t 'This method needs some work. Somehow it
ctra[30..26] := %00100
ctrb[30..26] := %00100
ctra[5..0] := 20
ctrb[5..0] := 23
dira[20]~~
dira[23]~~
cogstop(JoyStickValueUDCog)
ctra[30..26] := %00000 ''Put this here to
ctrb[30..26] := %00000
Start
repeat
DataIn := XB.Rx 'Here we read the value being sent from the controller to th
if DataIn == "!"
DataUD := XB.RxDec
ctra[30..26] := %00100 'Configures counters for CTRMODE(the 30..26 part) and single ended NC
ctrb[30..26] := %00100
frqa := frqb := 1 'The frq register adds one to the current value of the phs reg
dira[20]~~
dira[23]~~ 'Sets PWM pins as outputs(the ~~ part means they are out
Frequency := clkfreq/20_000 'This controls the frequency that the repeat loops cycles
Pulse_length := Frequency/Speed 'This controls the duration within a single cycle of the a
t := cnt
repeat until DataLR > 200 'Speed holds here until cond
phsa := phsb:= -Pulse_length 'The reading of the current
t += Frequency 'Cannot check DataIn := XB.R
waitcnt(t)
cogstop(JoyStickValueLRCog)
ctra[30..26] := %00000
ctrb[30..26] := %00000
repeat
DataIn := XB.Rx 'Here we read the value being sent from the controller to th
if DataIn == "@"
DataLR := XB.RxDec
ctra[30..26] := %00100
ctrb[30..26] := %00100
page \ [page] of \ [pages]
\ [date]
ctra[5..0] := 20
ctrb[5..0] := 23
frqa := frqb := 1 'The frq register adds one to the current value of the phs reg
dira[20]~~
dira[23]~~ 'Sets PWM pins as outputs(the ~~ part means they are out
Frequency := clkfreq/20_000 'This controls the frequency that the repeat loops cycles
Pulse_length := Frequency/Speed 'This controls the duration within a single cycle of the a
t := cnt
repeat until DataLR < 800 'Speed holds here until cond
phsa := phsb:= -Pulse_length 'The reading of the current
t += Frequency 'Cannot check DataIn := XB.R
waitcnt(t)
cogstop(JoyStickValueLRCog)
ctra[30..26] := %00000
ctrb[30..26] := %00000
ctra[5..0] := 20
ctrb[5..0] := 23
frqa := frqb := 1 'The frq register adds one to the current value of the p
dira[20]~~
dira[23]~~
page \ [page] of \ [pages]
\ [date]
Frequency := clkfreq/20_000 'This controls the frequency that the repeat loops cycle
Pulse_length := Frequency/(K_Speed) 'This controls the duration within a single cycle of
repeat until (K_DataIn_z < K_Far_dist) OR (DataIn <> "k") OR (K_CharIn == "l") OR (K_DataIn_x
t := cnt 'The reading of the current clock position mu
repeat 1_000 'Cannot check DataIn := XB.Rx while in the re
phsa := phsb:= -Pulse_length 'Why is this negative?
t += Frequency 'phsa is the length of the pulse duration.
waitcnt(t)
PUB K_Reverse | Frequency, Pulse_length, t ''For AUTO MODE. Remember: 'Cannot check D
ctra[30..26] := %00100
ctrb[30..26] := %00100
ctra[5..0] := 20
ctrb[5..0] := 23
dira[20]~~
dira[23]~~
repeat until (K_DataIn_z > K_Near_dist) OR (DataIn <> "k") OR (K_CharIn == "l") OR (range3 < P
t := cnt
repeat 1_000 'The readin
phsa := phsb:= -Pulse_length
t += Frequency 'phsa is the
waitcnt(t)
ctra[30..26] := %00100
ctrb[30..26] := %00100
ctra[5..0] := 20
ctrb[5..0] := 23
frqa := frqb := 1 'The frq register adds one to the current value of the phs reg
dira[20]~~
dira[23]~~ 'Sets PWM pins as outputs(the ~~ part means they are out
Frequency := clkfreq/20_000 'This controls the frequency that the repeat loops cycles
Pulse_length := Frequency/(K_Speed) 'This controls the duration within a single cycle of t
repeat until (K_DataIn_x > -K_Horiz_dist) OR (DataIn <> "k") OR (K_CharIn == "l") OR (range0 < P
t := cnt
repeat 100
phsa := phsb:= -Pulse_length 'The reading of the current
t += Frequency 'Cannot check DataIn := XB.R
waitcnt(t)
ctra[30..26] := %00000
ctrb[30..26] := %00000
ctra[30..26] := %00100 'Configures counters for CTRMODE(the 30..26 part) and single ended NC
ctrb[30..26] := %00100
frqa := frqb := 1 'The frq register adds one to the current value of the p
dira[20]~~
dira[23]~~ 'Sets PWM pins as outputs(the ~~ part means they are out
Frequency := clkfreq/20_000 'This controls the frequency that the repeat loops cycles
Pulse_length := Frequency/(K_Speed) 'This controls the duration within a single cycle of t
repeat until (K_DataIn_x < K_Horiz_dist) OR (DataIn <> "k") OR (K_CharIn == "l") OR (range2 < Pi
t := cnt
repeat 100
phsa := phsb:= -Pulse_length 'The reading of the current
t += Frequency 'Cannot check DataIn := XB.R
waitcnt(t)
ctra[30..26] := %00000
ctrb[30..26] := %00000