Beispiel #1
0
 def find_theta(self, cart, rng, tol, zero):
   '''
   PURPOSE:
     Find the optimal theta to range in the rifle.
   INPUTS:
     Theta - angle (begins with 0.0 rad)
     dist  - target range in meters
     zero  - distance from zero (default 0.0)
   OUTCOME:
     Ballistics.theta is changed to optimal theta (err < 0.01 inches)
   '''
   cart.y = []  # initialize the history for (new) shot
   vx, vy  = func.vel_comp(cart.mv, cart.theta)
   cart.y0 = [0.0, vx, cart.traj[0], vy]
   self.model_integrate(cart)
   
   x = cart.y[:,0]           # x-position
   y = cart.y[:,2]           # y-position
   f = interp1d(x, y)
   xint = array([rng])
   yint = f(xint)
   print 'yErr:', yint[0], '\ttheta:', cart.theta, '\tzero:', zero
   yErr = yint[0]
   
   if (yErr < zero and yErr > zero - tol) or \
      (yErr > zero and yErr < zero + tol):
     None
   elif yErr > zero + tol:
     cart.theta = cart.theta - math.atan( (abs(yErr) + zero) / rng ) / 1.15
     self.find_theta(cart, rng, tol, zero)
   elif yErr < zero - tol:
     cart.theta = cart.theta + math.atan( (abs(yErr) + zero) / rng ) / 1.15
     self.find_theta(cart, rng, tol, zero)
Beispiel #2
0
 def fire_round(self, cart, theta, tol=1e-5, zero=0.0): 
   '''
   PURPOSE:
     Method to fire the rifle specified theta.
   INPUT:
     theta - the angle from the horizon to fire the rifle.
     zero  - distance from zero (default 0.0)
   OUTCOME:
     trajectory saved to Ballistics.x as a numpy array [x, vx, y, vy]
   '''
   cart.y = []  # initialize the history for (new) shot
   vx, vy  = func.vel_comp(cart.mv, theta)
   cart.y0 = [0.0, vx, cart.traj[0], vy]
   self.model_integrate(cart)