<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>RobotBuzz</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/" />
<modified>2004-12-18T21:22:16Z</modified>
<tagline></tagline>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3</id>
<generator url="http://www.movabletype.org/" version="3.11">Movable Type</generator>
<copyright>Copyright (c) 2004, cm1002</copyright>
<entry>
<title>Frozen Code</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/frozen_code.html" />
<modified>2004-12-18T21:22:16Z</modified>
<issued>2004-12-18T06:27:57Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.83</id>
<created>2004-12-18T06:27:57Z</created>
<summary type="text/plain">What we are assuming will work for the show...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>What we are assuming will work for the show<br />
</p>]]>
<![CDATA[<p>'****************************************************************<br />
'* Name : robot_motorc.BAS *<br />
'* Author : robotGroup<br />
'* Notice : Copyright (c) 2004 *<br />
'* : All Rights Reserved *<br />
'* Date : 4/16/2004 *<br />
'* Version : 1.0 *<br />
'* Notes : *<br />
'* : *<br />
'****************************************************************</p>

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in</p>

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

<p>TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify</p>

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

<p>lightThreshold con 100 'phototransistor threshold<br />
searchTimeOut con 30000 'how log does it look<br />
' ----------------------------------------------------- VARIABLES</p>

<p>'-- ir and ultrasonic vars</p>

<p>getIR var WORD 'getIR is the IR reading<br />
readMotion var WORD 'normalized IR reading<br />
readMotion2 var WORD 'normalized IR reading</p>

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

<p>lastRight var BYTE<br />
lastLeft var BYTE<br />
lastCenter var BYTE</p>

<p>'-- state flags<br />
leftLightVar var bit<br />
rightLightVar var bit<br />
centerLightVar var bit</p>

<p>lastRightFlag var bit<br />
lastLeftFlag var bit<br />
lastCenterFlag var bit</p>

<p>foundCenter var bit<br />
iFoundIt var bit<br />
iLostIt var bit</p>

<p><br />
'-- counters<br />
turnCounter var word<br />
turnCounter = 0</p>

<p><br />
' ----------------------------------------------------- FAKEDATA</p>

<p>'getSonic = 375</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence</p>

<p><br />
main:<br />
HIGH PORTD.2<br />
Pause 100<br />
LOW PORTD.2</p>

<p><br />
'get values</p>

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

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

<p>'debug sensor infomation<br />
'for somereason this seems to lock up for a while<br />
'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]</p>

<p>If (getIR > 400) Then fullBackward</p>

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

<p>IF (lefttransistor > lightThreshold) THEN<br />
leftLightVar = 1<br />
else<br />
leftLightVar = 0<br />
endIF</p>

<p>IF (righttransistor > lightThreshold) THEN<br />
rightLightVar = 1<br />
else<br />
rightLightVar = 0<br />
endIF</p>

<p><br />
IF (centerLightVar == 1) THEN centerT<br />
if (leftLightVar == 1) and (rightLightVar == 1) then compareSides<br />
if (leftLightVar == 1) then leftT<br />
if (rightLightVar == 1) then rightT</p>

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

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

<p>goto main</p>

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

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

<p>rightT:<br />
'rc4<br />
HIGH PORTD.3<br />
gosub searchingRight<br />
LOW PORTD.3<br />
lastRight = centerTransistor<br />
lastRightFlag = 1<br />
goto main</p>

<p>leftT:<br />
'rd3<br />
HIGH PORTC.5<br />
gosub searchingLeft<br />
LOW PORTC.5<br />
lastLeft = centerTransistor<br />
lastLeftFlag = 1<br />
goto main</p>

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

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

<p>fullForward:<br />
PORTB = %01010000<br />
goto main</p>

<p>fullBackward:<br />
PORTB = %10100000<br />
goto main</p>

<p>fullStop:<br />
PORTB = %00000000<br />
goto main</p>

<p>leftForward:<br />
PORTB = %01000000<br />
goto main</p>

<p>leftBackward:<br />
PORTB = %10000000<br />
goto main</p>

<p>rightForward:<br />
PORTB = %00010000<br />
goto main</p>

<p>rightBackward:<br />
PORTB = %00100000<br />
goto main</p>

<p>standStillLeft:<br />
PORTB = %01100000<br />
pause 700<br />
goto main</p>

<p>standStillRight:<br />
PORTB = %10010000<br />
pause 500<br />
goto main<br />
</p>]]>
</content>
</entry>
<entry>
<title>Things to do (no order)</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/things_to_do_no.html" />
<modified>2004-12-18T06:27:03Z</modified>
<issued>2004-12-18T05:49:03Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.82</id>
<created>2004-12-18T05:49:03Z</created>
<summary type="text/plain">One of my famous lists...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Meeting Notes</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>One of my famous lists</p>]]>
<![CDATA[<p>Physical / Power<br />
? Make Wings<br />
Add a power button (at center of wing joint)<br />
charge & deplete the batteries <br />
wire leads on the ends of the power caps<br />
figure out how the new battery packs are going to fit on the bees<br />
to corral or not to corral</p>

<p>Code<br />
Get the latest copy of the code on all the chips<br />
Tune the constants <br />
more the IR to dominant?</p>

<p>do we want it to wiggle?</p>

<p>Phototransistor Hell<br />
turn eyes out<br />
add caps<br />
bring a flash light<br />
make a "superbright flashlight" so we know what we are dealing with from that.<br />
do the phototransistors need a cup?<br />
wire a board with serial so can watch the values again<br />
more light from the tails? (more LED, tin collar?)<br />
- put solution on other bees<br />
</p>]]>
</content>
</entry>
<entry>
<title>searchingRight</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/searchingright.html" />
<modified>2004-12-18T05:28:42Z</modified>
<issued>2004-12-17T20:47:27Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.81</id>
<created>2004-12-17T20:47:27Z</created>
<summary type="text/plain">Things tried troubleshooting a WHILE statement or &quot;Seven steps to realize how stupid you can be.&quot;...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>Things tried troubleshooting a <strong>WHILE</strong> statement or "Seven steps to realize how stupid you can be."</p>]]>
<![CDATA[<p><strong>Option 7 - final, for now</strong><br />
<em>Lesson learned: a counter moves wicked faster than pulse count. Some stupid tax on this one.</em></p>

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

<p><strong>Option 6</strong><br />
<em>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</em><br />
'-- counters<br />
turnCounter var word<br />
turnCounter = 0</p>

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

<p><strong>Option 5</strong><br />
<em>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... </em><br />
'-- counters<br />
turnCounter var word<br />
turnCounter = 3001</p>

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

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

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

<p><strong>Option 3</strong><br />
<em>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...</em><br />
searchingRight:<br />
while (iFoundIt = 0)<br />
ADCIN 3, centerTRANSISTOR<br />
'left wheel forward to turn right<br />
PORTB = %01000000<br />
turnCounter = turnCounter + 1<br />
if  (centerTransistor < 75) AND (turnCounter < 3000) then<br />
    iFoundIt = 0<br />
else<br />
    iFoundIt = 1 <br />
endif <br />
wend<br />
turnCounter = 0<br />
iFoundIt = 0<br />
return</p>

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

<p><strong>Option 1</strong><br />
<em>works like a charm, stays turning until the flashlight shines on the middle phototransitor.</em><br />
searchingRight:<br />
while centerTransistor < 75<br />
ADCIN 3, centerTransistor<br />
'right wheel forward to turn left<br />
PORTB = %00010000<br />
wend<br />
return</p>]]>
</content>
</entry>
<entry>
<title>flocking continued 12_16_04</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/flocking_contin.html" />
<modified>2004-12-17T05:44:13Z</modified>
<issued>2004-12-16T23:27:29Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.80</id>
<created>2004-12-16T23:27:29Z</created>
<summary type="text/plain">(room transfer)...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>(room transfer)</p>]]>
<![CDATA[<p>'****************************************************************<br />
'* Name : robot_motorc.BAS *<br />
'* Author : robotGroup<br />
'* Notice : Copyright (c) 2004 *<br />
'* : All Rights Reserved *<br />
'* Date : 4/16/2004 *<br />
'* Version : 1.0 *<br />
'* Notes : *<br />
'* : *<br />
'****************************************************************</p>

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in </p>

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

<p>TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify</p>

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

<p>lightThreshold con 100 'phototransistor threshold<br />
' ----------------------------------------------------- VARIABLES</p>

<p>'-- ir and ultrasonic vars</p>

<p>getIR       var WORD 'getIR is the IR reading<br />
readMotion  var WORD 'normalized IR reading<br />
readMotion2 var WORD 'normalized IR reading</p>

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

<p>lastRight   var  BYTE<br />
lastLeft    var  BYTE<br />
lastCenter  var  BYTE</p>

<p>'-- state flags<br />
leftLightVar    var bit<br />
rightLightVar   var bit<br />
centerLightVar  var bit</p>

<p>lastRightFlag   var  bit<br />
lastLeftFlag    var  bit<br />
lastCenterFlag  var  bit</p>

<p>foundCenter     var bit<br />
iLostIt         var bit</p>

<p><br />
'-- counters<br />
turnCounter     var word</p>

<p></p>

<p><br />
' ----------------------------------------------------- FAKEDATA</p>

<p>'getSonic = 375</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence</p>

<p><br />
main:<br />
HIGH PORTD.2<br />
Pause 100<br />
LOW PORTD.2</p>

<p><br />
'get values</p>

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

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

<p>'debug sensor infomation<br />
'for somereason this seems to lock up for a while<br />
'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]</p>

<p></p>

<p>If (getIR > 400) Then fullBackward</p>

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

<p>IF (lefttransistor > lightThreshold) THEN <br />
    leftLightVar = 1<br />
else <br />
    leftLightVar = 0<br />
endIF</p>

<p>IF (righttransistor > lightThreshold) THEN <br />
    rightLightVar = 1<br />
else <br />
    rightLightVar = 0<br />
endIF</p>

<p><br />
IF (centerLightVar == 1) THEN centerT<br />
if (leftLightVar == 1) and (rightLightVar == 1) then compareSides<br />
if (leftLightVar == 1) then leftT<br />
if (rightLightVar == 1) then rightT</p>

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

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

<p>goto main</p>

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

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

<p>rightT:<br />
'rc4<br />
HIGH PORTD.3<br />
gosub searchingRight<br />
LOW PORTD.3<br />
lastRight = centerTransistor<br />
lastRightFlag = 1<br />
goto main</p>

<p>leftT:<br />
'rd3<br />
HIGH PORTC.5<br />
gosub searchingRight<br />
LOW PORTC.5<br />
lastLeft = centerTransistor<br />
lastLeftFlag = 1<br />
goto main</p>

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

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

<p>fullForward: <br />
PORTB = %01010000<br />
goto main</p>

<p>fullBackward: <br />
PORTB = %10100000<br />
goto main</p>

<p>fullStop: <br />
PORTB = %00000000<br />
goto main</p>

<p>leftForward: <br />
PORTB = %01000000<br />
goto main</p>

<p>leftBackward: <br />
PORTB = %10000000<br />
goto main</p>

<p>rightForward: <br />
PORTB = %00010000<br />
goto main</p>

<p>rightBackward: <br />
PORTB = %00100000<br />
goto main</p>

<p>standStillLeft: <br />
PORTB = %01100000<br />
pause 700<br />
goto main</p>

<p>standStillRight:<br />
PORTB = %10010000<br />
pause 500<br />
goto main</p>]]>
</content>
</entry>
<entry>
<title>psudo code for better flocking pre-alpha</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/psudo_code_for.html" />
<modified>2004-12-16T22:31:51Z</modified>
<issued>2004-12-16T22:31:07Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.79</id>
<created>2004-12-16T22:31:07Z</created>
<summary type="text/plain">some jibber jabber to get me thinking...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>some jibber jabber to get me thinking</p>]]>
<![CDATA[<p>if there is a light on left<br />
	set leftPhotolightVar = true<br />
end it</p>

<p>if there is a light on right<br />
	set rightPhotolightVar = true<br />
end it</p>

<p>if there is a light on center<br />
	set centerPhotolightVar = true<br />
end it</p>

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

<p>if foundCenter = true<br />
	go forward<br />
	lastFoundCenter = true<br />
else<br />
	if lasfFoundcenter = true<br />
		iLostit = true<br />
	endif<br />
endif</p>

<p>if iLostit<br />
	sine and cos the motors? look and then just move around<br />
endif</p>

<p>ir behavior routine here</p>]]>
</content>
</entry>
<entry>
<title>Schematic - Round 2 (Class Final)</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/schematic_round_1.html" />
<modified>2004-12-09T00:10:18Z</modified>
<issued>2004-12-09T00:07:38Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.78</id>
<created>2004-12-09T00:07:38Z</created>
<summary type="text/plain">Main Schematic Power Schematic...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Schematics</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>Main Schematic</p>
<img src="/~cm1002/Fall04_advtech/robotBuzz/skematic5.gif" width="800" height="600">
<p>Power Schematic</p>
<img src="/~cm1002/Fall04_advtech/robotBuzz/power_schm.gif" width="410" height="300">]]>

</content>
</entry>
<entry>
<title>The final parts list</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/the_final_parts.html" />
<modified>2004-12-16T22:44:16Z</modified>
<issued>2004-12-08T23:03:28Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.77</id>
<created>2004-12-08T23:03:28Z</created>
<summary type="text/plain">Parts as listed on the schematic...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Parts</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>Parts as listed on the schematic</p>]]>
<![CDATA[<p><strong>Basic Microcontroller Setup</strong><br />
1	PIC chip: Microchip: 18F452<br />
1	10 k? resisitor (pull up reset pin)<br />
1	4 Mhz clock: SparkFun: Comp-XTAL, HC49/UA Package<br />
2	22 pF capacitor (for clock)<br />
1	1 k? resistor (for system check LED)<br />
1	regular LED (system check LED)</p>

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

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

<p><strong>Sensors </strong><br />
1	IR detector: Sharp: GP2D12<br />
3	phototransistor: Ledtech: LT9593-91-0125<br />
3	22 k? resisitor: <br />
0	ultra-sonic movement detector:  Jameco: 125090 , MFG#:DK20(6020 KT)<br />
1	Super Bright LEDs: Sparkfun:Comp-SBL <br />
3	1 k? resisitors (for phototransistor status lights) <br />
3	yellow LEDs (phototransistor status lights)<br />
3	0.001 µF capacitors (future: to even out signal)</p>]]>
</content>
</entry>
<entry>
<title>The final code</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/the_final_code.html" />
<modified>2004-12-08T22:58:35Z</modified>
<issued>2004-12-08T22:54:03Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.76</id>
<created>2004-12-08T22:54:03Z</created>
<summary type="text/plain">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...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>for class anyway:</p>

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

<p>- 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)<br />
- remember for the pic, 25 miliamps/pin max over a 3 pin max<br />
- 1000 ohm normal LED -  220 superb</p>]]>
<![CDATA[<p>'****************************************************************<br />
'* Name : robot_motorc.BAS *<br />
'* Author : robotGroup<br />
'* Notice : Copyright (c) 2004 *<br />
'* : All Rights Reserved *<br />
'* Date : 4/16/2004 *<br />
'* Version : 1.0 *<br />
'* Notes : *<br />
'* : *<br />
'****************************************************************</p>

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in </p>

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

<p>TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify</p>

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

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

<p>getIR       var WORD    'getIR is the IR reading<br />
readMotion  var WORD    'normalized IR reading<br />
readMotion2 var WORD    'normalized IR reading</p>

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

<p></p>

<p>' ----------------------------------------------------- FAKEDATA</p>

<p>'getSonic = 375</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence</p>

<p><br />
main:<br />
HIGH PORTD.2<br />
Pause 100<br />
LOW PORTD.2</p>

<p><br />
'get values</p>

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

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

<p>'debug sensor infomation<br />
'for somereason this seems to lock up for a while<br />
'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]</p>

<p></p>

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

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

<p>goto main</p>

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

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

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

<p>fullForward: <br />
PORTB = %01010000<br />
goto main</p>

<p>fullBackward: <br />
PORTB = %10100000<br />
goto main</p>

<p>fullStop: <br />
PORTB = %00000000<br />
goto main</p>

<p>leftForward: <br />
PORTB = %01000000<br />
goto main</p>

<p>leftBackward: <br />
PORTB = %10000000<br />
goto main</p>

<p>rightForward: <br />
PORTB = %00010000<br />
goto main</p>

<p>rightBackward: <br />
PORTB = %00100000<br />
goto main<br />
                       <br />
standStillLeft: <br />
PORTB = %01100000<br />
pause 700<br />
goto main</p>

<p>standStillRight:<br />
PORTB = %10010000<br />
pause 500<br />
goto main</p>]]>
</content>
</entry>
<entry>
<title>Rockin kick ass begining of everything code</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/rockin_kick_ass.html" />
<modified>2004-12-08T16:50:12Z</modified>
<issued>2004-12-08T16:48:46Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.75</id>
<created>2004-12-08T16:48:46Z</created>
<summary type="text/plain">This moves. This avoid things. This goes towards the light....</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>This <strong>moves</strong>. This <strong>avoid things</strong>. This goes <strong>towards the light</strong>.</p>]]>
<![CDATA[<p>'****************************************************************<br />
'* Name : robot_motorc.BAS *<br />
'* Author : robotGroup<br />
'* Notice : Copyright (c) 2004 *<br />
'* : All Rights Reserved *<br />
'* Date : 4/16/2004 *<br />
'* Version : 1.0 *<br />
'* Notes : *<br />
'* : *<br />
'****************************************************************</p>

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in </p>

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

<p>TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify</p>

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

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

<p>getIR       var WORD    'getIR is the IR reading<br />
readMotion  var WORD    'normalized IR reading<br />
readMotion2 var WORD    'normalized IR reading</p>

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

<p></p>

<p>' ----------------------------------------------------- FAKEDATA</p>

<p>'getSonic = 375</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence</p>

<p><br />
main:<br />
HIGH PORTD.2<br />
Pause 100<br />
LOW PORTD.2</p>

<p><br />
'get values</p>

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

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

<p>'readMotion2 = ((1024 - getSonic) / 8)</p>

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

<p>'debug sensor infomation<br />
'for somereason this seems to lock up for a while<br />
'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]</p>

<p></p>

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

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

<p>goto main</p>

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

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

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

<p>fullForward: <br />
PORTB = %01010000<br />
goto main</p>

<p>fullBackward: <br />
PORTB = %10100000<br />
goto main</p>

<p>fullStop: <br />
PORTB = %00000000<br />
goto main</p>

<p>leftForward: <br />
PORTB = %01000000<br />
goto main</p>

<p>leftBackward: <br />
PORTB = %10000000<br />
goto main</p>

<p>rightForward: <br />
PORTB = %00010000<br />
goto main</p>

<p>rightBackward: <br />
PORTB = %00100000<br />
goto main<br />
                       <br />
standStillLeft: <br />
PORTB = %01100000<br />
pause 700<br />
goto main</p>

<p>standStillRight:<br />
PORTB = %10010000<br />
pause 500<br />
goto main</p>]]>
</content>
</entry>
<entry>
<title>No more read motion</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/no_more_read_mo.html" />
<modified>2004-12-08T06:30:05Z</modified>
<issued>2004-12-08T06:28:50Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.74</id>
<created>2004-12-08T06:28:50Z</created>
<summary type="text/plain">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&apos;t linear......</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>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...</p>]]>
<![CDATA[<p>'****************************************************************<br />
'* Name : robot_motorc.BAS *<br />
'* Author : robotGroup<br />
'* Notice : Copyright (c) 2004 *<br />
'* : All Rights Reserved *<br />
'* Date : 4/16/2004 *<br />
'* Version : 1.0 *<br />
'* Notes : *<br />
'* : *<br />
'****************************************************************</p>

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in </p>

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

<p>TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify</p>

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

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

<p>getIR       var WORD    'getIR is the IR reading<br />
readMotion  var WORD    'normalized IR reading<br />
readMotion2 var WORD    'normalized IR reading</p>

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

<p></p>

<p>' ----------------------------------------------------- FAKEDATA</p>

<p>'getSonic = 375</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence</p>

<p></p>

<p>main:<br />
HIGH PORTD.2<br />
Pause 100<br />
LOW PORTD.2</p>

<p><br />
'get values</p>

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

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

<p>'readMotion2 = ((1024 - getSonic) / 8)</p>

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

<p>'debug sensor infomation<br />
'for somereason this seems to lock up for a while<br />
'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]</p>

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

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

<p>goto main</p>

<p>fullForward: <br />
PORTB = %01010000<br />
goto main</p>

<p>fullBackward: <br />
PORTB = %10100000<br />
goto main</p>

<p>fullStop: <br />
PORTB = %00000000<br />
goto main</p>

<p>leftForward: <br />
PORTB = %01000000<br />
goto main</p>

<p>leftBackward: <br />
PORTB = %10000000<br />
goto main</p>

<p>rightForward: <br />
PORTB = %00010000<br />
goto main</p>

<p>rightBackward: <br />
PORTB = %00100000<br />
goto main<br />
                       <br />
standStillLeft: <br />
PORTB = %01100000<br />
pause 700<br />
goto main</p>

<p>standStillRight:<br />
PORTB = %10010000<br />
pause 500<br />
goto main</p>]]>
</content>
</entry>
<entry>
<title>Baseline code</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/baseline_code.html" />
<modified>2004-12-08T06:32:30Z</modified>
<issued>2004-12-08T06:27:10Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.73</id>
<created>2004-12-08T06:27:10Z</created>
<summary type="text/plain">This is the code that sorta works kinda...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>This is the code that sorta works kinda</p>]]>
<![CDATA[<p>'****************************************************************<br />
'* Name : robot_motorc.BAS *<br />
'* Author : robotGroup<br />
'* Notice : Copyright (c) 2004 *<br />
'* : All Rights Reserved *<br />
'* Date : 4/16/2004 *<br />
'* Version : 1.0 *<br />
'* Notes : *<br />
'* : *<br />
'****************************************************************</p>

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in </p>

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

<p>TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify</p>

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

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

<p>getIR       var WORD    'getIR is the IR reading<br />
readMotion  var WORD    'normalized IR reading<br />
readMotion2 var WORD    'normalized IR reading</p>

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

<p></p>

<p>' ----------------------------------------------------- FAKEDATA</p>

<p>'getSonic = 375</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence</p>

<p></p>

<p>main:<br />
HIGH PORTD.2<br />
Pause 100<br />
LOW PORTD.2</p>

<p><br />
'get values</p>

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

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

<p>'readMotion2 = ((1024 - getSonic) / 8)</p>

<p>readMotion = ((1024 - getIR) / 8)</p>

<p>'translates the values to be 127 to 60 <br />
'from the range of 12 inches to 3 inches</p>

<p>'debug sensor infomation<br />
'for somereason this seems to lock up for a while<br />
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]</p>

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

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

<p>goto main</p>

<p>fullForward: <br />
PORTB = %01010000<br />
goto main</p>

<p>fullBackward: <br />
PORTB = %10100000<br />
goto main</p>

<p>fullStop: <br />
PORTB = %00000000<br />
goto main</p>

<p>leftForward: <br />
PORTB = %01000000<br />
goto main</p>

<p>leftBackward: <br />
PORTB = %10000000<br />
goto main</p>

<p>rightForward: <br />
PORTB = %00010000<br />
goto main</p>

<p>rightBackward: <br />
PORTB = %00100000<br />
goto main<br />
                       <br />
standStillLeft: <br />
PORTB = %01100000<br />
goto main</p>

<p>standStillRight:<br />
PORTB = %10010000<br />
goto main</p>]]>
</content>
</entry>
<entry>
<title>JUST LIGHT THE LED, DARN IT</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/just_light_the.html" />
<modified>2004-12-08T00:09:50Z</modified>
<issued>2004-12-08T00:08:56Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.72</id>
<created>2004-12-08T00:08:56Z</created>
<summary type="text/plain">just lights an LED...</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>just lights an LED</p>]]>
<![CDATA[<p>'****************************************************************<br />
'* Name : robot_motorc.BAS *<br />
'* Author : translaton of Christina Goodness BX Code, Carlyn Maw<br />
'* Notice : Copyright (c) 2004 *<br />
'* : All Rights Reserved *<br />
'* Date : 4/16/2004 *<br />
'* Version : 1.0 *<br />
'* Notes : *<br />
'* : *<br />
'****************************************************************</p>

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in </p>

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

<p>' ----------------------------------------------------- FAKEDATA</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence<br />
HIGH PORTD.2<br />
Pause 1000<br />
LOW PORTD.2<br />
Pause 1000<br />
HIGH PORTD.2</p>

<p><br />
main:</p>

<p><br />
'get values</p>

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

<p>HIGH PORTD.3</p>

<p>goto main<br />
</p>]]>
</content>
</entry>
<entry>
<title>PIC with Transistors</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/pic_with_transi.html" />
<modified>2004-12-07T17:15:32Z</modified>
<issued>2004-12-07T17:08:16Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.71</id>
<created>2004-12-07T17:08:16Z</created>
<summary type="text/plain">Here&apos;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...</summary>
<author>
<name>christina</name>

<email>goodness@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>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.</p>]]>
<![CDATA[<pre>

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

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in</p>

<p>'analog<br />
' Define ADCIN parameters:<br />
DEFINE ADC_BITS 10 ' Set number of bits in result<br />
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)<br />
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS<br />
 <br />
TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify<br />
 <br />
' ----------------------------------------------------- CONSTANTS<br />
'serial<br />
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)<br />
basicSpeed con 100 ' used in IR detection<br />
' ----------------------------------------------------- VARIABLES</p>

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

<p><br />
CLEAR 'CLEAR ALL AND ANY RANDOM BITS</p>

<p><br />
' ----------------------------------------------------- START MAIN<br />
 'startup sequence<br />
main:<br />
HIGH PORTD.2<br />
Pause 100<br />
LOW PORTD.2</p>

<p>'get values IN PORT A<br />
ADCIN 0, getIR ' get the ADC value of Ultrasonic reading from pin A1<br />
ADCIN 2, leftTransistor 'GET THE TRANSISTOR READING on the right<br />
ADCIN 3, centerTransistor 'GET THE TRANSISTOR READING ON THE LEFT<br />
ADCIN 4, rightTransistor 'GET THE READING ON THE CENTER TRANSISTOR<br />
 <br />
robotMotion = ((1024 - getIR) / 8)</p>

<p><br />
SEROUT2 tx, inv9600, ["rightTRANSISTOR IS ", dec rightTransistor, 13,10, "centerTRANSISTOR IS ", dec centerTransistor , 13,10, "lefttTRANSISTOR IS ", dec leftTransistor , 13,10]</p>

<p>pause 1000</p>

<p>'end sequence<br />
HIGH PORTD.1<br />
Pause 100<br />
LOW PORTD.1</p>

<p>goto main<br />
</pre></p>]]>
</content>
</entry>
<entry>
<title>here&apos;s some code that works with beginings of flocking</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/heres_some_code.html" />
<modified>2004-12-07T19:30:34Z</modified>
<issued>2004-12-05T03:48:52Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.70</id>
<created>2004-12-05T03:48:52Z</created>
<summary type="text/plain">hey gals, i actually just modified the code a very very small bit - carly you&apos;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...</summary>
<author>
<name>christina</name>

<email>goodness@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>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.</p>

<p>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.</p>]]>
<![CDATA[<pre>
'****************************************************************
'* 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 : *
'* : *
'****************************************************************

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in </p>

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

<p>TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify</p>

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

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

<p>getIR       var WORD    'getIR is the IR reading<br />
readMotion  var WORD    'normalized IR reading<br />
readMotion2 var WORD    'normalized IR reading</p>

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

<p></p>

<p>' ----------------------------------------------------- FAKEDATA</p>

<p>'getSonic = 375</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence</p>

<p></p>

<p>main:<br />
HIGH PORTD.2<br />
Pause 100<br />
LOW PORTD.2</p>

<p><br />
'get values</p>

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

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

<p>'readMotion2 = ((1024 - getSonic) / 8)</p>

<p>readMotion = ((1024 - getIR) / 8)</p>

<p>'translates the values to be 127 to 60 <br />
'from the range of 12 inches to 3 inches</p>

<p>'debug sensor infomation<br />
'for somereason this seems to lock up for a while<br />
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]</p>

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

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

<p>goto main</p>

<p>fullForward: <br />
PORTB = %01010000<br />
goto main</p>

<p>fullBackward: <br />
PORTB = %10100000<br />
goto main</p>

<p>fullStop: <br />
PORTB = %00000000<br />
goto main</p>

<p>leftForward: <br />
PORTB = %01000000<br />
goto main</p>

<p>leftBackward: <br />
PORTB = %10000000<br />
goto main</p>

<p>rightForward: <br />
PORTB = %00010000<br />
goto main</p>

<p>rightBackward: <br />
PORTB = %00100000<br />
goto main<br />
                       <br />
standStillLeft: <br />
PORTB = %01100000<br />
goto main</p>

<p>standStillRight:<br />
PORTB = %10010000<br />
goto main</p>

<p></p>

</pre>]]>
</content>
</entry>
<entry>
<title>FINALLY - PIC of BX</title>
<link rel="alternate" type="text/html" href="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/archives/2004/12/finally_pic_of.html" />
<modified>2004-12-04T22:00:21Z</modified>
<issued>2004-12-04T19:27:21Z</issued>
<id>tag:stage.itp.tsoa.nyu.edu,2004:/~cm1002/robotBuzz/3.68</id>
<created>2004-12-04T19:27:21Z</created>
<summary type="text/plain">This should work identically to the BX code......</summary>
<author>
<name>cm1002</name>

<email>cm1002@nyu.edu</email>
</author>
<dc:subject>Code</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://stage.itp.tsoa.nyu.edu/~cm1002/robotBuzz/">
<![CDATA[<p>This <em>should</em> work identically to the BX code...<br />
</p>]]>
<![CDATA[<p>'****************************************************************<br />
'* Name : robot_motorc.BAS *<br />
'* Author : translaton of Christina Goodness BX Code, Carlyn Maw<br />
'* Notice : Copyright (c) 2004 *<br />
'* : All Rights Reserved *<br />
'* Date : 4/16/2004 *<br />
'* Version : 1.0 *<br />
'* Notes : *<br />
'* : *<br />
'****************************************************************</p>

<p>DEFINE OSC 4<br />
' ----------------------------------------------------- PORT SET-UP<br />
'set port b to output:</p>

<p>TRISB = %00000000<br />
TRISD = %00000000</p>

<p>'serial<br />
TRISC = %10000000<br />
tx var portc.6 'out<br />
rx var portc.7 ' in </p>

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

<p>TRISA = %11111111 ' Set PORTA to all input<br />
ADCON1 = %10000010 ' Set PORTA analog and right justify</p>

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

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

<p>getIR var WORD 'getIR is the IR reading<br />
readMotion var WORD 'normalized IR reading</p>

<p>getSonic var WORD 'getSonic is the Ultrasonic reading</p>

<p><br />
' ----------------------------------------------------- FAKEDATA</p>

<p>'getSonic = 375</p>

<p>' ----------------------------------------------------- START MAIN</p>

<p>'startup sequence<br />
HIGH PORTD.2<br />
Pause 1000<br />
LOW PORTD.2<br />
Pause 1000<br />
HIGH PORTD.2</p>

<p><br />
main:</p>

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

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

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

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

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

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

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

<p><br />
goto main</p>

<p>fullForward: <br />
PORTB = %01010000<br />
goto main</p>

<p>fullBackward: <br />
PORTB = %10100000<br />
goto main</p>

<p>fullStop: <br />
PORTB = %00000000<br />
goto main</p>

<p>leftForward: <br />
PORTB = %01000000<br />
goto main</p>

<p>leftBackward: <br />
PORTB = %10000000<br />
goto main</p>

<p>rightForward: <br />
PORTB = %00010000<br />
goto main</p>

<p>rightBackward: <br />
PORTB = %00100000<br />
goto main</p>

<p>standStillLeft: <br />
PORTB = %01100000<br />
goto main</p>

<p>standStillRight:<br />
PORTB = %10010000<br />
goto main</p>

<p><br />
</p>]]>
</content>
</entry>

</feed>
