from LinearAlgebra.Spherical import * from LinearAlgebra.Quaternion import * from LinearAlgebra.SwingTwist import * from Messages import * class Thing: """! A thing is the basic building block""" class Type: """! Predefined thing types """ Undetermined = 0x00 # Sensor Switch = 0x01 DistanceSensor = 0x02 DirectionalSensor = 0x03 TemperatureSensor = 0x04 TouchSensor = 0x05 # Motor ControlledMotor = 0x06 UncontrolledMotor = 0x07 Servo = 0x08 # Other Roboid = 0x09 Humanoid = 0x10 ExternalSensor = 0x11 Animator = 0x40 Position = 0x01 Orientation = 0x02 LinearVelocity = 0x04 AngularVelocity = 0x08 def __init__(self, owner = None, thing_id = 0, type = Type.Undetermined, parent = None, name = None): """! Create a new thing """ ## The parent thing self.parent = None if parent is not None: owner = parent.owner self.SetParent(parent) elif owner == None: from ParticipantUDP import ParticipantUDP owner = ParticipantUDP.Isolated() self.children = [] ## The participant owning this thing self.owner = owner ## The ID of the thing self.id = thing_id ## The type of the thing self.type = type ## The name of the thing self.name = name ## An URL pointing to the location where a model of the thing can be found self.model_url = None ## The position of the thing in local space, in meters self.position: Spherical = Spherical.zero self.position_updated: bool = False ## The new orientation in local space self.orientation: Quaternion = Quaternion.identity self.orientation_updated: bool = False ## The linear velocity of the thing in local space, in meters per second self.linear_velocity: Spherical = Spherical.zero self.linear_velocity_updated: bool = False ## The angular velocity of the thing in local space, in degrees per second self.angular_velocity: Spherical = Spherical.zero self.angular_velocity_updated: bool = False #self.pose_updated = 0x00 # the bits indicate which fields have been updated self.owner.Add(self) def SetPosition(self, position): """! Set the position of the thing @param position The new position in local space, in meters """ self.position = position self.position_updated = True def SetOrientation(self, orientation): """! Set the orientation of the thing @param orientation The new orientation in local space """ self.orientation = orientation self.orientation_updated = True def SetLinearVelocity(self, linear_velocity): """! Set the linear velocity of the thing @param linearVelocity The new linear velocity in local space, in meters per second """ if self.linear_velocity != linear_velocity: self.linear_velocity_updated = True self.linear_velocity = linear_velocity def SetAngularVelocity(self, angular_velocity): """! Set the angular velocity of the thing @param angularVelocity the new angular velocity in local space """ if self.angular_velocity != angular_velocity: self.angular_velocity_updated = True self.angular_velocity = angular_velocity def Update(self, currentTime, recurse = False): self.position_updated = False self.orientation_updated = False self.linear_velocity_updated = False self.angular_velocity_updated = False if recurse: for child in self.children: if child is None: continue child.Update(currentTime, recurse) def SetParent(self, parent): if parent is None: parentThing = self.parent if parentThing is not None: parentThing.RemoveChild(self) self.parent = None else: parent.AddChild(self) def AddChild(self, child): if child in self.children: return child.parent = self self.children.append(child) def RemoveChild(self, child): self.children.remove(child) def GenerateBinary(self, buffer, ix_ref) -> int: return 0 def ProcessBinary(self, data): print('default binary processor') pass