Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Calculating Angle to fire at (http://www.chiefdelphi.com/forums/showthread.php?t=41363)

craigbutcher 14-01-2006 03:59

Re: Calculating Angle to fire at
 
When seeking guidance, look up. There is a very good website with the basics, not only on ballistics, but also on other cool and significant topics. I am really very impressed by this website. I recommend starting with this index page:

http://exploration.grc.nasa.gov/educ...ket/short.html


You will probably want to be sure to have a look at this particular page:

http://exploration.grc.nasa.gov/educ...et/flteqs.html

Our government has borrowed trillions of dollars to fund this website, so you should take advantage of it!


The strictly ballistic part (without air resistance) you can do parametrically, using the Newtonian relation F=m*a, with first term physics/calculus, or algebraically by looking it up. That's a good first approximation and probably 80% right or so.

The drag part is a much harder problem because the drag always shows up as a force vector whose vertical and horizontal components are changing as a function of the magnitude and direction of the overall velocity vector. Drag in the horizontal direction, for instance, will be largest at the top of the projectile's arc. For this reason you cannot treat the components as ordinary differential equations with separable variables as you can using the simple Newtonian equations of motion. If the projectile is dropping straight down there is no horizontal component, and if it is a car there is no vertical component, which is why you can solve for terminal velocity using simple calculus.

You can make some simplifying assumptions about the average horizontal and vertical drag components, and that will get you closer if you pick the right assumptions. However, your best bet is to do prepare a numerical model using the state equations and some sort of calculation software--you can use Excel, or MATLAB, or Mathematica, or Mathcad, or program it in C. In other words, chop the problem up into N parts of the total flight time T (t0,t1,t2...tN), calculate an approximation at each interval, plug that value back in to calculate the conditions at t2, and so forth. The more the N, the more reality will be willing to cooperate with your answer...if the numbers you pick for the drag coefficient and for the area and so on are the right ones.

Oh, I almost forgot. There is also the Magnus effect which adds another wrinkle yet. A symmetrical spinning or rotating projectile moving through a viscous fluid (for example, air) will experience forces due to pressure differences caused by the Bernoulli effect created by the rotation. This is the subject of curveballs and so on. And while we're on that subject, I should probably mention surface roughness, reynolds number, airstreams, laminar flow, turbulent flow, and chaos theory. Not to worry, though. If even the very smartest of us really understood this stuff (and I am not one of those guys), we wouldn't need to build wind tunnels.

Your numerical simulation will get you in the ballpark. Once in, you need to build a pitching machine and do some testing.

Good luck.

David Brinza 14-01-2006 09:30

Re: Calculating Angle to fire at
 
Quote:

Originally Posted by craigbutcher
When seeking guidance, look up. There is a very good website with the basics, not only on ballistics, but also on other cool and significant topics. I am really very impressed by this website. I recommend starting with this index page:

http://exploration.grc.nasa.gov/educ...ket/short.html


You will probably want to be sure to have a look at this particular page:

http://exploration.grc.nasa.gov/educ...et/flteqs.html

Our government has borrowed trillions of dollars to fund this website, so you should take advantage of it!

Yes indeed, there is a good collection of resources here (correction to the first URL):

http://exploration.grc.nasa.gov/educ...et/shortr.html

I'm taking serious offense to the statement above about our government borrowing trillions of dollars to fund this website. NASA's total budget this year is on the order of $17 billion dollars. Since NASA's inception (< 50 years ago), it hasn't spent $1 trillion dollars. The current NASA budget funds a huge list of activities: returning the Space Shuttle to flight, starting the development of the new human spaceflight vehicle, operating the ISS, supporting the Mars missions - operating (2 of Dave Lavery's "other cars" and 3 orbiters) and two in development (Mars Science Lab and Phoenix), operating Cassini at Saturn, launching New Horizons Pluto mission (later this month), operating Stardust (returning Jan. 15 with cometary and interplanetary dust particles), operating 2 Voyager spacecraft (at the real "edge" of our solar system), operating Hubble Space Telescope (including the final Hubble repair mission), operating Spitzer (a large infrared space telescope), developing the Space Interferometer Mission, supporting aeronautics research, operating and developing many, many Earth Science missions, plus many other missions and research activities that wouldn't begin to fit on a whole page of this thread.

On top of all the research and mission support, the NASA budget is providing some support to educational activities (such as FIRST and the above referenced website). The NASA education budget is on the order of 1% of the total NASA budget (which in of itself is about 0.7% of the federal government's budget). The website above was probably developed by a small handful of dedicated people - true educators, with a tiny budget and, most unfortunately, not a totally secure job future. (NASA's budget is under tremendous pressure and scrutiny as the agency is in a period of transition - there have be many layoffs within the agency and with contractors that support NASA in the past year).

Sorry for the rant, but I suspect there's a lot of people with the misconception that NASA's budget is large (it's less than 5% of the Department of Defense budget). I think the public gets a lot for what it invests (not borrows) in NASA.

seanwitte 14-01-2006 13:39

Re: Calculating Angle to fire at
 
Quote:

Originally Posted by Korbin
was this tested using the four bulbs that came in the kit, or with all eight that will be used in competition?

I used what Dave gave me, which was an aluminum enclosure with two sets of 4 tube cathode tubes and an HDPE cover plate. I powered it with a 12V jump starter. With the target at the opposite side of my office at home (about 20' away) the number of tracked pixels was very small and the camera would occasionally lose the target and jump back into the search pattern.

dababyjebus 14-01-2006 16:37

Re: Calculating Angle to fire at
 
I don't know whether the question was sufficiently answered as far as calculating the angle goes. I certainly agree that with the trig involved and the other factors like air resistance and spin it's probably not going to be the way to go, but there is a simpler way to get theta than "A = 1/2 * (asin( (((g * x^2) / (Vo^2)) +y) / sqrt(x^2 + y^2) ) - atan2(-y/x))" ~Matt Adams.

Asumming:
Y = hieght to center of hoop
V = constant velocity
X = distance to goal from end of firing mechanism
Yo = height at which projectile leaves the firing mechanism

Vox = cos(A) * V
Voy = sin(A) * V

Y = Yo + Voy * t - 4.9 * t^2,
T = x/Vox,
Voy = Vox * tan(A);

Y = Yo + (Vox * tan(A)) * (X / Vox) - 4.9 * X^2 / Vox^2
Y = Yo + X * tan(A) - 4.9 * X^2 * sec(A)^2 / V^2
0 = Yo * V^2 - Y * V^2 + X * V^2 * tan(A) - 4.9*X^2 * (1 + tan(A)^2)
0 = (-4.9*X^2*tan(A)^2) + (X * V^2 * tan(A)) + ( V^2 (Yo - Y - 4.9X^2))

so just plug that into the quadratic formula with:
a = -4.9 * X * X
b = X * V * V
c = V * V * (Yo - Y - (4.9 * X * X) )

arctan( (-b + sqrt(b * b - 4 * a * c)) / (2 * a) )

Though it has been said that you will have to take into account the variables of air resistance and spin among others, this should give some people a good idea of where to start and fine tune from.

Hope this was at least somewhat helpful.

MikeDubreuil 16-01-2006 10:21

Re: Calculating Angle to fire at
 
Quote:

Originally Posted by seanwitte
When I tested the camera code I could only get about 20' away before the trackable pixel area becomes too small. At 6" increments your lookup table is only 40 entries long.

We tested the camera with Kevin Watson's camera code last night. I was astonished to find that we could track the vision target from approximately 55 feet away. In fact it was so far that we didn't have a tape measure long enough and we had to go through several connected rooms to get to that distance. We were not able to test the maximum distance because we ran out of room. We even tested different lighting situations and it had no effect on the camera's performace. We were really floored last night and I have to hand it to FIRST Engineering because this is simply awesome.

seanwitte 16-01-2006 14:11

Re: Calculating Angle to fire at
 
Quote:

Originally Posted by MikeDubreuil
We tested the camera with Kevin Watson's camera code last night. I was astonished to find that we could track the vision target from approximately 55 feet away. In fact it was so far that we didn't have a tape measure long enough and we had to go through several connected rooms to get to that distance. We were not able to test the maximum distance because we ran out of room. We even tested different lighting situations and it had no effect on the camera's performace. We were really floored last night and I have to hand it to FIRST Engineering because this is simply awesome.

Its encouraging that you had better results. I'd heard from other sources that the range was quite far. I think the the color calibration values may not have been spot on for the cathode target when I was testing. Anyways, ignore my comments earlier in this thread, apparently the tracking range is not an issue.

Cuog 16-01-2006 19:07

Re: Calculating Angle to fire at
 
Quote:

Originally Posted by dababyjebus
I don't know whether the question was sufficiently answered as far as calculating the angle goes. I certainly agree that with the trig involved and the other factors like air resistance and spin it's probably not going to be the way to go, but there is a simpler way to get theta than "A = 1/2 * (asin( (((g * x^2) / (Vo^2)) +y) / sqrt(x^2 + y^2) ) - atan2(-y/x))" ~Matt Adams.

Asumming:
Y = hieght to center of hoop
V = constant velocity
X = distance to goal from end of firing mechanism
Yo = height at which projectile leaves the firing mechanism

Vox = cos(A) * V
Voy = sin(A) * V

Y = Yo + Voy * t - 4.9 * t^2,
T = x/Vox,
Voy = Vox * tan(A);

Y = Yo + (Vox * tan(A)) * (X / Vox) - 4.9 * X^2 / Vox^2
Y = Yo + X * tan(A) - 4.9 * X^2 * sec(A)^2 / V^2
0 = Yo * V^2 - Y * V^2 + X * V^2 * tan(A) - 4.9*X^2 * (1 + tan(A)^2)
0 = (-4.9*X^2*tan(A)^2) + (X * V^2 * tan(A)) + ( V^2 (Yo - Y - 4.9X^2))

so just plug that into the quadratic formula with:
a = -4.9 * X * X
b = X * V * V
c = V * V * (Yo - Y - (4.9 * X * X) )

arctan( (-b + sqrt(b * b - 4 * a * c)) / (2 * a) )

Though it has been said that you will have to take into account the variables of air resistance and spin among others, this should give some people a good idea of where to start and fine tune from.

Hope this was at least somewhat helpful.

I already have a .c file with this already implemented and it will calculate angles in 3 dimensions as well as use accelerometer input, i am hoping to release this to teams by the end of the month since i still have to put finishing touches on the software and my team has side tracked my to starting to code for our robot which is unfortunetaly lacking a cannon

dlavery 16-01-2006 21:28

Re: Calculating Angle to fire at
 
Quote:

Originally Posted by MikeDubreuil
We tested the camera with Kevin Watson's camera code last night. I was astonished to find that we could track the vision target from approximately 55 feet away. In fact it was so far that we didn't have a tape measure long enough and we had to go through several connected rooms to get to that distance. We were not able to test the maximum distance because we ran out of room. We even tested different lighting situations and it had no effect on the camera's performace. We were really floored last night and I have to hand it to FIRST Engineering because this is simply awesome.

While it is encouraging that we all recognize the contributions and value of the FIRST Engineering staff, I do feel that it is important to give full credit where credit is due for the camera system used in this year's Kit Of Parts. Like so many other things, the camera development was a collaboration of a lot of talents and resources. The camera design is obviously based on the CMUcamII developed by Illah Nourbaksh and Anthony Rowe from Carnegie Mellon University, and then reconfigured to fit within the physical constraints by the fine folks at Innovation First. The pan-tilt unit for the camera was designed by JVN at IFI. The software that allows the entire system to operate with the level of performance you are seeing was written by Kevin Watson at the NASA Jet Propulsion Lab. James Rahaim at FIRST, Peggy Caserto and Marcis Jansons at the U.S. Coast Guard Academy, and Sean Witte all helped with the testing and validation. If you like what you see with the camera system, please thank each of these folks for their efforts. If you don't like it, you can blame me.

-dave

aaronm_k 05-02-2006 18:19

Re: Calculating Angle to fire at
 
Quote:

Originally Posted by varcsscotty
OK! something really funny just happened. I was working on these trajectories and having quite the frustrating time with them....
In walks my brother with the comics section of The Oregonian newspaper. He tells me to read the Foxtrot comic, so I do. And what do I find? I find the Foxtrot dude doing equations to calculate the trajectory of a snowball. That made my day! So I got the equations now...heeheehee

Here's a scan of the comic, with the formula circled:


The equation is not that simple, though, when you want it the other way around, with launch angle in terms of range/target distance. I calculated it as:


Unfortunately, as Hutch noted, spin and air resistance make it almost pointless to try to use a physics function, so you're probably better off with a best-fit polynomial anyway.

Bongle 08-02-2006 10:20

Re: Calculating Angle to fire at
 
If you ever end up with an equation like
f(x) = g(x)

and you're unable to isolate x, there are many fast ways to get good approximations for x.

Newton's Method
Rearrange it so that you have
f(x) - g(x) = 0
Now your problem is reduced to finding the zeroes of f(x)-g(x). This is still difficult, unless you're clever, like Newton was. If you take a tangent to this function at some point x1, then find the 0-intercept of that tangent, the x-position of that intercept is probably closer to the zero of (f[x] - g[x]) than your start point was. Call the tangent's intercept x2. Repeat this process from x2. Unless you picked your start position poorly, you should iteratively get closer.

Code example:
Code:

float fcn(float v,float d,float h,float t)
{        return 0.5*sin(2*t)*d - (G*d*d)/(2*v*v) - h*cos(t)*cos(t);
}
float der(float v,float d,float h,float t)
{        return cos(2*t)*d + 2*h*cos(t)*sin(t);
}
float getAngle(float v,float d,float h)
{
        // function: f[t] = 0.5*sin(2t)*d - gdd/2vv - hcoscos
        // derivative: f'[t] = cos(2t)*dist + 2h*cos*sin       
        float xn = PI/8; // I start at 22.5 degrees because I know the solution will be somewhere nearby
        for(int x=0;x<5;x++)
        {               
                xn = xn - fcn(v,d,h,xn)/der(v,d,h,xn);               
        }
        return xn;
}

In this code, I get close enough in just 5 iterations, and I could probably cut back on the iteration count. Note that this does not include any air resistance or spin or anything.


Also check out the wikipedia article on this: http://en.wikipedia.org/wiki/Newton's_method

Bongle 08-02-2006 10:39

Re: Calculating Angle to fire at
 
2 Attachment(s)
Here's a small application that demonstrates a calculation of firing angle.

The project zip file contains all the source code. It's meant for VC++ 6.0. If you want to use another IDE, you'll have to link comctl32.lib and figure out how to use the resource file.

ldeffenb 09-02-2006 10:01

Re: Calculating Angle to fire at
 
Quote:

Originally Posted by dlavery
If you like what you see with the camera system, please thank each of these folks for their efforts. If you don't like it, you can blame me.

Well stated and my personal hat goes off to their efforts. I know we tackled the camera last year and *almost* had it working, but using reflected light from non-controlled sources introduced just plain TOO MANY variables. The emitted green light this year will hopefully eliminate those vagaries.

Our only concern at this point is the light warm-up period. I'm sure hoping they have the lights on *BEFORE* autonomous begins. Our camera takes 17 seconds to "see the light" from a cold start. After warming up for a bunch of minutes, it will still recognize it nearly instantaneously after a 40 second off period.

If the lights are not kept on most of the time, I suspect that the initial autonomous action will be entertaining for the audience and disappointing to the programmers!

Lynn (D) - Team Voltage 386


All times are GMT -5. The time now is 00:09.

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