added option for rotation around theta to python visualizer

This commit is contained in:
Dirk Dokter
2012-09-24 12:13:08 +02:00
parent b069c66f97
commit 2b7b89a86f
+12 -4
View File
@@ -52,6 +52,8 @@ class Visualization:
self.airspeed = 0.0 self.airspeed = 0.0
self.display_list = None self.display_list = None
self.display_dirty = True self.display_dirty = True
self.rotate_theta = parent.rotate_theta
for message_name, index, name, bfp in VEHICLE_QUATS: for message_name, index, name, bfp in VEHICLE_QUATS:
self.quats.append(TelemetryQuat(message_name, index, name, bfp)) self.quats.append(TelemetryQuat(message_name, index, name, bfp))
for message_name, index, name, offset, scale, max in BAR_VALUES: for message_name, index, name, offset, scale, max in BAR_VALUES:
@@ -227,7 +229,8 @@ class Visualization:
try: try:
scaled_quat = [telemetry_quat.qi * telemetry_quat.scale, telemetry_quat.qx * telemetry_quat.scale, telemetry_quat.qy * telemetry_quat.scale, telemetry_quat.qz * telemetry_quat.scale] scaled_quat = [telemetry_quat.qi * telemetry_quat.scale, telemetry_quat.qx * telemetry_quat.scale, telemetry_quat.qy * telemetry_quat.scale, telemetry_quat.qz * telemetry_quat.scale]
glRotate(360 * math.acos(scaled_quat[0] ) / math.pi, scaled_quat[2], -scaled_quat[3], -scaled_quat[1]) glRotate(360 * math.acos(scaled_quat[0] ) / math.pi, scaled_quat[2], -scaled_quat[3], -scaled_quat[1])
glRotate(-90, 1, 0, 0) glRotate(self.rotate_theta, 1, 0, 0)
self.DrawVehicle(telemetry_quat.name) self.DrawVehicle(telemetry_quat.name)
except Exception: except Exception:
raise Exception raise Exception
@@ -237,7 +240,8 @@ class Visualization:
glPopMatrix() glPopMatrix()
class Visualizer: class Visualizer:
def __init__(self): def __init__(self, rotate_theta):
self.rotate_theta = rotate_theta
self.visualization = Visualization(self) self.visualization = Visualization(self)
# listen to Ivy # listen to Ivy
@@ -326,21 +330,25 @@ def run():
VEHICLE_QUATS = [ ["AHRS_REF_QUAT", 6, "Estimate", True], ["AHRS_REF_QUAT", 2, "Reference", True]] VEHICLE_QUATS = [ ["AHRS_REF_QUAT", 6, "Estimate", True], ["AHRS_REF_QUAT", 2, "Reference", True]]
BAR_VALUES = [ ["ROTORCRAFT_RADIO_CONTROL", 5, "Throttle (%%) %i", 0, 100, 100] ] BAR_VALUES = [ ["ROTORCRAFT_RADIO_CONTROL", 5, "Throttle (%%) %i", 0, 100, 100] ]
window_title = "Attitude_Viz" window_title = "Attitude_Viz"
rotate_theta = -90
try: try:
opts, args = getopt.getopt(sys.argv[1:], "t:", ["title"]) opts, args = getopt.getopt(sys.argv[1:], "t:r:", ["title", "rotate_theta"])
for o, a in opts: for o, a in opts:
if o in ("-t", "--title"): if o in ("-t", "--title"):
window_title = a window_title = a
if o in ("-r", "--rotate_theta"):
rotate_theta = int(a)
except getopt.error as msg: except getopt.error as msg:
print(msg) print(msg)
print("""usage: print("""usage:
-t, --title set window title -t, --title set window title
-r, --rotate_theta rotate the quaternion by n degrees over the pitch axis (default: -90)
""") """)
pygame.init() pygame.init()
screen = pygame.display.set_mode(SCREEN_SIZE, pygame.OPENGL|pygame.DOUBLEBUF) screen = pygame.display.set_mode(SCREEN_SIZE, pygame.OPENGL|pygame.DOUBLEBUF)
#resize(*SCREEN_SIZE) #resize(*SCREEN_SIZE)
init() init()
visualizer = Visualizer() visualizer = Visualizer(rotate_theta)
try: try:
while True: while True: