#!/usr/bin/env python ''' Python interface to CRRCSIM simulator ''' from aircraft import Aircraft import util, time, struct import socket, select from math import degrees, radians, sin, cos from rotmat import Vector3, Matrix3 class CRRCSim(Aircraft): '''a CRRCCIM shim''' def __init__(self, frame="generic"): Aircraft.__init__(self) self.sim = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sim.connect(('127.0.0.1', 9002)) self.sim.setblocking(0) self.accel_body = Vector3(0, 0, -self.gravity) self.frame = frame self.last_timestamp = 0 if self.frame.find("heli") != -1: self.decode_servos = self.decode_servos_heli else: self.decode_servos = self.decode_servos_fixed_wing def decode_servos_heli(self, servos): '''decode servos for heli''' swash1 = servos[0] swash2 = servos[1] swash3 = servos[2] tail_rotor = servos[3] rsc = servos[7] col_pitch = (swash1+swash2+swash3)/3.0 - 0.5 roll_rate = (swash1 - swash2)/2 pitch_rate = -((swash1 + swash2)/2.0 - swash3)/2 yaw_rate = -(tail_rotor - 0.5) rsc_speed = rsc buf = struct.pack(' 0: self.adjust_frame_time(1.0/deltat) self.last_timestamp = timestamp def update(self, actuators): '''update model''' self.decode_servos(actuators) self.recv_fdm() self.update_position()