def On_PluginInit(self): self.DefaultVector = Vector3(0, 0, 0) self.Quat = Quaternion(0, 0, 0, 1) Commands.Register("attach")\ .setCallback("attach")\ .setDescription("your description here")\ .setUsage("The usage here") Commands.Register("attanimal")\ .setCallback("attanimal")\ .setDescription("your description here")\ .setUsage("The usage here") Commands.Register("detach")\ .setCallback("detach")\ .setDescription("your description here")\ .setUsage("The usage here") Commands.Register("test")\ .setCallback("test")\ .setDescription("your description here")\ .setUsage("The usage here")
def world_to_local_y_rot(self, v): # rotate vector with the vehicle's current yaw quat = Quaternion.Inverse(self.quat_ry) return quat * v
def quat_ry(self): return Quaternion.Euler(Vector3(0, self.rotation.y, 0))
def update(self): self.dt = Time.deltaTime if self.dt == 0: return if self._first_update: self.home = self.core.Position if self.core_height is None: self.core_height = self.core.Position.y # Besiege.ClearMarks() # ClearMarks is broken self._first_update = False return # check for key press events and respective callbacks self.update_keys() # get the current relative angular velocity self.rate = Quaternion.Inverse( self.core.RotationQuaternion) * self.core.AngularVelocityDeg # get the current relative angles self.rotation = self.core.Rotation # get the current world position self.position = self.core.Position # get the current axes values self.controls = self.get_controls() # A mode function can return None if it's delegating to # another mode. In that case, we loop until we get a power # adjustment response power = None while power is None: power = self.mode(*self.controls) Besiege.Watch('dt', self.dt) Besiege.Watch('mode', self.mode.__name__) # using Vector4 merely for the nice string repr Besiege.Watch('controls', Vector4(*self.controls)) Besiege.Watch('rotation', self.rotation) Besiege.Watch('rotation_sp', self.rotation_sp) Besiege.Watch('position', self.position) Besiege.Watch('position_sp', self.position_sp) Besiege.Watch('position_sp_local', self.position_sp_local) Besiege.Watch('position_sp_distance', self.position_sp_distance) Besiege.Watch('rate', self.rate) Besiege.Watch('rate_sp', self.rate_sp) Besiege.Watch('velocity', self.velocity) Besiege.Watch('velocity_sp', self.velocity_sp) # get ASL and real altitude Besiege.Watch('altitude', Vector2(self.position.y, self.position.y - self.terrain)) self.set_power(*power)
def world_to_local(self, v): quat = Quaternion.Inverse(self.quat) return quat * v
def quat(self): return Quaternion.Euler(self.rotation)
def update(self): self.dt = Time.deltaTime if self.dt == 0: return if self._first_update: # self.home = self.core.Position # if self.core_height is None: # self.core_height = self.core.Position.y # Besiege.ClearMarks() # ClearMarks is broken self._first_update = False return # check for key press events and respective callbacks self.update_keys() # get the current relative angular velocity self.rate = Quaternion.Inverse(self.core.RotationQuaternion) * self.core.AngularVelocityDeg # get the current relative angles self.rotation = self.core.Rotation # get the current world position self.position = self.core.Position # get the current axes values self.controls = self.get_controls() # self.get_collisions() # A mode function can return None if it's delegating to # another mode that was appended to the stack, or if it's # leaving the top of the stack. In that case, we loop until we # get a power adjustment response adjs = None while adjs is None: adjs = self.mode[-1](*self.controls) Besiege.Watch('dt', self.dt) Besiege.Watch('mode', self.mode[-1].__name__) Besiege.Watch('yaw_mode', self.yaw_mode.__name__ if self.yaw_mode else 'none') Besiege.Watch('controls', pretty(self.controls)) Besiege.Watch('rate', self.rate) Besiege.Watch('rate_sp', self.rate_sp) Besiege.Watch('rotation', self.rotation) Besiege.Watch('rotation_sp', self.rotation_sp) Besiege.Watch('position', self.position) Besiege.Watch('position_sp', self.position_sp) Besiege.Watch('position_sp_local', self.position_sp_local) Besiege.Watch('position_sp_distance', self.position_sp_distance) Besiege.Watch('velocity', self.velocity) Besiege.Watch('velocity_sp', self.velocity_sp) # get ASL and real altitude Besiege.Watch('altitude', Vector2(self.position.y, self.position.y - self.terrain)) self.set_power(**self.get_power(*adjs))