|
In lugnet.robotics, Ralph Hempel writes:
> [...] I encourage anyone to post an
> application where the dynamic range of signed 32 bit values is outside the
> range of numbers which would be useful to an RCX application!
Here is a simple example where 32 bits isn't enough precision.
Task: Given a robot with at least one motor, rotational velocity sensors [1] on
each motor and a light sensor, implement a program to compile statistics on
motor speed and light level during training and use a linear regression model
to create a light-seeking or dark-seeking behavior.
Algorithm: While the user is training the robot, the robot needs to watch its
speed and light level, continuously collecting data points and accumulating the
five sums necessary to perform the linear regression calculation. The goal is
to be able to notice whether the user was rolling the robot faster while in
light and slower in dark, or vice versa:
motor
| .
| . '
| . '
| : ' .
| ..
| ' .'
| '
| . . '.
| . '
|
+--------------------------- light
The analog rotation sensors give readings from -100 (full reverse) to 100 (full
forward) and the light sensor gives readings from 0 to 100. To keep it
reasonable, we will assume that readings are taken at a rate of 10 per second
for a maximum of 100 seconds, for 1000 readings total.
The five sums that need to be tallied are:
n (number of data points)
Sigma L (sum of light readings)
Sigma M (sum of motor readings)
Sigma M^2 (sum of squares of motor readings)
Sigma L * M
The ranges for the five sums are [0 to 1000], [0 to 100,000], [-100,000 to
100,000], [0 to 10,000,000] and [-10,000,000 to 10,000,000] respectively.
The actual linear regression analysis starts with these three equations:
Delta = n * (sigma M^2) - (sigma M) * (sigma M)
A = ((sigma M^2) * (sigma L) - (sigma M) * (sigma L*M)) / Delta
B = (n * (sigma L*M) - (sigma M) * (sigma L)) / Delta
Overflows occur here:
Delta: [0 to 10,000,000,000]
Numerator in A: [0 to 1,000,000,000,000]
First half of numerator in B: [0 to 10,000,000,000]
I won't explain the rest of the linear regression analysis or the method of
playing back the model, the point was just to demonstrate the overflow.
Of course, you can change the formulas or change the code to compute the same
answers in a different way (which amounts to the same thing) but that's not the
point. High-precision and floating-point libraries are something that you write
once, and once it's been written, everyone else can get real work done without
having to screw around with their formulas.
- Robert Munafo www.mrob.com
[1] A rotational velocity sensor is just a motor hooked up to a sensor input
through two 47K resistors. It allows the robot to sense the rotation of the
motor while the robot is pushed along by the user. See
www.mrob.com/robot/adapter.html
|
|
Message is in Reply To:
16 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|