« Baseline code | Main | Rockin kick ass begining of everything code »

December 08, 2004

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 December 8, 2004 01:28 AM

Comments

Post a comment




Remember Me?