Go to Post Students can learn to drive on whatever they give us. Ramps, carpet, grating, HDPE, lexan, diamond plate, regolith, other robots the driver station wall, referees, stairs, Dean, the bar, goals, the scorer's table, you name it, I've watched robots somehow manage to drive on it - Peter Matteson [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 23-01-2002, 08:09
Leo M Leo M is offline
Registered User
#0384 (Tucker Tigers)
 
Join Date: Jun 2001
Location: Richmond, VA
Posts: 70
Leo M is just really niceLeo M is just really niceLeo M is just really niceLeo M is just really niceLeo M is just really nice
Return of the Inverse Trig Functions

Our team is not planning on using the optical sensors to track the goals, but maybe some of you might want to experiment with them and would find a use for inverse sine and cosine functions that work with the Basic Stamp's idiosyncratic math processing abilities. The Stamp's sine (sin) and cosine (cos) functions take an argument (an angle) in 'binary radians' (brads) and output an integer result in the range -127 to +127. The brad is an angular measure arrived at by dividing a circle into 256 arcs, instead of the customary 360 degrees. A brad is 360/256 = 1.406 degrees.
Integer output of the functions is used because the Stamp knows nothing of numbers between 0 and 1. The normal 0 to 1 range (abs) of the sine and cosine is thus scaled up to 0 to 127.

If we restrict the discussion to angles between 0 and 90 degrees (0 to 64 brads), the sin and cos functions map integers in the range 0 to 64 into other integers in the range 0 to 127. Going the other way, the inverse sine and cosine functions should map integers in the range 0 to 127 into integers in the range 0 to 64.

In order to accomplish that, I fit quadratic curves to the integers obtained from the Stamp's sin and cos functions, such that the curves would take arguments in the range of 0 to 127, and return angles of 0 to 64. I used two curves for each inverse function, and pieced them together. I had to apply some 'end correction' to the inverse sine to get a closer agreement with the Stamp's sine values, but in general the inverse functions have relatively small errors. They aren't perfect; feel free to contact me for the details of how I arrived at them, if you would like to do some more work on the problem.

The inverse sine and cosine functions are presented below. They are valid for input in the range 0 to 127, and will output angles in brads in the range 0 to 64 (0 to 90 degrees). You will have to decide on what trig relationships will give you what you need if you want to work outside those ranges - but it is certainly possible. Also, you may wish to rename variables. The code needs to be all on one line - I have divided it for readability. Be very careful with the parentheses - think before changing them, or you may get some strange results. The quadratics are written in 'nested form' to keep intermediate values within the allowable range of the Stamp's word-length work space. So, don't be scared of the large integers inside the functions - everything works out.

arccosine:

arccos = ((1-(x/118))*(((-x-181)*x+48472)/769)) +
((x/118)*((((-3*x+707)*x-41331)/20)))


arcsine:

arcsin = ((1-(x/118))*(((x+181)*x+744)/769)) +
((x/118)*(((((3*x-707)*x+42611)/20))+((x-115)/3)))

Just one more note in this excessively long post. The (x/118) and (1 - x/118) use the Stamp's integer math to turn the two curves on and off at the right time. To the Stamp, 117/118 =0, and
127/118 = 1.

Good luck, and let me know if you use these.
__________________
Leo M.
  #2   Spotlight this post!  
Unread 23-01-2002, 11:31
zorro zorro is offline
Registered User
#0292 (PantherTech)
 
Join Date: Jan 2002
Location: Kokomo, IN
Posts: 21
zorro is an unknown quantity at this point
Send a message via AIM to zorro
I thought about using the trig functions, then I arrived at a better conclusion. If you have the time, it would be considerably easier to make a lookup lookdown command going off the servo value itself. If you are making a ball launcher, you don't need to know the exact distance away from the goal you are. You just need to know how fast to turn the motor. Instead of using two equations (one to find the distance and another to set the speed of the launcher), just use the lookup/down commands for getting the servo position then use the returned index value to set the speed of the motor.
__________________
Greg Szorc
gregszorc@cwru.edu
  #3   Spotlight this post!  
Unread 23-01-2002, 13:45
Matt Reiland's Avatar
Matt Reiland Matt Reiland is offline
'The' drive behind the drive
None #0226 (TEC CReW Hammerheads)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1999
Location: Troy Michigan
Posts: 712
Matt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond reputeMatt Reiland has a reputation beyond repute
Nice Job Leo we were looking for a better way to calculate our steering angle
  #4   Spotlight this post!  
Unread 24-01-2002, 08:12
Leo M Leo M is offline
Registered User
#0384 (Tucker Tigers)
 
Join Date: Jun 2001
Location: Richmond, VA
Posts: 70
Leo M is just really niceLeo M is just really niceLeo M is just really niceLeo M is just really niceLeo M is just really nice
Thanks. It was really just an 'intellectual exercise' for me during the off-season. Once I really got into it, I started learning all sorts of useful things that can be done with that little Stamp processor. The end result was just a couple of lines of code that we aren't going to use (not this year, anyway). They were too good to just throw away, so I thought it would be a lot better to give them to my friends in the FIRST community. It certainly would make me happy to know that someone got some use out of them, if only to learn more about curve fitting and least squares.
__________________
Leo M.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 19:27.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi