need help with brads
W9GFO
Posts: 4,010
Hi all, I've been scratching my head for quite a while and just can't get this figured out. It seems like it ought to be simple, so now I ask for help...
I have a direction I want to go, in brads
I have a heading that I am going, in brads
I need to determine the difference in brads between the direction and heading
That's it, I hope someone can help with the solution
I have a direction I want to go, in brads
I have a heading that I am going, in brads
I need to determine the difference in brads between the direction and heading
That's it, I hope someone can help with the solution
Comments
what's wrong with a simple subtract ?
Ed
Post Edited (Skywalker49) : 4/19/2007 9:44:07 AM GMT
I'm not quite sure what you mean by "I have a direction I want to go, in brads", but regardless, how about the following:
difference VAR BYTE
heading VAR BYTE
direction VAR BYTE
difference = abs(heading-direction)
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Brad vars need to be Word type otherwise trig. functions will not work correctly.
See Allen Tracy's website: http://www.emesystems.com/BS2math3.htm#arcCos
Ed
I see no trig being used at present in the data given. so we can disregard that warning for now. Since brad values run from 0 to 255 the largest diffference that can be seen is 255 - 0 which is 255 and well within the capacity of a BYTE. Use WORDS _ONLY_ when you NEED to use WORDS, otherwise use BYTEs or NIBs as they are more appropriate and will conserve valuable RAM space.
If we had been adding or multiplying, there might have been a case for a WORD variable as the receiving field. That is clearly not the case here, as we're doing substraction.
Just for the record ABS means ABSOLUTE value, which has nothing to do with trig.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
your are ABSolutely right about the choise of vars.
On top ...
Reading the documentation again, byte is ok for angles in brads.
This is even ok for trig. functions which most likely will be used when angles are involved.
Where one MUST use word variables is in the result of trig. functions. These functions return a 16 bit result.
Sorry for the confusing message sent earlier but hopefully now that the message is complete, it adds some value.
Ed
direction = 250
heading = 20 (the difference here should be 26)
difference = ABS(heading-dir)
difference = 230
If one is between 192 and 255 and the other is between 0 and 64, the difference will give a result too large.
Rich H
IF difference > 128 THEN
difference =ABS((difference /2) - 128)*2
I'm gonna go try it...
I'm not sure what you're trying to calculate here, as it's not the kind of navigation I've done, but if you're happy with the result above. I suspect Tracy Allen can show you a way to do it in one line of program code using the MAX and/or MIN function.
Tracy can shoot it right out, but it would take me an hour to ferret it out and test it to my and your satisfaction. What you essentially are doing is taking the larger or smaller of the calculations BOTH of which will appear in the extended instruction. This is possible because PBASIC is very adept about using and saving intermediate results. It's one of the more powerful aspects of PBASIC which are hardy "played up" enough. Tracy uses it all the time and thus it's fairly easy for him to see exactly what needs to be done.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
will select the one that is shorter. It is a little more complicated if you want to maintain the sign, that is, which direction to rotate.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
http://web.mit.edu/don_eng/Public/SciFair/SciFair05/Dilemmas.doc
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
diff = ABS(heading-direction)
IF diff < 129 THEN done
diff = 256 - diff
Done:
Ed
I do want to determine which direction to rotate, I'm just starting to try to figure that one out...
I sympathize completely with the student who wrote that doc.
I have had to;
Figure out how to make lat/long coords fit into bytes and words,
Figure out how to calculate differences in lats and longs while using a byte and word for each
Reduce varying distances to destinations (in signed bytes) while maintaining maximum accuracy to be used with the ATN function
Change the direction of rotation of brads to cw for terrestrial navigation,
Rotate brads ccw by 64 so that 0 is north
I didn't expect any of these limitations when I started, I had never worked with brads before and didn't expect the -127 to 127 limit for the ATN nor had I had to use the large numbers which are required in lat/lon coords.
I'm getting there, slowly...
Rich H
You might want to consider using a math co-processor to save you more gray hair! Here are a couple you might consider:
Parallax: http://www.parallax.com/detail.asp?product_id=604-00030
Al Williams: http://www.awce.com/pak1.htm
Just as an aside, I thought some GPS units would do navigation calculations for you.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
deviation = ABS(heading - direction)
deviation = deviation MAX (256 - deviation)
IF deviation < ABS(heading -(direction+1)) THEN
Steer Right
ELSE
Steer Left
ENDIF
Does that look like a good way to do it?
Rich H
That math co-processor looks like it would make things a lot easier, as long as I can figure out how to work it - I just ordered one.
I think I have my distance, heading, off course deviation and direction to steer figured out so now I'm on to learning how to use the GPS
You'll probably hear from me again
Thanks for all the help,
Rich H
Please look at these two articles.· They demonstrate the necessary conversions for both Cartesian to Polar and back again for robot navigation with a BASIC Stamp.
·
Boe-Bot + Ping))) Ultrasonic Rangefinder
· Ping)))Dar - a Radar Style Display
· Scan for and Go to Closest Object
These are just a few of the interesting things you will find on the Stamps in Class "Mini Projects"·post.
Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Remember, you're going to want a 'dead' zone, where you don't turn at all. If not, you will constantly zig-zag. Left, then right, then back again.
HTH, Chris