« Thursday Code - Motor Code, first if statement attempt | Main | FINALLY - PIC of BX »

December 04, 2004

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 December 4, 2004 01:07 AM

Comments

Post a comment




Remember Me?