math on the prop
P!-Ro
Posts: 1,189
I have created an equation to take ping distances and turn them into x and y coordinates. My only problem is I don't know how to make the propeller·solve the equation.
I tried writing code to calculate it·recently but I just got error messages. Could you show me the correct way of doing it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
I tried writing code to calculate it·recently but I just got error messages. Could you show me the correct way of doing it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
Comments
For an example of simple floating point, see chapter 6 in the Propeller Education Kit Labs:Fundamentals Kit· book·(.pdf ~7MB)· source code (zip).· For Cam Thompson's object, you will have to call its start method before calling its conversion and calculation methods.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Post Edited (Andy Lindsay (Parallax)) : 2/15/2009 9:31:03 PM GMT
If you want floating point, just multiply by 1000 at the beginning and divide at the end.
I don't know if this is what you were looking for, but I hope it helps!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
It's good
With your permission
a website with equations for program?
Equations for linear motion etc.
Sorry for my English
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Did the curiosity kill the cat?
......................................
http://forums.parallax.com/showthread.php?p=590115
·
As far as I know this equation isn't on the internet anywhere. I just created it by modifying the Pythagorean Theorem.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
h = atan2(x,y) - 45 degrees
d = (x*y)/sqrt(x^2+y^2)
Note: Better double-check the sense of the two arguments of atan2. In the Fortran and C versions, the first argument is the sine part, the second the cosine part. Mathcad does it the other way. I'm not sure which convention the Propeller version uses, but the formula I gave is the formula for (sin, cos).
I have the analysis in HTML format, if anyone wants me to upload it.
Jack
Jack
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
No. I guess I misinterpreted your figure. I saw the triangle, and assumed that the two axes were lines of sight of two sensors. I assumed that the hypotenuse was some wall. Given that assumption, my equations would give the heading to, and distance from, the wall.
Maybe it's time you told us what that figure is supposed to represent.
Or (also a possibility) maybe everyone else already knows.
Jack
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
theta=atan(y/x) is the inverse of
y/x = tan(theta)
A while ago on this forum, there was an extended sidetrack (within a CORDIC thread) about how one might do vector additions without resorting to trig to go back and forth painfully from polar to rectangular coordinates.
http://forums.parallax.com/showthread.php?p=609449
If I recall correctly, no super duper tricks were forthcoming.
But Pi Guy, I don't understand your equation or the geometry of the mapping problem you are trying to solve. I'm thinking of something like the following diagram, where the PING)) knows where it is in X and Y and also its angle, and it detects an object at that angle at distance d, and needs to put it on the map. The new coordinates x= d*cos(Ω[noparse];)[/noparse] and y=d*sin(Ω[noparse];)[/noparse] need to be added (signed) to the current coordinates of the PING)). Is that off base?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Assume the ping sensor rotates to determine the angle we now only have to deal with the fact that the sensor will probably detect the object over a range of angles either side of its direction. So we need to find the mean angle. If there is more than one object the problem is going to get interesting.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
I published how to take these kind of measurements with the BASIC Stamp for Boe-Bot + Ping))) navigation (polar to Cartesian and Cartesian to polar coordinate conversions). In fact, I think I based some of it on Tracy Allen's articles on inverse trig functions with the BASIC Stamp. You can find these articles under the Boe-Bot + Ping))) heading at forums.parallax.com -> Stamps in Class -> Stamps in Class "Mini Projects".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
@tracy: I just read the thread from 2006. Sorry, guys, but there's no shortcut to using Cartesian coordinates. Everything that looks like a shortcut is really a longcut. If folks insist on using polar coordinates, get used to calling sin/cos.
Better choice: Ditch polar coordinates from the get-go, and do everything in Cartesian. If your concern is relating a vector measured in body (sensor) coordinates, you only need to do a 2x2 matrix multiply to get it. Conventionally, we write the matrix
| cos a -sin a |
C = | sin a cos a|
But that's more for our benefit than the computers. There are lots of ways to generate C directly from sensor measurements, without ever really having to MENTION the word "angle."
@tracy and heater
Ok, I get the geometry of the single sensor, but that leaves me wondering what Pi Guy's "angle1" and "angle 2" are.
In any case, the situation tracy drew only gives you a single isolated point in space. If you're interested in mapping the environment, don't you need to somehow recognize extended shapes? This is hard to do, even for us lower-order animals (humans). Can we say "optical illusion"?
On the other hand, ping (or laser) radar gives you something your eyeballs can't, which is range. That's really valuable.
It gets even more valuable if you can scan something. That's why I was thinking two sensors. Better yet, how about a single sensor, on a swivel. You could sweep the sensor, sort of like the chrome-plated Cylons do. Or Robbie the Robot.
Even better yet, sweep the ROBOT, or at least his head, as birds, lizards, and people do.
A few years ago, I saw a demonstration of a laser system that generates a 3-d image (!). Using mirrors, they sweep a scene using a plain ol' raster scan. But the laser's not only giving you returns from the target, but range for each pixel. In one 60 Hz sweep, they got a 3-d picture <!>. Take a bunch, and you've got a 3-d movie. Then they had software that could take a convention color picture of the same scene, and 3-d-ize it. Then view it from any direction (within reason -- still can't see the back side). Way cool.
Sorry this post was so long. I didn't have time to post a short one.
Jack
Rgds,
······ John Twomey
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Those who can, do.Those who can’t, teach.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
Pythagorean Theorem
x^2 + y^2 = h^2
Where h^2 is the hypotenuse. You did something like
h^2/angleY = x^2
x = (h^2/angleY)^(1/2)
Correct analysis?
If you don't believe it will work, then punch in some numbers and try it. If you get a reading of 10" at 90 deg. angle1 = 1 angle2 = 0. Since I made a mistake the equation for angle 1 will now find you y. If you square 10 it will become 100, multiplied by 1, equals 100. The square root gets you ten again. If you do it for x, it will get you 0. Correct is it not? Now how about 45 deg. 10"? You get ~7.07 for both x and y. If you graph the coordinates they will line up no matter what angle you throw into the equation. Need anymore proof that it works?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
Triangle in question:sides of 1, root(3), and 2 and angles of 30,60, and 90. Picture:
y should return 1
x should return root(3)
d should be 2
To calculate x, I use the first equation (since you told us to switch the x and y)
I change 30 degrees to fit on the 0 to 1 scale that you have so my angle is 1/3. My equation is:
x = root(2^2 / (1/3))
x = root(4*3/1)
x = root(12)
x = root(12) != root(3)
Yes, your equation works for multiples of 45 degrees, but not anything else (most likely based on the fact that 45 and 90 degrees are easily simplified in your equation). You'll have to use trigonometric functions (or their approximations) to calculate the x and y coordinates of from a hypotenuse and angle.
Post Edited (SRLM) : 2/19/2009 6:24:43 AM GMT
Dang! Forget all my ideas about swiveling a sensor. I see that you guys were about 3 years ahead of me.
Story of my life.
Sounds like what Pi Guy needs is a sin/cos decoder. Not sure how much they cost, but I can think of a couple of cheap versions, one using slide pots, one magnetic.
Nah, forget both. Just use a stepper motor, and turn counts into sin-cos using table lookup. Multiply by the range, and you've got your Cartesian vector.
Jack
BTW I think my equation works for all 45-45-90 triangles, but it will take some fixing to work for others as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
Do explain...
BTW, this is not meant to be an attack on you or your intelligence or anything like that. I'm just pointing out that possible errors.
find the regular answer using my equation (for yours it's sqroot 1.333 for y, sqroot 2.666 for x)
Next you would subtract the larger deg from the smaller one (90 - 60) and if the deg for the sensor is smaller than 45 deg (.5) you add the fraction to x and subtract from y, if it is less it would be the reverse. In your equation you would get 30 for the sensors angle, or 30/90 which is 1/3. So, sqroot 1.333 becomes sqroot 1 and sqroot 2.666 becomes sqroot 3. So, your coordinates are (sqroot 3, 1).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
PG, I said "Cartesian vector," not "cartesian filter."
>Can it find me x and y coordinates?
The x- and y-coordinates _ARE_ the Cartesian vector. You seem to be trying to compute these coordinates from the range and angle info. The conversion is simply:
x = d cos(angle)
y = d sin(angle)
Cartesian vector = [noparse][[/noparse]x, y]
I was suggesting that you might get the sine and cosine from a sin/cos encoder, or simply by a table lookup, given the angle. I'm afraid there is no shortcut. You can't do trig without trig functions, no matter how hard you try.
Jack