def executeTimestep(self,deltat): """This method is called by the simulator to advance the aircraft through time by an amount deltat (in seconds). The aircraft tries to acommodate the commands given to it.""" speed = self.commandSpeed if speed>ControllableAirplane.vmax: speed = ControllableAirplane.vmax elif speed<ControllableAirplane.vmin: speed = ControllableAirplane.vmin max_delta_altitude = speed*math.sin(ControllableAirplane.max_tilt)*deltat altitude = self.commandAltitude if altitude>ControllableAirplane.alt_max: altitude = ControllableAirplane.alt_max elif altitude<ControllableAirplane.alt_min: altitude = ControllableAirplane.alt_min current_heading = math.pi/2.0-self.velocity.phi # headings are between 0 and 2pi if current_heading < 0.0: current_heading += 2.0*math.pi current_altitude = self.position.z tilt_set = 0.0 delta_altitude = altitude - current_altitude if delta_altitude > max_delta_altitude: tilt_set = ControllableAirplane.max_tilt elif delta_altitude < max_delta_altitude and delta_altitude > -max_delta_altitude: tilt_set = math.asin(delta_altitude/speed/deltat) else: tilt_set = -ControllableAirplane.max_tilt heading_set = current_heading delta_heading = self.commandHeading - current_heading # Adjust turn so it can go through 2pi if delta_heading > math.pi: delta_heading -= 2.0*math.pi elif delta_heading < -math.pi: delta_heading += 2.0*math.pi max_delta_heading = ControllableAirplane.turn_rate*deltat if delta_heading > max_delta_heading: heading_set += max_delta_heading elif delta_heading < max_delta_heading and delta_heading > -max_delta_heading: heading_set += delta_heading else: heading_set -= max_delta_heading new_velocity = vector.sphvec(speed,math.pi/2.0-tilt_set,math.pi/2.0-heading_set) new_position = self.position+(self.velocity/2.0+new_velocity/2.0)*deltat self.velocity = new_velocity self.position = new_position
def generateCollidingPair(x, y, z, name1, name2, tcollision): """Create a set of airplanes which will collide at position x, y, z in tcollision seconds""" crashpos = vector.recvec(x, y, z) phi1 = -math.pi + random.random_sample() * 2.0 * math.pi phi2 = -math.pi + random.random_sample() * 2.0 * math.pi v = airplane.ControllableAirplane.vcruise v1 = vector.sphvec(v, math.pi / 2.0, phi1) v2 = vector.sphvec(v, math.pi / 2.0, phi2) pos1 = crashpos - v1 * tcollision pos2 = crashpos - v2 * tcollision airplane1 = airplane.ControllableAirplane(name1, pos1, v1) airplane2 = airplane.ControllableAirplane(name2, pos2, v2) return airplane1, airplane2
def generateRandomPlane(name,altitude): phi = -math.pi+random.random_sample()*2.0*math.pi dir_flight = phi+3.0*math.pi/4.0+random.random_sample()*math.pi/2.0 position = vector.cylvec(70000.0,phi,altitude) velocity = vector.sphvec(airplane.ControllableAirplane.vcruise,math.pi/2.0,dir_flight) return airplane.ControllableAirplane(name,position,velocity)
def generateCollidingPair(x,y,z,name1,name2,tcollision): """Create a set of airplanes which will collide at position x, y, z in tcollision seconds""" crashpos = vector.recvec(x,y,z) phi1 = -math.pi+random.random_sample()*2.0*math.pi phi2 = -math.pi+random.random_sample()*2.0*math.pi v = airplane.ControllableAirplane.vcruise v1 = vector.sphvec(v,math.pi/2.0,phi1) v2 = vector.sphvec(v,math.pi/2.0,phi2) pos1 = crashpos-v1*tcollision pos2 = crashpos-v2*tcollision airplane1 = airplane.ControllableAirplane(name1,pos1,v1) airplane2 = airplane.ControllableAirplane(name2,pos2,v2) return airplane1, airplane2