Subject:
|
Re: (no subject)
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Tue, 29 Dec 1998 07:24:21 GMT
|
Original-From:
|
John A. Tamplin <jat@traveller.com=AvoidSpam=>
|
Viewed:
|
1448 times
|
| |
| |
On Sun, 27 Dec 1998 MwalimuB@aol.com wrote:
> After reading Dave's commentary on the RCX's ADC system, I did a few more
> test's, and found that I could easily predict the value that the RCX would
> produce for a given resistor. Just use the voltage divider formula - V=R2 /
> (10,000 + R2) and multiply your result by 1023. My table for multiple sensors
> would be as follows:
>
> A=10K B=22K C=33K
>
> A=512(10K) AB=417(6875 ohms) ABC=371(5690 ohms)
> B=703(22K) AC=444(7674 ohms) no closures = 1023
> C=785(33K) BC=582(13200 ohms)
>
> This is of course all theoretical - I have to build it.
Wouldn't the resultant reading be:
value=1023/(10000*(sum (Si/Ri)) + 1)
where Si is 1 if Switch i is closed and 0 otherwise
and Ri is the value of the resistor attached in series with Switch i
Inversely, sum(Si/Ri)=(1023-V)/(10000*V), but unfortunately this isn't
a linear function so we can't transform the reading values into the
binary number S representing which switches are active with a linear
function. The easiest way to do it is to remove the terms from the sum
in order by their magnitude (ie, in order by resistance with the first
being the smallest resistor). Sample C code:
long Resistors[]={
6000,
12000,
22000,
65000,
0
};
int Switches(int value) {
double target_sum;
int i,switches=0;
target_sum=(1024-value)/(10000.0*value-55000.0);
for(i=0; Resistors[i]; i++) {
if(target_sum>=(1.0/Resistors[i]-.000001) {
target_sum-=1.0/Resistors[i];
switches|=(1<<i);
}
}
return switches;
}
This properly decodes all 4-bit values assuming the A/D reading is within
+/-4 of the theoretical reading (the Hamming distance between codes in
this example is 5, so you can't do better than +/-4). If the conversion
is more accurate and stable than that, you can fit more bits. 4 is enough
for me, since I want to have bumpers on all sides and read them by a
single sensor input.
The resistance of the wire is not factored into this computation, but I
expect it to be low enough tht it doesn't affect the result.
I am sure the code above can be rewritten to avoid floating point, but this
will give you an idea of how to systematically approach the problem.
NOTE: I haven't built this yet, but I am about to do so. I may find out
that the A/D conversion isn't consistent enough to pack 4 switches into a
single sensor, but I wouldn't think so. If you build it before I do, please
let me know how it works for you.
John A. Tamplin Traveller Information Services
jat@Traveller.COM 2104 West Ferry Way
256/705-7007 - FAX 256/705-7100 Huntsville, AL 35801
--
Did you check the web site first?: http://www.crynwr.com/lego-robotics
|
|
Message is in Reply To:
| | (no subject)
|
| After reading Dave's commentary on the RCX's ADC system, I did a few more test's, and found that I could easily predict the value that the RCX would produce for a given resistor. Just use the voltage divider formula - V=R2 / (10,000 + R2) and (...) (26 years ago, 28-Dec-98, to lugnet.robotics)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in Robotics
|
|
|
|