« November 2004 | Main

December 18, 2004

Frozen Code

What we are assuming will work for the show

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : robotGroup
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection

lightThreshold con 100 'phototransistor threshold
searchTimeOut con 30000 'how log does it look
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading
readMotion2 var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor

lastRight var BYTE
lastLeft var BYTE
lastCenter var BYTE

'-- state flags
leftLightVar var bit
rightLightVar var bit
centerLightVar var bit

lastRightFlag var bit
lastLeftFlag var bit
lastCenterFlag var bit

foundCenter var bit
iFoundIt var bit
iLostIt var bit


'-- counters
turnCounter var word
turnCounter = 0


' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence


main:
HIGH PORTD.2
Pause 100
LOW PORTD.2


'get values

ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 2, lefttransistor 'GET THE TRANSISTOR READING on the right
ADCIN 3, centerTRANSISTOR 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 4, rightTRANSISTOR 'GET THE READING ON THE CENTER TRANSISTOR


'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

'debug sensor infomation
'for somereason this seems to lock up for a while
'SEROUT2 tx, inv9600, ["ir is ", dec readMotion, 13,10, "RIGHTLIGHT IS ", dec RIGHTTRANSISTOR, 13,10, "LEFTLIGHT IS ", dec LEFTTRANSISTOR, 13,10, "CENTERLIGHT IS ", dec CENTERTRANSISTOR, 13,10]

If (getIR > 400) Then fullBackward

IF (centerTransistor > lightThreshold) THEN
'the value to set this should be such that going forward is the right thing to do?
centerLightVar = 1
else
centerLightVar = 0
endif

IF (lefttransistor > lightThreshold) THEN
leftLightVar = 1
else
leftLightVar = 0
endIF

IF (righttransistor > lightThreshold) THEN
rightLightVar = 1
else
rightLightVar = 0
endIF


IF (centerLightVar == 1) THEN centerT
if (leftLightVar == 1) and (rightLightVar == 1) then compareSides
if (leftLightVar == 1) then leftT
if (rightLightVar == 1) then rightT

IF (getIR >= 300) AND (getIR <= 400 )Then leftBackward
IF (getIR >= 250) AND (getIR <= 300 )Then rightBackward
IF (getIR >= 220) AND (getIR <= 250 )Then standStillLeft
IF (getIR >= 200) AND (getIR <= 220 )Then standStillRight
IF (getIR < 200) then fullForward

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html

goto main


compareSides:
if lefttransistor > righttransistor then leftT
if lefttransistor < righttransistor then rightT
if lefttransistor = righttransistor then leftT
goto main

centerT:
'rc4
HIGH PORTC.4
'go forward
PORTB = %01010000
pause 500
LOW PORTC.4
lastCenter = centerTransistor
lastCenterFlag = 1
'set all wiggle timers to 0?
goto main

rightT:
'rc4
HIGH PORTD.3
gosub searchingRight
LOW PORTD.3
lastRight = centerTransistor
lastRightFlag = 1
goto main

leftT:
'rd3
HIGH PORTC.5
gosub searchingLeft
LOW PORTC.5
lastLeft = centerTransistor
lastLeftFlag = 1
goto main

searchingRight:
while (centerTransistor < lightThreshold) and (turnCounter < searchTimeOut)
ADCIN 3, centerTransistor
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
return

searchingLeft:
while (centerTransistor < lightThreshold) and (turnCounter < searchTimeOut)
ADCIN 3, centerTransistor
'right wheel forward to turn left
PORTB = %00010000
turnCounter = turnCounter + 1
wend
turnCounter = 0
return

fullForward:
PORTB = %01010000
goto main

fullBackward:
PORTB = %10100000
goto main

fullStop:
PORTB = %00000000
goto main

leftForward:
PORTB = %01000000
goto main

leftBackward:
PORTB = %10000000
goto main

rightForward:
PORTB = %00010000
goto main

rightBackward:
PORTB = %00100000
goto main

standStillLeft:
PORTB = %01100000
pause 700
goto main

standStillRight:
PORTB = %10010000
pause 500
goto main

Posted by cm1002 at 01:27 AM | Comments (0)

Things to do (no order)

One of my famous lists

Physical / Power
? Make Wings
Add a power button (at center of wing joint)
charge & deplete the batteries
wire leads on the ends of the power caps
figure out how the new battery packs are going to fit on the bees
to corral or not to corral

Code
Get the latest copy of the code on all the chips
Tune the constants
more the IR to dominant?

do we want it to wiggle?

Phototransistor Hell
turn eyes out
add caps
bring a flash light
make a "superbright flashlight" so we know what we are dealing with from that.
do the phototransistors need a cup?
wire a board with serial so can watch the values again
more light from the tails? (more LED, tin collar?)
- put solution on other bees

Posted by cm1002 at 12:49 AM | Comments (0)

December 17, 2004

searchingRight

Things tried troubleshooting a WHILE statement or "Seven steps to realize how stupid you can be."

Option 7 - final, for now
Lesson learned: a counter moves wicked faster than pulse count. Some stupid tax on this one.

searchingRight:
while (centerTransistor < lightThreshold) and (turnCounter < searchTimeOut)
ADCIN 3, centerTransistor
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
return

Option 6
wow. this is crazyness 10000 keeps it lit for maybe 2 sseconds, settled on 25000 and set a constant so can change it at the top
'-- counters
turnCounter var word
turnCounter = 0

searchingRight:
while (turnCounter < 10000)
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
iFoundIt = 0
return

Option 5
wtf? this works. I mean I am counting to 13 (9 mississippi), not 3... is it variable overflow? if you comment out the turnCounter = 0 line it works? the turn counter is randomly reseting? raising only the while statement condition 6000 locks it out again. Is the chip reseting? am I crazy? Is it time to re-wire the board for serial...
'-- counters
turnCounter var word
turnCounter = 3001

searchingRight:
while (turnCounter > 3000)
ADCIN 3, centerTransistor
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 3000
iFoundIt = 0
return

Option 5
well aparently turnCounter is NEVER < 3000??? (releases as soon as the flashlight is off the transistor.) shhhht
searchingRight:
while (turnCounter < 3000)
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
iFoundIt = 0
return

Option 4
Not suprisingly same as the last
searchingRight:
while (iFoundIt = 0)
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
if (centerTransistor > 75) or (turnCounter > 3000) then
iFoundIt = 1
else
iFoundIt = 0
endif
wend
turnCounter = 0
iFoundIt = 0
return

Option 3
Releases as soon as the flashlighlight is off the right transistor. Commenting out last iFoundIt = 0 means the condition never finds true again so it is checking the while statement...
searchingRight:
while (iFoundIt = 0)
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
if (centerTransistor < 75) AND (turnCounter < 3000) then
iFoundIt = 0
else
iFoundIt = 1
endif
wend
turnCounter = 0
iFoundIt = 0
return

Option 2
Light blinks on and off, one second interval? Never escapes
searchingRight:
while ((centerTransistor < 75) and (turnCounter < 3000))
ADCIN 3, centerTransistor
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
return

Option 1
works like a charm, stays turning until the flashlight shines on the middle phototransitor.
searchingRight:
while centerTransistor < 75
ADCIN 3, centerTransistor
'right wheel forward to turn left
PORTB = %00010000
wend
return

Posted by cm1002 at 03:47 PM | Comments (0)

December 16, 2004

flocking continued 12_16_04

(room transfer)

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : robotGroup
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection

lightThreshold con 100 'phototransistor threshold
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading
readMotion2 var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor

lastRight var BYTE
lastLeft var BYTE
lastCenter var BYTE

'-- state flags
leftLightVar var bit
rightLightVar var bit
centerLightVar var bit

lastRightFlag var bit
lastLeftFlag var bit
lastCenterFlag var bit

foundCenter var bit
iLostIt var bit


'-- counters
turnCounter var word


' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence


main:
HIGH PORTD.2
Pause 100
LOW PORTD.2


'get values

ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 2, lefttransistor 'GET THE TRANSISTOR READING on the right
ADCIN 3, centerTRANSISTOR 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 4, rightTRANSISTOR 'GET THE READING ON THE CENTER TRANSISTOR


'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

'debug sensor infomation
'for somereason this seems to lock up for a while
'SEROUT2 tx, inv9600, ["ir is ", dec readMotion, 13,10, "RIGHTLIGHT IS ", dec RIGHTTRANSISTOR, 13,10, "LEFTLIGHT IS ", dec LEFTTRANSISTOR, 13,10, "CENTERLIGHT IS ", dec CENTERTRANSISTOR, 13,10]

If (getIR > 400) Then fullBackward

IF (centerTransistor > lightThreshold) THEN
'the value to set this should be such that going forward is the right thing to do?
centerLightVar = 1
else
centerLightVar = 0
endif

IF (lefttransistor > lightThreshold) THEN
leftLightVar = 1
else
leftLightVar = 0
endIF

IF (righttransistor > lightThreshold) THEN
rightLightVar = 1
else
rightLightVar = 0
endIF


IF (centerLightVar == 1) THEN centerT
if (leftLightVar == 1) and (rightLightVar == 1) then compareSides
if (leftLightVar == 1) then leftT
if (rightLightVar == 1) then rightT

IF (getIR >= 300) AND (getIR <= 400 )Then leftBackward
IF (getIR >= 250) AND (getIR <= 300 )Then rightBackward
IF (getIR >= 220) AND (getIR <= 250 )Then standStillLeft
IF (getIR >= 200) AND (getIR <= 220 )Then standStillRight
IF (getIR < 200) then fullForward

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html

goto main


compareSides:
if lefttransistor > righttransistor then leftT
if lefttransistor < righttransistor then rightT
if lefttransistor = righttransistor then leftT
goto main

centerT:
'rc4
HIGH PORTC.4
'go forward
PORTB = %01010000
pause 500
LOW PORTC.4
lastCenter = centerTransistor
lastCenterFlag = 1
'set all wiggle timers to 0?
goto main

rightT:
'rc4
HIGH PORTD.3
gosub searchingRight
LOW PORTD.3
lastRight = centerTransistor
lastRightFlag = 1
goto main

leftT:
'rd3
HIGH PORTC.5
gosub searchingRight
LOW PORTC.5
lastLeft = centerTransistor
lastLeftFlag = 1
goto main

searchingRight:
'ADCIN 3, centerTRANSISTOR
'while (centerTransistor < 75 and turnCounter < 2000)
while centerTransistor < 75
ADCIN 3, centerTRANSISTOR
'left wheel forward to turn right
PORTB = %01000000
turnCounter = turnCounter + 1
wend
turnCounter = 0
return

searchingLeft:
'ADCIN 3, centerTRANSISTOR
while centerTransistor < 75
ADCIN 3, centerTRANSISTOR
'right wheel forward to turn left
PORTB = %00010000
wend
return

fullForward:
PORTB = %01010000
goto main

fullBackward:
PORTB = %10100000
goto main

fullStop:
PORTB = %00000000
goto main

leftForward:
PORTB = %01000000
goto main

leftBackward:
PORTB = %10000000
goto main

rightForward:
PORTB = %00010000
goto main

rightBackward:
PORTB = %00100000
goto main

standStillLeft:
PORTB = %01100000
pause 700
goto main

standStillRight:
PORTB = %10010000
pause 500
goto main

Posted by cm1002 at 06:27 PM | Comments (0)

psudo code for better flocking pre-alpha

some jibber jabber to get me thinking

if there is a light on left
set leftPhotolightVar = true
end it

if there is a light on right
set rightPhotolightVar = true
end it

if there is a light on center
set centerPhotolightVar = true
end it

is the leftPhotolightVar = true?
is the turnCounter < Y
turn leftForward
is the center lit?
turnCounter = 0
leftPhotolightVar
foundCenter = true
else
turnCounter = 0
end if
end if

if foundCenter = true
go forward
lastFoundCenter = true
else
if lasfFoundcenter = true
iLostit = true
endif
endif

if iLostit
sine and cos the motors? look and then just move around
endif

ir behavior routine here

Posted by cm1002 at 05:31 PM | Comments (0)

December 08, 2004

Schematic - Round 2 (Class Final)

Main Schematic

Power Schematic

Posted by cm1002 at 07:07 PM | Comments (0)

The final parts list

Parts as listed on the schematic

Basic Microcontroller Setup
1 PIC chip: Microchip: 18F452
1 10 k? resisitor (pull up reset pin)
1 4 Mhz clock: SparkFun: Comp-XTAL, HC49/UA Package
2 22 pF capacitor (for clock)
1 1 k? resistor (for system check LED)
1 regular LED (system check LED)

Motors
1 H-bridge: Texas Instruments: SN754410NE
2 motors: Solarbotics: GM8
2 green LED (direction status)
2 red LED (direction status)
2 1 k? resistor (for status LED)

Power Setup
1 Switch
2 heavy duty heat sink: ANGLIA: TV5, Farnell: 170-072
2 5V regulator: TIP7805
2 diodes
2 100 µF capacitor
2 0.1 µF capacitor

Sensors
1 IR detector: Sharp: GP2D12
3 phototransistor: Ledtech: LT9593-91-0125
3 22 k? resisitor:
0 ultra-sonic movement detector: Jameco: 125090 , MFG#:DK20(6020 KT)
1 Super Bright LEDs: Sparkfun:Comp-SBL
3 1 k? resisitors (for phototransistor status lights)
3 yellow LEDs (phototransistor status lights)
3 0.001 µF capacitors (future: to even out signal)

Posted by cm1002 at 06:03 PM | Comments (0)

The final code

for class anyway:

some last minute sdvice: put capacitors and change the resistors, change the power source to keep the phototrans from overloading the circuit.

- use the 29 suummmathin 05 instead of the TIP 7805 (the 8 stands for the min. number of volts you can put into it... who knew)
- remember for the pic, 25 miliamps/pin max over a 3 pin max
- 1000 ohm normal LED - 220 superb

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : robotGroup
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading
readMotion2 var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor

' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence


main:
HIGH PORTD.2
Pause 100
LOW PORTD.2


'get values

ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 2, lefttransistor 'GET THE TRANSISTOR READING on the right
ADCIN 3, centerTRANSISTOR 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 4, rightTRANSISTOR 'GET THE READING ON THE CENTER TRANSISTOR


'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

'debug sensor infomation
'for somereason this seems to lock up for a while
'SEROUT2 tx, inv9600, ["ir is ", dec readMotion, 13,10, "RIGHTLIGHT IS ", dec RIGHTTRANSISTOR, 13,10, "LEFTLIGHT IS ", dec LEFTTRANSISTOR, 13,10, "CENTERLIGHT IS ", dec CENTERTRANSISTOR, 13,10]


If (getIR > 400) Then fullBackward
IF (righttransistor > 150) THEN rightT
IF (lefttransistor > 150) THEN leftT
IF (CENTERTRANSISTOR > 150) THEN cenerT
IF (getIR >= 300) AND (getIR <= 400 )Then leftBackward
IF (getIR >= 250) AND (getIR <= 300 )Then rightBackward
IF (getIR >= 220) AND (getIR <= 250 )Then standStillLeft
IF (getIR >= 200) AND (getIR <= 220 )Then standStillRight
IF (getIR < 200) then fullForward

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html

goto main

cenerT:
PORTB = %00000000
'rc4
HIGH PORTC.4
PORTB = %01010000
pause 500
LOW PORTC.4
'gosub fullForward
goto main

rightT:
PORTB = %00000000
'rc4
HIGH PORTD.3
pause 500
PORTB = %01000000
LOW PORTD.3
'GOSUB leftForward
goto main

leftT:
PORTB = %00000000
'rd3
HIGH PORTC.5
pause 100
PORTB = %00010000
LOW PORTC.5
'GOSUB rightForward
goto main

fullForward:
PORTB = %01010000
goto main

fullBackward:
PORTB = %10100000
goto main

fullStop:
PORTB = %00000000
goto main

leftForward:
PORTB = %01000000
goto main

leftBackward:
PORTB = %10000000
goto main

rightForward:
PORTB = %00010000
goto main

rightBackward:
PORTB = %00100000
goto main

standStillLeft:
PORTB = %01100000
pause 700
goto main

standStillRight:
PORTB = %10010000
pause 500
goto main

Posted by cm1002 at 05:54 PM | Comments (0)

Rockin kick ass begining of everything code

This moves. This avoid things. This goes towards the light.

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : robotGroup
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading
readMotion2 var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor

' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence


main:
HIGH PORTD.2
Pause 100
LOW PORTD.2


'get values

ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 2, lefttransistor 'GET THE TRANSISTOR READING on the right
ADCIN 3, centerTRANSISTOR 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 4, rightTRANSISTOR 'GET THE READING ON THE CENTER TRANSISTOR


'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

'readMotion2 = ((1024 - getSonic) / 8)

'readMotion = ((1024 - getIR) / 8)
'translates the values to be 127 to 60
'from the range of 12 inches to 3 inches

'debug sensor infomation
'for somereason this seems to lock up for a while
'SEROUT2 tx, inv9600, ["ir is ", dec readMotion, 13,10, "RIGHTLIGHT IS ", dec RIGHTTRANSISTOR, 13,10, "LEFTLIGHT IS ", dec LEFTTRANSISTOR, 13,10, "CENTERLIGHT IS ", dec CENTERTRANSISTOR, 13,10]


If (getIR > 400) Then fullBackward
IF (righttransistor > 150) THEN rightT
IF (lefttransistor > 150) THEN leftT
IF (CENTERTRANSISTOR > 150) THEN cenerT
IF (getIR >= 300) AND (getIR <= 400 )Then leftBackward
IF (getIR >= 250) AND (getIR <= 300 )Then rightBackward
IF (getIR >= 220) AND (getIR <= 250 )Then standStillLeft
IF (getIR >= 200) AND (getIR <= 220 )Then standStillRight
IF (getIR < 200) then fullForward

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html

goto main

cenerT:
PORTB = %00000000
'rc4
HIGH PORTC.4
PORTB = %01010000
pause 500
LOW PORTC.4
'gosub fullForward
goto main

rightT:
PORTB = %00000000
'rc4
HIGH PORTD.3
pause 500
PORTB = %01000000
LOW PORTD.3
'GOSUB leftForward
goto main

leftT:
PORTB = %00000000
'rd3
HIGH PORTC.5
pause 100
PORTB = %00010000
LOW PORTC.5
'GOSUB rightForward
goto main

fullForward:
PORTB = %01010000
goto main

fullBackward:
PORTB = %10100000
goto main

fullStop:
PORTB = %00000000
goto main

leftForward:
PORTB = %01000000
goto main

leftBackward:
PORTB = %10000000
goto main

rightForward:
PORTB = %00010000
goto main

rightBackward:
PORTB = %00100000
goto main

standStillLeft:
PORTB = %01100000
pause 700
goto main

standStillRight:
PORTB = %10010000
pause 500
goto main

Posted by cm1002 at 11:48 AM | Comments (0)

No more read motion

not necessarily the best idea to get rig of it... makes it more erratic but it can see further... good and bad there. problem is that ir readings aren't linear...

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : robotGroup
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading
readMotion2 var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor

' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence

main:
HIGH PORTD.2
Pause 100
LOW PORTD.2


'get values

ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 1, lefttransistor 'GET THE TRANSISTOR READING on the right
ADCIN 2, centerTRANSISTOR 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 3, rightTRANSISTOR 'GET THE READING ON THE CENTER TRANSISTOR


'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

'readMotion2 = ((1024 - getSonic) / 8)

'readMotion = ((1024 - getIR) / 8)
'translates the values to be 127 to 60
'from the range of 12 inches to 3 inches

'debug sensor infomation
'for somereason this seems to lock up for a while
'SEROUT2 tx, inv9600, ["ir is ", dec readMotion, 13,10, "RIGHTLIGHT IS ", dec RIGHTTRANSISTOR, 13,10, "LEFTLIGHT IS ", dec LEFTTRANSISTOR, 13,10, "CENTERLIGHT IS ", dec CENTERTRANSISTOR, 13,10]

If (getIR > 400) Then fullStop
IF (getIR >= 300) AND (getIR <= 400 )Then leftBackward
IF (getIR >= 250) AND (getIR <= 300 )Then rightBackward
IF (getIR >= 220) AND (getIR <= 250 )Then standStillLeft
IF (getIR >= 200) AND (getIR <= 220 )Then standStillRight
IF (getIR < 200) then fullForward

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html

goto main

fullForward:
PORTB = %01010000
goto main

fullBackward:
PORTB = %10100000
goto main

fullStop:
PORTB = %00000000
goto main

leftForward:
PORTB = %01000000
goto main

leftBackward:
PORTB = %10000000
goto main

rightForward:
PORTB = %00010000
goto main

rightBackward:
PORTB = %00100000
goto main

standStillLeft:
PORTB = %01100000
pause 700
goto main

standStillRight:
PORTB = %10010000
pause 500
goto main

Posted by cm1002 at 01:28 AM | Comments (0)

Baseline code

This is the code that sorta works kinda

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : robotGroup
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading
readMotion2 var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor

' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence

main:
HIGH PORTD.2
Pause 100
LOW PORTD.2


'get values

ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 1, lefttransistor 'GET THE TRANSISTOR READING on the right
ADCIN 2, centerTRANSISTOR 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 3, rightTRANSISTOR 'GET THE READING ON THE CENTER TRANSISTOR


'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

'readMotion2 = ((1024 - getSonic) / 8)

readMotion = ((1024 - getIR) / 8)

'translates the values to be 127 to 60
'from the range of 12 inches to 3 inches

'debug sensor infomation
'for somereason this seems to lock up for a while
SEROUT2 tx, inv9600, ["ir is ", dec readMotion, 13,10, "RIGHTLIGHT IS ", dec RIGHTTRANSISTOR, 13,10, "LEFTLIGHT IS ", dec LEFTTRANSISTOR, 13,10, "CENTERLIGHT IS ", dec CENTERTRANSISTOR, 13,10]

IF (READMOTION < 60) THEN rightBackward
IF (READMOTION >= 60 ) AND (READMOTION <= 70 ) THEN leftBackward
IF (readMotion < basicSpeed) Then rightBackward
If (readMotion = basicSpeed) Then fullStop
If (readMotion > basicSpeed) Then fullForward
IF (righttransistor > 200) THEN rightbackward
IF (lefttransistor > 200) THEN leftbackward
IF (CENTERTRANSISTOR > 200) THEN fullForward

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html
pause 1000

goto main

fullForward:
PORTB = %01010000
goto main

fullBackward:
PORTB = %10100000
goto main

fullStop:
PORTB = %00000000
goto main

leftForward:
PORTB = %01000000
goto main

leftBackward:
PORTB = %10000000
goto main

rightForward:
PORTB = %00010000
goto main

rightBackward:
PORTB = %00100000
goto main

standStillLeft:
PORTB = %01100000
goto main

standStillRight:
PORTB = %10010000
goto main

Posted by cm1002 at 01:27 AM | Comments (0)

December 07, 2004

JUST LIGHT THE LED, DARN IT

just lights an LED

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : translaton of Christina Goodness BX Code, Carlyn Maw
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES

' ----------------------------------------------------- FAKEDATA

' ----------------------------------------------------- START MAIN

'startup sequence
HIGH PORTD.2
Pause 1000
LOW PORTD.2
Pause 1000
HIGH PORTD.2


main:


'get values


'debug sensor infomation
''for somereason this seems to lock up for a while
'SEROUT2 tx, inv9600, ["helllllloooooo", 13,10]

HIGH PORTD.3

goto main

Posted by cm1002 at 07:08 PM | Comments (0)

PIC with Transistors

Here's the code that works getting transistor readings on pins A 2, 3 and 5. The analog readings are set to A2, A3 and A4 because analog reading A4 actually maps to pin A5. Dont ask me why, because its not clear in the 18F452 datasheet. The range is 0 to 255, with a clear reading of around 3 at a direct beam of light at 3 feet. The closer it gets the higher the numbers are. I set the resistors to 220K because I got a basic reading of 0 with those resistors with florescent lights. And its only MORE sensistive with the lights off. So basically it will still work with the lights on, just not as sensistively. This basic transistor logic should be mapped into the motor code now.



'****************************************************************
'* Name : robot code *
'* Author : BeeBots Group
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)
getIR var WORD 'getIR is the IR reading
robotMotion var WORD 'normalized IR reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor


CLEAR 'CLEAR ALL AND ANY RANDOM BITS


' ----------------------------------------------------- START MAIN
'startup sequence
main:
HIGH PORTD.2
Pause 100
LOW PORTD.2

'get values IN PORT A
ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 2, leftTransistor 'GET THE TRANSISTOR READING on the right
ADCIN 3, centerTransistor 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 4, rightTransistor 'GET THE READING ON THE CENTER TRANSISTOR

robotMotion = ((1024 - getIR) / 8)


SEROUT2 tx, inv9600, ["rightTRANSISTOR IS ", dec rightTransistor, 13,10, "centerTRANSISTOR IS ", dec centerTransistor , 13,10, "lefttTRANSISTOR IS ", dec leftTransistor , 13,10]

pause 1000

'end sequence
HIGH PORTD.1
Pause 100
LOW PORTD.1

goto main

Posted by christina at 12:08 PM | Comments (0)

December 04, 2004

here's some code that works with beginings of flocking

hey gals, i actually just modified the code a very very small bit - carly you'll see some new variables and ways that direction is handled. but I actually just popped the h-bridge right on the existing circuit with your LEDs and switched the wires. It worked! e voila. I added 3 transistors to govern direction - right left and center, even though center doesnt seem to matter much, we might just use center to light a blinky? anyway, the code is below.

also - important note - i got rid of the Ultrasonics altogether since they were so problematic, just for simplicity. Perhaps once we get the transistors workign well, we can add the US back in. I just felt like it was holding us up and we are running out of time. Since the IR can basically do the basic avoidance behavior alone, why not just go with it and add the coherence factor already via transistors. Perhaps later we can isolate the US on their own circuit and just get them to work well on their own, THEN add them back in. Anyway, thats my vote. Good night.

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : translaton of Christina Goodness BX Code, Carlyn Maw
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading
readMotion2 var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading
rightTransistor VAR BYTE 'getLight is Transistor the on the right
leftTransistor VAR BYTE 'getleftlight is the tranistor on the left
centerTransistor VAR BYTE 'getcenterlight is the center transistor

' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence

main:
HIGH PORTD.2
Pause 100
LOW PORTD.2


'get values

ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1
ADCIN 1, lefttransistor 'GET THE TRANSISTOR READING on the right
ADCIN 2, centerTRANSISTOR 'GET THE TRANSISTOR READING ON THE LEFT
ADCIN 3, rightTRANSISTOR 'GET THE READING ON THE CENTER TRANSISTOR


'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

'readMotion2 = ((1024 - getSonic) / 8)

readMotion = ((1024 - getIR) / 8)

'translates the values to be 127 to 60
'from the range of 12 inches to 3 inches

'debug sensor infomation
'for somereason this seems to lock up for a while
SEROUT2 tx, inv9600, ["ir is ", dec readMotion, 13,10, "RIGHTLIGHT IS ", dec RIGHTTRANSISTOR, 13,10, "LEFTLIGHT IS ", dec LEFTTRANSISTOR, 13,10, "CENTERLIGHT IS ", dec CENTERTRANSISTOR, 13,10]

IF (READMOTION < 60) THEN RIGHTBACKWARD
IF (READMOTION >= 60 ) AND (READMOTION <= 70 ) THEN LEFTBACKWARD
IF (readMotion < basicSpeed) Then fullBackward
If (readMotion = basicSpeed) Then fullStop
If (readMotion > basicSpeed) Then fullForward
IF (righttransistor > 200) THEN rightbackward
IF (lefttransistor > 200) THEN leftbackward
IF (CENTERTRANSISTOR > 200) THEN FULLFORWARD

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html
pause 1000

goto main

fullForward:
PORTB = %01010000
goto main

fullBackward:
PORTB = %10100000
goto main

fullStop:
PORTB = %00000000
goto main

leftForward:
PORTB = %01000000
goto main

leftBackward:
PORTB = %10000000
goto main

rightForward:
PORTB = %00010000
goto main

rightBackward:
PORTB = %00100000
goto main

standStillLeft:
PORTB = %01100000
goto main

standStillRight:
PORTB = %10010000
goto main

Posted by christina at 10:48 PM | Comments (0)

FINALLY - PIC of BX

This should work identically to the BX code...

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : translaton of Christina Goodness BX Code, Carlyn Maw
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
basicSpeed con 100 ' used in IR detection
' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading


' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence
HIGH PORTD.2
Pause 1000
LOW PORTD.2
Pause 1000
HIGH PORTD.2


main:


'get values
ADCIN 0, GETSONIC ' get the ADC value from the UltraSonic on pin A0
ADCIN 1, getIR ' get the ADC value of Ultrasonic reading from pin A1

'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

readMotion = ((1024 - getIR) / 8)
'translates the values to be 127 to 60
'from the range of 12 inches to 3 inches

'debug sensor infomation
'for somereason this seems to lock up for a while
SEROUT2 tx, inv9600, ["readMotion ", dec readMotion, 13,10]


'if getSonic <= 200 then rightBackward
'if (400 > getSonic) AND (getSonic >= 355) then rightForward

If (getSonic >= 200 ) And ( getSonic < 300 ) Then rightForward
if (getSonic >= 300 ) And ( getSonic < 400 ) Then leftForward
IF (readMotion > basicSpeed) Then fullBackward
If (readMotion = basicSpeed) Then fullStop
If (readMotion < basicSpeed) Then fullForward

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html


goto main

fullForward:
PORTB = %01010000
goto main

fullBackward:
PORTB = %10100000
goto main

fullStop:
PORTB = %00000000
goto main

leftForward:
PORTB = %01000000
goto main

leftBackward:
PORTB = %10000000
goto main

rightForward:
PORTB = %00010000
goto main

rightBackward:
PORTB = %00100000
goto main

standStillLeft:
PORTB = %01100000
goto main

standStillRight:
PORTB = %10010000
goto main


Posted by cm1002 at 02:27 PM | Comments (0)

Friday Code

IR and ultrasonic being gathered, motor control syntax but no actuall logic. Couldn't get an ultrasonic to work, deal with that tomorrow

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : Carlyn Maw
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:

TRISB = %00000000
TRISD = %00000000

'serial
TRISC = %10000000
tx var portc.6 'out
rx var portc.7 ' in

'analog
' Define ADCIN parameters:
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify

' ----------------------------------------------------- CONSTANTS
'serial
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)

' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var WORD 'getIR is the IR reading
readMotion var WORD 'normalized IR reading

getSonic var WORD 'getSonic is the Ultrasonic reading


' ----------------------------------------------------- FAKEDATA

'getSonic = 375

' ----------------------------------------------------- START MAIN

'startup sequence
HIGH PORTD.2
Pause 1000
LOW PORTD.2
Pause 1000
HIGH PORTD.2


main:

'get values
ADCIN 0, GETSONIC ' get the ADC value from the UltraSonic on pin A0
ADCIN 1, getIR ' get the ADC value of Ultrasonic reading from pin A1

'IR goes from 5 ish (spikes up to 12ish)
' 3 inches white 480-520
' 6 inches white 360-380
' 12 inches white 190's
' 2 feet white 100's
' 3 feet white 70's

readMotion = ((1024 - getIR) / 8)
'translates the values to be 127 to 60
'from the range of 12 inches to 3 inches

SEROUT2 tx, inv9600, ["readMotion ", dec readMotion, 13,10]


'if getSonic <= 200 then rightBackward
'if (400 > getSonic) AND (getSonic >= 355) then rightForward

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html


goto main

fullForward:
PORTB = %01010000
Pause 5000
goto main

fullBackward:
PORTB = %10100000
Pause 5000
goto main

fullStop:
PORTB = %00000000
Pause 5000
goto main

leftForward:
PORTB = %01000000
Pause 5000
goto main

leftBackward:
PORTB = %10000000
Pause 5000
goto main

rightForward:
PORTB = %00010000
Pause 5000
goto main

rightBackward:
PORTB = %00100000
Pause 5000
goto main

standStillLeft:
PORTB = %01100000
Pause 5000
goto main

standStillRight:
PORTB = %10010000
Pause 5000
goto main

Posted by cm1002 at 01:07 AM | Comments (0)

December 03, 2004

Thursday Code - Motor Code, first if statement attempt

Acting funny. I hate if satements in PIC Basic

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : Carlyn Maw
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:
T
TRISB = %00000000
TRISD = %00000000
' ----------------------------------------------------- CONSTANTS

' ----------------------------------------------------- VARIABLES

'-- ir and ultrasonic vars (words or ints I'm not sure...)

getIR var BYTE 'getIR is the IR reading
readMotion var BYTE 'normalized IR reading

getSonic var BYTE 'getSonic is the Ultrasonic reading


' ----------------------------------------------------- FAKEDATA

' ----------------------------------------------------- START MAIN

'startup sequence
HIGH PORTD.2
Pause 1000
LOW PORTD.2
Pause 1000
HIGH PORTD.2


main:

'get values
'ADCIN 0, GETSONIC ' get the ADC value from the IR on pin A0
'ADCIN 1, getIR ' get the ADC value of Ultrasonic reading from pin A1
'readMotion = ((1024 - getIR) / 8)

If 300 > getSonic > 200 then leftBackward
if 400 > getSonic >= 300 Then leftForward
if getSonic < 200 then fullStop

'check out HPWM and todd's PWM code
'http://stage.itp.nyu.edu/~tvh204/code/simplepwm.html


goto main

fullForward:
PORTB = %01010000
Pause 5000
goto main

fullBackward:
PORTB = %10100000
Pause 5000
goto main

fullStop:
PORTB = %00000000
Pause 5000
goto main

leftForward:
PORTB = %01000000
Pause 5000
goto main

leftBackward:
PORTB = %10000000
Pause 5000
goto rightForward

rightForward:
PORTB = %00010000
Pause 5000
goto main

rightBackward:
PORTB = %00100000
Pause 5000
goto main

standStillLeft:
PORTB = %01100000
Pause 5000
goto main

standStillRight:
PORTB = %10010000
Pause 5000
goto main

Posted by cm1002 at 08:45 PM | Comments (0)

PIC Motor Code 1

Basic sampe code to get the two motors runnig. Used with LED testing board.

'****************************************************************
'* Name : robot_motorc.BAS *
'* Author : Carlyn Maw
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'set port b to output:
T
TRISB = %00000000
TRISD = %00000000
' ----------------------------------------------------- CONSTANTS

' ----------------------------------------------------- VARIABLES

' ----------------------------------------------------- FAKEDATA

' ----------------------------------------------------- START MAIN

HIGH PORTD.2
Pause 5000
LOW PORTD.2
Pause 5000
HIGH PORTD.2
main:

'fullForward
PORTB = %01010000
Pause 5000
'fullBackward
PORTB = %10100000
Pause 5000
'stop 3 3
PORTB = %00000000
Pause 5000
'leftForward
PORTB = %01000000
Pause 5000
'leftBackward
PORTB = %10000000
Pause 5000
'rightForward
PORTB = %00010000
Pause 5000
'rightBackward
PORTB = %00100000
Pause 5000
'standStillLeft
PORTB = %01100000
Pause 5000
'standStillRight
PORTB = %10010000
Pause 5000


goto main

Posted by cm1002 at 08:39 PM | Comments (0)

December 02, 2004

Aaack... I broke the template

I promise I'll fix it!

Posted by cm1002 at 04:45 PM | Comments (0)

Schematic - Round 1

Main Schematic

Power Schematic

Plus a useful little site for Photo sensors incase we need to modify the circuit...

http://www.marktechopto.com/engineering/photo_sensor.cfm

Posted by cm1002 at 03:36 AM | Comments (0)

Part Spec Short Cuts

item Part Number Link
PHOTO-TRANSISTOR Ledtech # LT9593-91-0125

http://www.ledtech.net/en/.... and ALOT more

http://www.ledtech.net/images/pdf/LT9593-91-0125.pdf

HEAVY-DUTY TO-220 HEATSINK

ANGLIA TV5

Farnell 170-072

http://www.angliac.com/aavid/product_range.asp?partnumber=TV5&Submit=Search&orderby=&results=#productrange

http://www.angliac.com/product_search/pg_page_finder/from_page_number.asp?cat_number=421

PIC Chip 18F452 http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1335&dDocName=en010296
Super Bright LEDs    
H-Bridge SN754410NE
TEXAS INSTRUMENTS

spec: http://www-s.ti.com/sc/psheets/slrs007b/slrs007b.pdf

product page: http://focus.ti.com/docs/prod/folders/print/sn754410.html

ULTRA SONIC MOVE DETECTOR Jameco #: 125090
MFG#:DK20(6020 KT)
http://www.jameco.com/wcsstore/Jameco/Products/ProdDS/125090.pdf
IR Detector Sharp GP2D12 Infrared detector, analog http://rocky.digikey.com/scripts/ProductInfo.dll?Site=US&V=425&M=GP2D12
MOTORS Two GM8 gear motors with wheels, runs at 5V from solarbotics http://www.solarbotics.com/products/index.php?scdfa-250100084-viewDetail-productzq349zq4categoryzq37=true

Posted by cm1002 at 01:42 AM | Comments (0)

December 01, 2004

PIC Transistor test code

Simple test code transistor ADC in, print to serial out

'****************************************************************
'* Name : transistor test *
'* Author : silly code by goodness *
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'needed for serin and serout

include "modedefs.bas"

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'SET PORT A TO INPUT
TRISA = %11111111
'SET PORT C TO OUTPUT
TRISC = %00000000
' ----------------------------------------------------- CONSTANTS

' ----------------------------------------------------- VARIABLES
getTrans VAR BYTE
' ----------------------------------------------------- START MAIN


main:

ADCIN 0, getTrans ' get the ADC value from the transistor on PortA.0 pin

serout2 portc.6, 16468, [DEC getTrans, 10, 13]

PAUSE 50


goto main


Posted by christina at 08:55 PM | Comments (2)

Stripped Down PIC code: Nov 24

Last working PIC code stripped down due to strange shifting behavior on the B Port pins. Take it away codefrau!

BeGoodNow
« PIC Test 2 - Dam Robot | Main
November 25, 2004
PIC Test 3 - goddam robot

'****************************************************************
'* Name : robot_code1.BAS *
'* Author : BX by C.Goodness, modified by Carlyn Maw and Christina Goodness *
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'needed for serin and serout
include "modedefs.bas"
DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'SET PORT A TO INPUT
TRISA = %11111111
'set port b and c to output:
TRISB = %00000000
TRISC = %00000000
' ----------------------------------------------------- CONSTANTS
'movement constant
basicSpeed con 100
' ----------------------------------------------------- VARIABLES
'-- ir and ultrasonic vars (words or ints I'm not sure...)
readMotion var BYTE 'FORMULA TO GET THE IR READINGS INTO NORMAL RANGE
getDistance var BYTE 'getDistance is the IR reading
getSonic var BYTE 'getSonic is the Ultrasonic reading
' ----------------------------------------------------- START MAIN


main:
'ADCIN 0, GETDISTANCE ' get the ADC value from the IR on pin A0
ADCIN 1, GETSONIC ' get the ADC value of Ultrasonic reading from pin A1
readMotion = ((1024 - getDistance) / 8)


serout2 portc.6, 16468, [DEC getSonic, 10, 13]
HIGH PORTB.0
LOW PORTB.1
HIGH PORTB.2
LOW PORTB.3
'serout2 portc.6, 16468, [DEC readMotion, 10, 13]
'pause 1000


'GOTO MOTORCONTROL
PAUSE 50


goto main


'-----------------------------------

MOTORCONTROL:


IF GETSONIC < 100 THEN
HIGH PORTB.0
LOW PORTB.1
ELSE
IF GETSONIC > 100 THEN
HIGH PORTB.1
LOW PORTB.0
ENDIF
ENDIF


IF READMOTION > 100 THEN
HIGH PORTB.2
LOW PORTB.3
ELSE
IF READMOTION < 100 THEN
HIGH PORTB.3
ENDIF
ENDIF


RETURN

Posted by christina at 08:42 PM | Comments (0)