8 - Murray State Information Systems
8. Robot Tasks - Single Platform
In this chapter we review algorithmic techniques for individual mobile robots. Specific examples will be shown for the SPaRC-1 educational desktop robot but the methods described are adaptable to any wheeled robotic platform with differential drive.
8.1 SPaRC-1 Basic Configuration
Basic Software Library - The SPaRC-1 uses the BasicX-24 microcontroller, programmable in Basic. Refer to the NetMedia Basic Express Language Reference Manual for details on this version of the Basic programming language. The NetMedia System Library provides details for all the functions and procedures available on the BasicX-24 and BasicX-1 microcontrollers. A list of these functions and procedures is provided below:
Math functions
Abs Absolute value
ACos Arc cosine
ASin Arc sine
Atn Arc tangent
Cos Cosine
Exp Raises e to a specified power
Exp10 Raises 10 to a specified power
Fix Truncates a floating point value
Log Natural log
Log10 Log base 10
Pow Raises an operand to a given power
Sin Sine
Sqr Square root
Tan Tangent
String functions
Asc Returns the ASCII code of a character
Chr Converts a numeric value to a character
LCase Converts string to lower case
Len Returns the length of a string
Mid Copies a substring
Trim Trims leading and trailing blanks from string
UCase Converts string to upper case
Memory-related functions
BlockMove Copies a block of data from one RAM location to another
FlipBits Generates mirror image of bit pattern
GetBit Reads a single bit from a variable
GetEEPROM Reads data from EEPROM
MemAddress Returns the address of a variable or array
MemAddressU Returns the address of a variable or array
PersistentPeek Reads a byte from EEPROM
PersistentPoke Writes a byte to EEPROM
PutBit Writes a single bit to a variable
PutEEPROM Writes data to EEPROM
RAMpeek Reads a byte from RAM
RAMpoke Writes a byte to RAM
SerialNumber Returns the version number of a BasicX chip
Queues
GetQueue Reads data from a queue
OpenQueue Defines an array as a queue
PeekQueue Looks at queue data without removing any data
PutQueue Writes data to a queue
PutQueueStr Writes a string to a queue
StatusQueue Determines if a queue has data available for reading
Tasking
CallTask Starts a task
CPUsleep Puts the processor in various low-power modes
Delay Pauses task and allows other tasks to run
DelayUntilClockTick Pauses task until the next tick of the real time clock
FirstTime Determines if the program has been run since download
LockTask Locks the task and discourages other tasks from running
OpenWatchdog Starts the watchdog timer
ResetProcessor Resets and reboots the processor
Semaphore Coordinates the sharing of data between tasks
Sleep Pauses task and allows other tasks to run
TaskIsLocked Determine whether a task is locked
UnlockTask Unlocks a task
WaitForInterrupt Allows a task to respond to a hardware interrupt
Watchdog Resets the watchdog timer
Type conversions
CBool Convert Byte to Boolean
CByte Convert to Byte
CInt Convert to Integer
CLng Convert to Long
CSng Convert to floating point (single)
CStr Convert to string
CuInt Convert to UnsignedInteger
CuLng Convert to UnsignedLong
FixB Truncates a floating point value, converts to Byte
FixI Truncates a floating point value, converts to Integer
FixL Truncates a floating point value, converts to Long
FixUI Truncates a floating point value, converts to UnsignedInteger
FixUL Truncates a floating point value, converts to UnsignedLong
Real time clock
GetDate Returns the date
GetDayOfWeek Returns the day of week
GetTime Returns the time of day
GetTimestamp Returns the date and time of day
PutDate Sets the date
PutTime Sets the time of day
PutTimestamp Sets the date, day of week and time of day
Timer Returns floating point seconds since midnight
Pin I/O
ADCtoCom1 Streams data from ADC to serial port
Com1toDAC Streams data from serial port to DAC
CountTransitions Counts the logic transitions on an input pin
DACpin Generates a pseudo-analog voltage at an output pin
FreqOut Generates dual sinewaves on output pin
GetADC Returns analog voltage
GetPin Returns the logic level of an input pin
InputCapture Records a pulse train on the input capture pin
OutputCapture Sends a pulse train to the output capture pin
PlaySound Plays sound from sampled data stored in EEPROM
PulseIn Measures pulse width on an input pin
PulseOut Sends a pulse to an output pin
PutDAC Generates a pseudo-analog voltage at an output pin
PutPin Configures a pin to 1 of 4 input or output states
RCtime Measures the time delay until a pin transition occurs
ShiftIn Shifts bits from an I/O pin into a byte variable
ShiftOut Shifts bits out of a byte variable to an I/O pin
Communications
Debug.Print Sends string to Com1 serial port
DefineCom3 Defines parameters for serial I/O on any pin
Get1Wire Receives data bit using Dallas 1-Wire protocol
OpenCom Opens an RS-232 serial port
OpenSPI Opens SPI communications
Put1Wire Transmits data bit using Dallas 1-Wire protocol
SPIcmd SPI communications
X10cmd Transmits X-10 data
Processor Hardware - BasicX-24 microcontroller hardware configuration is discussed in detail in the NetMedia BX-24 Hardware Reference Manual. The BasicX-24 is programmable from a desktop PC through a serial interface using the BasicX Development Environment. The major features of the processing hardware listed below:
BX-24 Hardware - The BX-24 uses an Atmel AT90S8535 core processor with 400 bytes of RAM and 32 KBytes of EEPROM. This system provides 16 I/O ports (8 of them with ADC), timers, UARTs, and an SPI peripheral bus. The carriage also includes a voltage regulator and a red/green LED.
BasicX Operating System (BOS) - The BasicX Operating System supports a multitasking environment and includes the speed BasicX execution engine.
BasicX Development Environment - The BasicX Development Environment runs under Windows 98/NT and includes an editor, a compiler, debugging aids, and sample source code. This environment permits the downloading of compiled Basic code and support a two-way communication between the BasicX-24 and the desktop computer during runtime.
BX-24 Technical Specifications - The following table is taken from the NetMedia BX-24 Hardware Reference. This table lists the function and operational characteristics of the BasicX-24 microcontroller.
|I/O Lines |16 total; 8 digital plus 8 lines that can be ADC or digital |
|EEPROM for program |On-board 32 KB EEPROM |
|and data storage |Largest executable user program size is 32 KBytes |
|RAM |400 bytes |
|Analog to digital converter |8 channels of 10 bit ADC, can also be used as regular digital (TTL level) |
| |I/O |
|ADC sample rate |6 k samples/s maximum |
|On-chip LEDs |Has a 2-color surface mount LED (red/green), fully user programmable, not |
| |counted as I/O line |
|Program execution speed |60 microseconds per 16 bit integer add/subtract |
|Serial I/O speed |2400 baud to 460.8 Kbaud on Com1 |
| |300 baud to 19 200 baud on any I/O pin (Com3) |
|Operating voltage range |4.8 VDC to 15.0 VDC |
|Min/Max | |
|Current requirements |20 mA plus I/O loads, if any |
|I/O output source current |10 mA @ 5 V (I/O pin driven high) |
|I/O output sink current |20 mA @ 5 V (I/O pin pulled low) |
|Combined max current load allowed across |80 mA sink or source |
|I/Os | |
|I/O pull-up resistors |120 k( maximum |
|Floating point math |Yes |
|On-chip multitasking |Yes |
|On-chip clock/calendar |Yes |
|Built-in SPI interface |Yes |
|PC prog. interface |Parallel or serial downloads |
|Package type |24 pin PDIP carrier board |
|Environmental specs |Operating temperature: 0 (C to +70 (C |
|abs max ratings |Storage temperature: -65 (C to +150 (C |
BX-24 Pin Layout - The pinout configuration of the BasicX-24 is shown below. This microcontroller and its supporting chip set are mounted on a small circuit board matching the footprint of a 24-pin wide dual inline integrated circuit. Additional access points are provided for the EEPROM Chip Select, SPI MOSI and SCK, processor reset, output capture and the green and red LEDs.
The BasicX-24 is mounted on the SPaRC-1 mobile robot as shown in the figure below. On the SPaRC we have set up pins 5-12 as logical output pins, capable of controlling any TTL or CMOS compatible circuit such as a servo or H-bridge DC motor controller. Pins 13-20 have been set up as analog/digital inputs for sensors such as contact switches and photocells.
The BasicX-24 provides analog-to-digital conversion (ADC) on these eight pins. All 16 I/O pins can be used for input or output as needed for a particular application.
[pic]
When oriented as shown above, the servo type outputs are on the left. The leftmost column of pins are ground the next column is 4.5 volts (3 AA batteries) and the pins in the next column are connected to BX-24 outputs 5 -12 thrugh 1KΩ resistors. On the right side of the BX-24 are 5 columns of sockets. The sockets in the column closest to the BX-24 are connected directly to I/O pins 13-20. The next two columns are common pairs for additional attachments. The next column is 9 volts (from the 9-volt battery) and the rightmost column is ground. A small breadboard is also provided on the SPaRC-1 for circuit prototyping and experimentation. This breadboard is layed out in the conventional manner with electrically common rows at the top and bottom and groups of 5 common recepticles on either side of a central gutter.
Platform Basics - The SPaRC-1 robot uses two drive wheels (called differential drive) as shown below. These wheels are driven by "hacked" servos as discussed in Chapter 4.
|[pic] |[pic] |
|SPaRC-1 |Differential Drive |
A wheel can be driven counter-clockwise by sending it a series of pulses with puslewidth less than approximately 1.5 msec, and clockwise by series of pulses with pulsewidth greater than 1.5 msec. We can use the BasicX-24 system call PulseOut( ) to generate these pulses as shown in the sample code below.
for i=0 to 100
Call PulseOut(11,0.002,1)
Call PulseOut(12,0.001,1)
Call Delay(0.02)
next
The system call to Delay(0.02) separates the pulses with a 20 msec delay. The parameters in system call PulseOut are pin number, pulse width (in seconds) and the logical value of the pulse, respectively. Since the servos can be connected to any I/O pin (5 through 12), your code may need to be modified. Also, notice that to move forward or backward, one wheel must be turning clockwise while the other is turning counter-clockwise. You can rotate your robot by rotating both wheels in the same direction.
8.2 Tasks without Sensors
Most of the programming projects we will cover here involve the use of some types of sensors. Occasionally we will need to move the robot platform or some some manipulator without direct measurement of the robot itself or the environment. Controlled movement without sensing is referred to as dead reckoning. The following code segments and programs illustrate the basics of dead reckoning for a mobile robot platform.
Straight Line Motion - We can move the platform forward in an approximately straight line by driving the lefthand wheel counter-clockwise and the righthand wheel clockwise by the same amount. This can be accomplished using a for..loop similar to the code shown in the previous section. Unfortunately, not all servos have the same rotational rate. Sometimes we need to compensate for speed variations between servos. A simple approach is to provide one wheel with a few extra pulses to compensate for a slower rotation rate. In the code below the wheel driven from pin 12 is given an extra pulse every five passes through the for..loop. You can vary the number of extra pulses by changing the mod value.
for i=0 to 300
Call PulseOut(11,0.002,1)
Call PulseOut(12,0.001,1)
Call Delay(0.02)
if i mod 5 = 0 then
Call PulseOut(12,0.001,1)
Call Delay(0.02)
end if
next
Turning - When the SPaRC-1 needs to turn you can either turn one wheel or both. The amount of rotation is determined by the loop count and whether one or both wheels are turning.
When turning around an outside corner, the robot can move forward until the center of the inside wheel (i.e. wheel closest to the obstruction) is past the corner. Note that this will be the pivot point of the turn.
[pic]
Alternatively, the robot can turn by rotating both wheels counterclockwise (or clockwise for a left-hand turn). In this case the robot must move further past the corner before the turn is made.
[pic]
When turning at an inside corner the robot must start far enough from the edge of the wall to permit the rear of the robot to clear the wall during the turn. This is an important point to consider when applying contact sensors for detecting obstacles.
[pic]
Moving Slowly - One of the shortcomings often associated with using hacked servos for drive motors is the difficulty in making them turn slowly. The version of hacking used on the servos in the SPaRC-1 permits some control of motor speed. In the SPaRC-1 hacked servos the potentiometer has been disengaged from the gearbox and permamently fixed in a central position. This means that servo signals with a pulsewidth near the center of the range (apx. 1.5 msec) will produce a slower rotational speed. The servo electronics is designed to slow the motor when it gets close to the indicated position to reduce overshoot or "ringing" in the servo position as a function of time.
[pic]
We can take advantage of this feature by sending the hacked servo signals near the (1.5 msec pulsewidth). Variations between servos require that we experiment to find the exact value of the pulsewidth that stops the rototation. Once this value is found we can send pulsewidths a few microseconds wider or narrower than this value to drive the wheels slowly forward or reverse.
The source code shown below is a sample program to determine the pulsewidths needed to move each drive wheel of the SPaRC-1 as a desired speed. The particular values for x and y will be specific to your robot.
Public Sub Main()
dim x as single
dim y as single
dim i as integer
x=0.0015
y=0.00153
Call PutPin(26,0)
for i=1 to 1000
Call PulseOut(11,x,1)
Call PulseOut(12,y,1)
Call Delay(0.02)
next
Call PutPin(26,1)
End Sub
Dead Reckoning - We can estimate the distance traveled and the change in heading (i.e. position and orientation) using dead reckoning. To do this we need to collect some data.
To determine the straight line distance traveled by our robot running a for..loop as shown below, choose some point on your robot (e.g. the front) and mark the position on the floor or a table. Then run the for..loop for some value of K. Mark the new position of the robot and measure the distance moved.
for i=0 to K
Call PulseOut(11,0.001,1)
Call PulseOut(12,0.002,1)
Call Delay(0.02)
next
Repeat this for several values of N and plot the results. Note that the call to Delay(0.02) sets the amount of time until the next pulse. The total time between pulses to one of the drive servos is the sum of the delay and the two pulse widths (i.e. 0.023 secs or 23 msec). At these settings the servos are moving at maximum speed for K.(0.023) seconds. Changing the amount of delay will affect the time the servos run but not the speed. This is an important point for computing dead reckoning, since the distances moved will be a function of both the loop count and the delay. The data set you collect can be used to create a graph similar to the one shown below.
This graph shows that, except for a small loop count, the relationship between loop count and distance traveled is fairly linear. We can develop a loop count vs. distance traveled function to be used in dead reckoning. Assuming a linear function of the form,
Y = mX + b (m=slope, b=y axis intercept)
Count = m.(Distance) + 0
In our application we will want to know the Count (K) needed to move a desired distance. Therefore we let the distance traveled be the independent parameter use to derive the count. We can compute the slope (m) by choosing a pair of points on the graph that are well separated such as (11,25) and (95,225).
m = slope = rise/run = (225-25)/(95-11) = 2.381
Our function for count vs. distance is
Count = 2.381 (Distance)
As a test we compute the loop count needed to travel 50 cm to be 119.05, but since we need an integer we would use 119. This compares well with our experimentally derived value, so we are confident that this function is correct.
This graphical technique is rather limited and cannot be used when there is a significant amount of noise (due to measurement error or system uncertainty) or when the relationship between the dependent and independent variables is not linear. A superior and more generally applicable technique is called method of least squares.
Method of Least Squares - One of the simplest functional relationships we can study is the first order polynomial or linear function:
y = f(x) = b + mx
If we make meaurements of a physical system (i.e. determine a set of (x,y) values) there will be errors in these measurements. It is important to recognize that there is a difference between the function f(x) and the sampled data set. We need to establish a criterion for minimizing the difference between the chosen function f(x) and the y components of the data set. Using this criterion we can determine values for a the coefficients b and m that best fits the function to the data. There is no absolute method for determining the best values for b and m but we will argue for the use of a particular technique called the method of least squares.
First we want to choose coefficients b and m to minimize the differeneces between the actual y values and those calculated by the function f(x). That is,
minimize δyi = yi - b - mxi for all i=1,..,n
We could simply add all the δyi terms, but this would allow positive and negative difference to cancel each other, possibly masking larger discrepancies between f(x) and the measured values of y. Instead we can minimize the sum of the squares of the differences,
minimize Σδyi2
We can normalize each δyi term by dividing it by the standard deviation of the yi values,
This quantity is called the "chi-squared" value. It is also the exponent of the normal probability density function. When we minimize this term we will simul-taneously maximize the probability that the calculated yi will equal the measured yi. The yi's are the measured values and the - b - mxi are the derived values. The yi's are the measured values and the -b-mxi are the derived values. To find the values of the coefficients that minimize this sum, we will compute the partial derivatives of Χ 2 with respect to b and m, and set them equal to zero.
These partial derivatives can be computed and used to obtain values for b and m that minimize the mean squared error between the measured and computed values of x and y. (Actually the error is assumed to be associated with the dependent variable y).
[pic]
-----------------------
[pic]
[pic]
[pic]
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
Related searches
- why are information systems essential
- introduction to information systems pdf
- information systems professional organization
- information systems in business organizations
- information systems impact on business
- information systems affect on business
- how information systems impact organizations
- information systems in organizations pdf
- information systems within an organization
- management information systems organization
- what is information systems pdf
- importance of information systems pdf