Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Trajectory Calculator (W/ Drag) (http://www.chiefdelphi.com/forums/showthread.php?t=100965)

JesseGR 23-01-2012 15:49

Trajectory Calculator (W/ Drag)
 
Hello, my name is Jesse and I am a programmer from team 3539. In a few hours of downtime I had between our current projects, I applied a few physics formulas to a Java application and made a calculator that can accurately determine the path of an object when fired at an angle and a velocity, among other things.

http://img841.imageshack.us/img841/9954/77059684.png (Screenshot)
http://www.box.com/s/svmj0ln7vvzdh27pqckv (Download)

The ideal "Calculations per Second" setting is 5000, make sure you change it from the default of 5.

Enjoy.

Ether 23-01-2012 18:02

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by JesseGR (Post 1112020)
applied a few physics formulas to a Java application and made a calculator that can accurately determine the path of an object when fired at an angle and a velocity

How do you know it is accurate? i.e. what test data did you use to validate your model?


SenorZ 23-01-2012 18:07

Re: Trajectory Calculator (W/ Drag)
 
I can't seem to run this on my computer. Cannot find main class...?

Either way those curves don't look like there is any drag. Did you physically measure the air drag coefficient?

shuhao 23-01-2012 18:12

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by Ether (Post 1112109)
How do you know it is accurate? i.e. what test data did you use to validate your model?


Check it against mine?

I also wrote something about 2 weeks back. This one is in GNU Octave/Matlab

https://github.com/FRCTeam4069/Simul...sketball_sim.m

Lalaland1125 23-01-2012 22:18

Re: Trajectory Calculator (W/ Drag)
 
Our team started working on the same idea(manually integrate the drag + projectile formulas to calculate the projectile path)(http://ideone.com/aoChY, but we haven't quite gotten it to the level of completeness you did.


This is going to require a lot of testing to get the constants right though(and to see if it is accurate at all).

(Also, no offense, but I would heavily suggest for you to refactor your code. All of those functions with repeated code and the whole "god" class is going to make things hard to modify and debug later on)

robokiller 23-01-2012 23:41

Re: Trajectory Calculator (W/ Drag)
 
I really want to play with a couple of these programs but yours is not working on my computer
"could not find main class: Main program will exit"

Ether 25-01-2012 22:38

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by shuhao (Post 1112121)
Check it against mine? I also wrote something about 2 weeks back.

what test data did you use to validate your model?


Joe Ross 25-01-2012 22:58

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by shuhao (Post 1112121)
Check it against mine?

I also wrote something about 2 weeks back. This one is in GNU Octave/Matlab

Comparing a model to a model doesn't prove that either is correct. It only proves that they included similar factors, not that they included the correct factors (and factored them in correctly). The only way to validate a model is to compare it to actual test data.

shuhao 26-01-2012 00:01

Quote:

Originally Posted by Ether (Post 1113654)
what test data did you use to validate your model?


I was making a joke .... cmon..

Ed Law 26-01-2012 00:42

Re: Trajectory Calculator (W/ Drag)
 
Due to the relative light weight to the size of the ball this year, trajectory calculation this year cannot ignore air resistance and it also cannot ignore back spin for those who are using a single wheel. Back spin make the ball travel higher and further.

If you ignore air resistance or back spin and try to correlate to real test data by scaling the exit velocity, it would be meaningless. Adding air rsistance to your calculation would be an improvement because you have the shape constant to tune but you are still ignoring an important factor which is the back spin. The back spin is significant especially when you are shooting from far away.

I will be posting my trajectory calculator (in Excel) on our website soon. You can look at the calculator for 2008 and 2010.

We have not done tuning yet. Our robot will not be done for another 2 weeks.

gnunes 01-02-2012 22:49

Re: Trajectory Calculator (W/ Drag)
 
1 Attachment(s)
Here is a LabView trajectory calculator including the effects of drag and spin. You can adjust how much drag and how much spin (and whether it is back spin or top spin). You can also change which hoop you are aiming for and the height of your shooter exit point.

I've not tested it against any measurements, but the physics of spinning balls has been extensively studied, so it should at least be close. The biggest approximation is for the lift coefficient, where I have used a very simple model, and assumed that the spin does not slow during the flight. If you want to see what a complicated model for lift looks like, read the AJP paper referenced on the block diagram, where he develops an empirical model for spinning tennis balls...

Bendito 14-02-2012 19:30

Re: Trajectory Calculator (W/ Drag)
 
Now, the real question is, how do we have this trajectory calculator solve for angle if the velocity is constant?

engunneer 15-02-2012 09:23

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by Bendito (Post 1126704)
Now, the real question is, how do we have this trajectory calculator solve for angle if the velocity is constant?

That part is really tricky. What I did in my calc (which does not do drag!) was to have it iterate the angle until the calculated path went through the target basket. I did this using Excel's goalseek function. Then you make a table of different ranges to shoot from, and graph it. Add a trendline to generate an approximate formula for that velocity (I used Order 3 polynomial to get a high R^2 value). That simplified formula is what you would integrate with your robot code if you wanted to automate the angle.

Ether 15-02-2012 09:42

Re: Trajectory Calculator (W/ Drag)
 
1 Attachment(s)
Quote:

Originally Posted by engunneer (Post 1127104)
That part is really tricky. What I did in my calc (which does not do drag!) was to have it iterate the angle until the calculated path went through the target basket. I did this using Excel's goalseek function.

It's not tricky if you're ignoring drag and magnus effect (backspin)1. There's an explicit closed-form solution. See the last two equations on page 2 of the attachment.


1 of course, ignoring drag and backspin is probably not a valid assumption for this case. see post#10.

Bendito 15-02-2012 12:05

Re: Trajectory Calculator (W/ Drag)
 
Yes, I already have vision tracking getting a distance, using trigonometry to find the base of the triangle (distance of launcher parallel to the floor to the hoops) from the hypotenuse (distance of vision target from camera) and the opposite side (the known height of the hoop) and running it through an equation found on wikipedia to find angles to hit a target point (x,y). It has not been tested on the robot, but the math and plotted trajectories it outputs look sound.



I am trying to incorporate drag into this, however, it seems incredibly complicated, based on the vi's mentioned earlier. Compensating for air resistance within a set range might practically be accomplished through adding an arbitrary number to the x and y in that equation based on trial and error. There are some good drag equations on this page, too, though.

http://en.wikipedia.org/wiki/Trajectory_of_a_projectile

Edit: Use regressions and plot out the real world values to find an equation? IE. A function of angle on the Y axis and how far it travels until contacting ground (possibly set at a particular height, such as the top hoop) on the X (or vice versa)

gnunes 15-02-2012 12:53

Re: Trajectory Calculator (W/ Drag)
 
Yes, drag is complicated, but also important. If your launcher spins the ball, then lift is important too.

If you don't want this complication, then your best approach is empirical. Get a lot of data on distance vs. your launch parameters and make a table. Then, the robot can use interpolation to work the other way: given a distance, it can get values for the launch parameters. If you are varying two things (launch angle and ball velocity), then this could get complicated. You will have several tables, and will need an algorithm to determine which one to use.

Even though I wrote the trajectory calculator, our team is going to use the interpolation approach!

engunneer 15-02-2012 13:06

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by gnunes (Post 1127313)
Get a lot of data on distance vs. your launch parameters and make a table. Then, the robot can use interpolation to work the other way: given a distance, it can get values for the launch parameters.

This is pretty much our plan.

Hinfoiltat 15-02-2012 19:29

Re: Trajectory Calculator (W/ Drag)
 
I would appreciate a video of this in action.

Brandon_L 22-02-2012 02:40

Re: Trajectory Calculator (W/ Drag)
 
I see a formula for finding the angle to launch at with a constant velocity, but I can't find the opposite (Velocity to launch at with a constant angle) anywhere for the life of me. Does anyone know/have it? I've been going through my kinematic equations for the past 6 hours (I kid you not) and have nothing

Ether 22-02-2012 09:11

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by Brandon_L (Post 1132341)
I see a formula for finding the angle to launch at with a constant velocity, but I can't find the opposite (Velocity to launch at with a constant angle) anywhere for the life of me. Does anyone know/have it? I've been going through my kinematic equations for the past 6 hours (I kid you not) and have nothing

Let
Code:

d = horizontal distance (in feet) from launch point to hoop

h = vertical height (in feet) of hoop above the launch point

a = angle of launch (radians) above the horizontal

v = initial speed of ball (in ft/sec) as it leaves the launcher

Then the no-drag, no magnus formula for speed is:
Code:

v = 4*d/(cos(a)*sqrt(d*tan(a)-h))


Lalaland1125 22-02-2012 10:02

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by Brandon_L (Post 1132341)
I see a formula for finding the angle to launch at with a constant velocity, but I can't find the opposite (Velocity to launch at with a constant angle) anywhere for the life of me. Does anyone know/have it? I've been going through my kinematic equations for the past 6 hours (I kid you not) and have nothing

Our plan is to simply do the simple drag-free formula for an initial guess, and then slowly increase the velocity till the non-reversible drag including formula "hits" the target.

The computers are definitely fast enough for this, but who knows if the ball actually acts like its supposed to.

gnunes 22-02-2012 14:03

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by Lalaland1125 (Post 1132467)
Our plan is to...slowly increase the velocity till the non-reversible drag including formula "hits" the target.

The problem is that there is no "formula" for the case where drag is included. If you are using LabView, then you could take my trajectory calculator (see post #11) and turn it into a sub-VI that would find the distance for you (just cut out all the graphing stuff which you won't need).

I would recommend using the trajectory calculator "off-line" to calculate the distance for, say 100 or 200 launch velocities between your fastest and slowest launch speeds. Then store that table of distance vs launch speed in your competition code, and use interpolation to find the velocity you want in a single pass. Much, much faster.

Ether 22-02-2012 16:58

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by Lalaland1125 (Post 1132467)
Our plan is to simply do the simple drag-free formula for an initial guess, and then slowly increase the velocity till the non-reversible drag including formula "hits" the target.

Quote:

Originally Posted by gnunes (Post 1132662)
The problem is that there is no "formula" for the case where drag is included.

For a drag model where drag is either linear or quadratic in velocity, I believe there is a closed form solution* for height, given distance, launch angle, drag coefficient, and launch velocity. So you could vary the launch velocity and calculate the height until the height is the desired value.

I'm not saying that's the best way to do it, but it could be done.


* I haven't checked it. It's rather ugly.


Ether 22-02-2012 19:53

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by Ether (Post 1132806)
* I haven't checked it. It's rather ugly.

Here it is, if anyone wants to try it or check my math. I'm sure this could be simplified with a bit of work. Maybe even solved explicitly for Vo?

Code:

h=log(1-Vo^2*K/g)/(2*K)-log(sec(sqrt(-g)*sqrt(K)*((%e^(d*K)-1)/(cos(theta)*Vo*K)-atan((Vo*sqrt(K))/sqrt(-g))/(sqrt(-g)*sqrt(K)))))/K;
See attached PDF for derivation.



Ether 22-02-2012 22:58

Re: Trajectory Calculator (W/ Drag)
 


@gnunes: can you run your trajectory program with the following parameters, and post height vs distance data (say, every foot) and a PNG of a plot of height (above the launch point, in feet) vs distance (horizontal distance from the launch point) with the following parameters: Vo=23 feet/sec, theta=45 degrees, g=-32 ft/sec2, drag = -0.03*V2 ft/sec2, and no spin?



Lalaland1125 23-02-2012 19:56

Re: Trajectory Calculator (W/ Drag)
 
2 Attachment(s)
I ran your numbers through my dead simple approximator(code at bottom) and got a different result(image + source code is attached)

I am fairly sure that your result cannot be correct due to running it through the standard projectile motion equations.

Assuming no loss of energy, the ball will follow the equation: .5*Vy^2 = g * h.
(mgh = 1/2 * m * v^2)

Plugging this into wolfram alpha(http://www.wolframalpha.com/input/?i=%28%2823+feet+per+second+in+meters+*+sin%2845+d egrees%29%29+**+2++*+.5+%29%2F9.8+meters+per+secon d+squared) ( using meters because I am more used to them) gets me 4.113 ft as the max possible height. Your graph shows the ball approaching 7 m.

(When I set the drag to 0 on my code the height reaches a max of about 4ft and change)

Oh, and the code attachment shows what I mean by trial and error. Look at findBestCurveWithin.

Code:

void calcY(double& x,double& y, double &xVel, double& yVel)
{
  double oldxVel = xVel;
  double oldyVel = yVel;


  xVel += drag * xVel * xVel * timeIncrement;
  yVel += (g + drag * yVel * yVel) * timeIncrement;

  x += oldxVel * timeIncrement + .5 * timeIncrement * (xVel - oldxVel);
  y += oldyVel * timeIncrement + .5 * timeIncrement * (yVel - oldyVel);
}

QVector<QPointF> findCurve(double velocity, double angle, double targetX)
{
  QVector<QPointF> result;

  double rads = angle * M_PI/180;
  double xVel = velocity * cos(rads);
  double yVel = velocity * sin(rads);
  double x = 0;
  double y = 0;

  do
  {
      calcY(x,y,xVel,yVel);
      result.push_back(QPointF(x,y));
  }
  while (fabs(x - targetX) > .01);


  return result;
}


Ether 23-02-2012 20:46

Re: Trajectory Calculator (W/ Drag)
 
Quote:

Originally Posted by Lalaland1125 (Post 1133691)
I ran your numbers through my dead simple approximator(code at bottom) and got a different result(image + source code is attached)

Thank you. I have should have caught that.

Code:

x3: Vo =subst(0,t,rhs(x2));  <= a small typo on Page 2
x3: Vyo=subst(0,t,rhs(x2));  <= should have been

I'll see if a closed-form solution is still possible with this correction.




All times are GMT -5. The time now is 18:46.

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