changeset 9:480ccfc8a57e

Display dms instead of m (for geo coords) Almost smooth climb/decent when using ATL command committer: Jeff Sipek <jeffpc@jeff.(none)> 1120765916 -0400
author Jeff Sipek <jeffpc@jeff.(none)>
date Thu, 07 Jul 2005 19:51:56 -0400
parents 8a4a829f1cc0
children 7bb4cd2fa1bc
files atc_plane.py
diffstat 1 files changed, 41 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/atc_plane.py	Thu Jul 07 02:47:26 2005 -0400
+++ b/atc_plane.py	Thu Jul 07 19:51:56 2005 -0400
@@ -29,6 +29,7 @@
 import atc_utils
 
 mperpix		= 750.0
+mperdeg		= 950.0
 
 def m2pix(m):
 	""" Meters to pixels conversion fn """
@@ -37,6 +38,9 @@
 def pix2m(pix):
 	""" Pixels to meters conversion fn """
 	return pix*mperpix
+	
+def pix2geo(pix):
+	return pix2m(pix)/mperdeg
 
 plane_OK	= 0
 plane_RANGE	= 1
@@ -45,9 +49,13 @@
 plane_DEAD	= 4
 plane_PROXY	= 5
 
-plane_PROP	= 16.667 # meters/sec
-plane_JET	= 62.572
-
+# all measurements in meters/sec or meters
+plane_PROP				= {"stall_speed": 16.667,
+								"climb_normal": 182.0,
+								"max_altitude": 6500.0}
+plane_JET				= {"stall_speed": 62.572,
+								"climb_normal": 900.0,
+								"max_altitude": 13000.0}
 
 class Plane(pygame.sprite.Sprite):
 	""" Class to manage one plane's motion """
@@ -73,13 +81,18 @@
 		self.Y		= m2pix(pos[1])
 		self.Z		= m2pix(pos[2])
 		
+		# target position
+		self.targetX = None
+		self.targetY = None
+		self.targetZ = None
+		
 		# velocity
 		self.i		= m2pix(vel[0])
 		self.j		= m2pix(vel[1])
 		self.k		= m2pix(vel[2])
 		
 		# plane specs
-		self.stallspeed	= m2pix(plane_PROP)
+		self.specs	= plane_PROP
 		
 		# status flag
 		self.status	= plane_OK
@@ -93,16 +106,21 @@
 		self.Y += self.j
 		self.Z += self.k
 		
-		if (self.X <= 0) or (self.Y <= 0): # FIXME: max values
+		# FIXME: need physics
+		if (self.targetZ != None) and (self.Z >= (self.targetZ - m2pix(50))) and (self.Z <= (self.targetZ + m2pix(50))):
+			self.k = 0
+			self.targetZ = None
+		
+		if (self.X < 0) or (self.Y < 0): # FIXME: max values
 			self.status = plane_RANGE
 		
-		if (self.Z <= 0):
+		if (self.Z < 0):
 			self.i = 0
 			self.j = 0
 			self.k = 0
 			self.status = plane_CRASHED
 		
-		if (self.calc_vel()<self.stallspeed) and (not self.status==plane_CRASHED):
+		if (self.calc_vel()<m2pix(self.specs["stall_speed"])) and (not self.status==plane_CRASHED):
 			self.status = plane_STALL
 		
 		self.rect.move(self.i,self.j)
@@ -136,6 +154,15 @@
 	def calc_rc(self):
 		""" Calculate rate of climb """
 		return atan(self.k/self.i)	# REDO!!
+		
+	def calc_geo(self, xy):
+		df = pix2geo(xy)
+		d  = floor(df)
+		mf = (df-d) * 60.0
+		m  = floor(mf)
+		s  = (mf-m) * 60.0
+		
+		return "%dd %02dm %02ds" % (int(d), int(m), int(s))
 	
 	def recalc_vel(self,vel,heading,rc):
 		""" Set velocity to new value """
@@ -148,9 +175,10 @@
 		
 		if (parts[0] == "ALT"):
 			print "Changing altitude to " + parts[1] + "m"
-			# FIXME: change altitude SLOWLY, accodring to laws of physics
-			self.Z = m2pix(int(parts[1]))
-			self.k = 0
+			self.targetZ = m2pix(int(parts[1]))
+			self.k = m2pix(self.specs["climb_normal"])
+			if (self.Z > self.targetZ):
+				self.k *= -1
 	
 	def display(self,screen):
 		""" Put everything onto the screen """
@@ -166,12 +194,12 @@
 		x = int(self.X) + 10
 		y = int(self.Y) - 5
 		
-		# FIXME: display geographic coordinates
+		# FIXME: display geographic coordinates with NSWE appended/prepended
 		strings = (	self.flightno,
 				self.callsign + " " + str(self.status),
 				"Alt:  " + str(int(pix2m(self.Z))),
-				"Lat:  " + str(int(pix2m(self.X))),
-				"Long: " + str(int(pix2m(self.Y))),
+				"Lat:  " + self.calc_geo(self.X),
+				"Long: " + self.calc_geo(self.Y),
 				"Head: " + str(int(atc_utils.todeg(self.calc_head()))))
 		
 		for stri in strings: