Presentation is loading. Please wait.

Presentation is loading. Please wait.

BASIC Stamp II Programming for Descartes Robots

Similar presentations


Presentation on theme: "BASIC Stamp II Programming for Descartes Robots"— Presentation transcript:

1 BASIC Stamp II Programming for Descartes Robots
Alexander Stoytchev Mobile Robot Laboratory Georgia Tech CS4630: Robotics and Sensing

2 Descartes Robot

3 Bumpers

4 Motors

5 Wheel Encoders

6 Wheel Belts

7 Serial Cable

8 System Requirements IBM PC or compatible computer
3.5" floppy disk drive serial port 128K of RAM MS-DOS 2.0 or higher. A color video display is recommended.

9 Onboard Computer

10 Microcontroller Layout

11 BASIC Stamp II Manufactured by Parallax Inc.
Runs Parallax BASIC (PBASIC) programs.

12 BASIC Stamp II Processor: Parallax PIC16C57 EEPROM: 2048 bytes
RAM: 16 word registers (or 32 bytes!!!) Max. Program Length: ~500 instructions Clock Speed: 20-MHz Execution Speed: 4000 instructions/sec. Current Requirements: 7 mA running, 50 uA in sleep modes 16 I/O Lines; RS-232 input & output ( K bauds) Price $49

13 Secondary Processor Microchip(TM) PIC16C71 RISC, 10MHz
Automatically executes commands received from the main processor without intervention Motor PWM pulsing for speed control encoder monitoring for wheel position and velocity A/D conversions navigation control monitoring tasks

14 Electrical Diagram

15 EEPROM Layout

16 RAM Layout

17 PBASIC Parallax BASIC Token interpreter in program memory of the PIC
EEPROM as token and data memory

18 Types WORD, BYTE, NIB, BIT VAR, CON, DATA symbol VAR type
symbol VAR size(array) symbol VAR variable.modifier symbol CON expression symbol DATA type symbol DATA data, data, ...

19

20 Operators

21 Common Arithmetic Problems
Evaluation is always from left to right X = 2 + 3* ‘= 20 X = 3* ‘= 14 X = 2 + (3*4) ‘= 14

22 IF IF variable ?? value {AND/OR variable ?? value ...} THEN address
?? can be =, <>, =>, =<, >, < Variable(s) will be compared to Value(s). Value is a variable/constant. Address is a label which specifies where to go if condition is true.

23 BRANCH BRANCH offset,(address0,address1...addressN)
Branch to address specified by offset (if in range). Offset is a variable/constant which specifies which Address# to use (0-N). Addresses are labels which specify where to go.

24 Jumps & Subroutines GOTO label GOSUB subname RETURN

25 FOR Loop FOR variable = start TO end {STEP {-}increment} NEXT {variable} Variable will be used as a counter Start is the initial value of Variable End is the terminal value of Variable Increment is an optional value which overrides the default counter delta of +1. If Increment is negative it is subtracted

26 EEPROM Symbol DATA data, data, … READ location,variable
WRITE location,data EEPROM {location},(data,data...) Preload EEPROM data locations (those not used by the program).

27 DEBUG DEBUG cls,"Text",cr,var,$var,%var,#var,#$var,#%var
Display information in the debug window Text to be printed can be expressed in quotes; cls - clear screen cr - carriage return Simply naming the variables prints their current values Decimal is the default, $ - can be used for hex % - can be used for binary. # - (with optional '$' or '%' in front) the variable name will not be printed, instead only the value will be printed.

28 Unary Operators

29 Sin(x) Example y=sin(x) , x= 0 to 2*Pi
Y= 127 * sin (X/256 *2*Pi), X=1 to 255 The whole circle is described by 256 steps

30 Sin(x) and Cos(x)

31 Pausing and Sleeping STOP - like end but no power consumption
PAUSE milliseconds NAP period Power consumption is reduced to an extent dependent upon the length of the period. duration 2^period * ~18ms. Period (0 to 7) SLEEP seconds resolution is ~2.3s, accuracy is ~99.9% Power consumption reduced to 1/100th normal Seconds is a variable/constant ( ). STOP - like end but no power consumption END Sleep terminally until the power cycles (program re-runs) or the pc connects. Power is reduced to an absolute minimum

32 Miscellaneous SERIN pin,baudmode,(qualifier,qualifier...)
RANDOM wordvariable SOUND pin#,(note0, duration0, note1, duration1, ….) SERIN pin,baudmode,(qualifier,qualifier...) SEROUT pin,baudmode,({#}data,{#}data...)

33 Robot Commands: Initialization
The secondary PIC communicates with the BS2-IC at 50kbps over a serial link. Port 15 is used for communication. Port 14 is used for flow control. The PIC requires about 80ms to start-up. PAUSE use before every program SEROUT 15\14, 0, ["I"] - to reset the PIC

34 Syntax of PIC Commands SEROUT 15\14, 0, ["C", VALUE.LOWBYTE, VALUE.HIGHBYTE] C is the command character (not case-sensitive). VALUE.LOWBYTE is the low byte of the value. VALUE.HIGHBYTE is the high byte of the value.

35 Going Forward and Backward
SEROUT 15\14, 0, ["F", 100] SEROUT 15\14, 0, ["B", 44, 1] DISTANCE VAR WORD DISTANCE = 300 SEROUT 15\14, 0, [“B", DISTANCE.LOWBYTE, DISTANCE.HIGHBYTE]

36 Requesting Sensor Data
Send a SEROUT request for data followed IMMEDIATELY by a SERIN command. ‘Read left wheel encoder counts DISTANCE VAR WORD DL VAR DISTANCE.LOWBYTE DH VAR DISTANCE.HIGHBYTE SEROUT 15\14, 0, ["["] SERIN 15\14, 0, [DL, DH]

37 Heading Information SEROUT 15\14, 0, ["?"] SERIN 15\14, 0, [HEADING]
HEADING should be (turn resolution = 2 degrees) HEADING VAR WORD HEADING = 320 SEROUT 15\14, 0, ["H", HEADING/2] HEADING = HEADING * 2

38 Making Turns SEROUT 15\14, 0, [“L“, 20] ‘ turn left 40 degrees
SEROUT 15\14, 0, [“R“, 30] ‘ turn right 60 degrees Turn parameter * 2 = turn angle SEROUT 15\14, 0, [“H“, 45] ‘ Set heading SEROUT 15\14, 0, [“T“, 45] ‘ Set target heading

39 Motor Control SEROUT 15\14, 0, [“M“, %1010]
%00 turn off motor %01 set in backward motion %10 set in forward motion SEROUT 15\14, 0, [“S“, 10] ‘ Set Speed Valid speeds Automatic speed compensation. SEROUT 15\14, 0, [“<“, 10] ‘ Set left motor speed SEROUT 15\14, 0, [“>“, 15] ‘ Set right motor speed SEROUT 15\14, 0, [“(“] ‘ Request left wheel instantaneous velocity SEROUT 15\14, 0, [“)“] ‘ Request right wheel instantaneous velocity SEROUT 15\14, 0, [“#“] ‘ Request Stopped State SEROUT 15\14, 0, [“C“] ‘ Clear distances traveled

40 Common Problems “Hardware Not found” error message
Check Serial cable orientation Power down and up Check arithmetic operations for overflows Variable names and values

41 References http://www.divent.com http://www.parallaxinc.com/
File: progrmng.html Claus Kuhnel and Klaus Zahnert “BASIC Stamp” (second edition), Newness, 2000


Download ppt "BASIC Stamp II Programming for Descartes Robots"

Similar presentations


Ads by Google