« Links for parts and other stuff | Main | Initial Parts Order »

November 12, 2004

The begining of a PIC translation

some code notes - in process.... sorry!

'****************************************************************
'* Name : robot_code1.BAS *
'* Author : BX by C.Goodness, modified by Carlyn Maw *
'* 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

'Ports needed
' 2 ADC in, serial communication, 4 pins for the motors
' hardware serial?

' ----------------------------------------------------- PORT SET-UP

' Ports needed
' 2 ADC in, serial communication, 4 pins for the motors
' hardware serial?

'so.. for example
'set pins RC0-RC3 to input:
TRISC = %00001111
'set pins RB0-RB3 to output:
TRISB = %00000000


' --- Serial Port set up

'this is one way to set up for serial communication
'set pin porta.1 as rx and clear values:
TRISA = %10000010
PORTA = 0

'use PORTA for the serial port/cobox communication
tx var portc.6 'out
rx var portc.7 ' in

'old BX code to do it
gosub defineCom3(5, 6, bx1000_1000)
' set aside memory for input and output:
gosub openQueue(inputBuffer, 13)
gosub openQueue(outputBuffer, 50)

' ----------------------------------------------------- CONSTANTS

'movement constant
basicSpeed con 100

' -- serial information
inv9600 con 16468 ' baudmode (9600 8-N-1 inverted)
true9600 con 84

' ----------------------------------------------------- VARIABLES
'serial var, also not sure of size...
inputBuffer var byte '4-byte output buffer.
outputBuffer var byte '1-byte output buffer.

' -- ir and ultrasonic vars (words or ints I'm not sure...)
readMotion var word
getDistance var word 'getDistance is the IR reading
getSonic var word 'getSonic is the Ultrasonic reading

' ----------------------------------------------------- GENERAL COUNTERS
' varialbles for for loops, etc
x var byte
' ----------------------------------------------------- DUMMY DATA
' i make tis section for faking input data to isolate what I am
' checking in code, so for example fo fake what the ir data is

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


main: 'this is pseudo code to get values from sensors

' this is the BX code, never done ADC in PIC
getDistance = adcin 0, sensorValue getADC(15) ' get the ADC value from the IR
getSonic = adcin 0, sensorValue getADC(10) ' get the ADC value of Ultrasonic reading from pin 10
'set the basic speed to full stop on both motors

this would all be serout? (debug statements)
'call putQueueStr(outputBuffer, cstr(readMotion)
'print out value being read on pin 13/ultrasonic

readMotion = ((1024 - getDistance) \ 8)
Debug.Print "Distance reading: "; CStr(readMotion)
Debug.Print "Sonic reading:"; CStr(getSonic)

'around three inches, it bottoms out at 65, then numbers start going up again
'between zero and three inches
'it ranges from 63 to 110
'above three inches it ranges from 63 to 127

'---------- my serout code from a different program
'------------------------------------------------------- SEND DATA

'' serout2 tx, inv9600, [parkName]
'sendVAR = ~switchVAR
sendArray[0] = 104
sendArray[1] = switchVAR & %11111111
sendArray[2] = switchVAR >> 8
for x = 0 to 2
serout2 tx, inv9600, [sendArray(x)]
next

'-------------------------------------------------------- GET DATA


serin2 RX, inv9600, 100, nodata, [wait("h"), str recieveArray\2]
remoteVAR = recieveArray(1) << 8
remoteVAR = recieveArray(0) | remoteVAR
' --- end of my serin/serout example



'okay, so if I was writing this I would just set the port values here? why didn't she? (Using portB b/c port C has the serial stuff on it) The PWM stuff might be harder this way if the wheels need to move a different speeds... but
'0000 = you have 4 bits here
'0101 = both motors going forward
'1010 = both motors going backwards
'0000 = both motors stopped, etc.

so the same table as below would be
'Name lDirection rDirection
'direction old new
'leftForward 1 3 PORTB = %00000100
'leftBackward 2 3 PORTB = %00001000
'rightForward 3 1 PORTB = %00000001
'rightBackward 3 2 PORTB = %0010
'standStillLeft 1 2 PORTB = %0110
'standStillRight2 1 PORTB = %00001001
'stop 3 3 PORTC = %00000000
'fullForward 1 1 PORTB = %00000101
'fullBackward 2 2 PORTB = %00001010

'what is the 1-100 business for? just a counter to make it move?

'not sure how to do the
if ( getSonic > = 200 ) && ( getSonic < 300 ) then
PORTB = %00000001
ElseIf ( getSonic > = 300 ) And ( getSonic < 400 ) Then
PORTB = %00000100

ElseIf (readMotion > basicSpeed) Then
'
ElseIf( readMotion = basicSpeed) Then
'
ElseIf(readMotion < basicSpeed) Then
'

' END OF MAIN PROGRAM
goto main

Posted by cm1002 at November 12, 2004 05:43 PM

Comments

Post a comment




Remember Me?