diff --git a/DoxyGen/DoxyWarnLogfile.txt b/DoxyGen/DoxyWarnLogfile.txt index 351e9b1..cd6bceb 100644 --- a/DoxyGen/DoxyWarnLogfile.txt +++ b/DoxyGen/DoxyWarnLogfile.txt @@ -1,4 +1,16 @@ warning: source 'images' is not a readable file or directory... skipping. +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:57: warning: @copybrief or @copydoc target 'Thing::Update' not found +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:46: warning: Found unknown command '@params' +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:22: warning: Member SetDriveDimensions(self, wheel_diameter, wheel_separation) (function) of class DifferentialDrive.DifferentialDrive is not documented. +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:33: warning: Member SetMotors(self, wheel_left, wheel_right) (function) of class DifferentialDrive.DifferentialDrive is not documented. +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:46: warning: Found unknown command '@params' +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:57: warning: @copybrief or @copydoc target 'Thing::Update' not found +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:19: warning: Member wheel_left (variable) of class DifferentialDrive.DifferentialDrive is not documented. +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:20: warning: Member wheel_right (variable) of class DifferentialDrive.DifferentialDrive is not documented. +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:46: warning: Found unknown command '@params' +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:47: warning: Found unknown command '@params' +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:57: warning: @copybrief or @copydoc target 'Thing::Update' not found +d:/Python/RoboidControl-python/Things/DifferentialDrive.py:58: warning: @copydetails or @copydoc target 'Thing::Update' not found d:/Python/RoboidControl-python/LocalParticipant.py:61: warning: Member GetParticipant(self, ip_address, port) (function) of class RoboidControl-python.LocalParticipant.LocalParticipant is not documented. d:/Python/RoboidControl-python/LocalParticipant.py:71: warning: Member AddParticipant(self, ip_address, port) (function) of class RoboidControl-python.LocalParticipant.LocalParticipant is not documented. d:/Python/RoboidControl-python/LocalParticipant.py:93: warning: Member SendThingInfo(self, thing) (function) of class RoboidControl-python.LocalParticipant.LocalParticipant is not documented. @@ -39,6 +51,25 @@ d:/Python/RoboidControl-python/Messages/ParticipantMsg.py:53: warning: Member Se d:/Python/RoboidControl-python/Messages/ParticipantMsg.py:64: warning: Member Publish(participant, network_id) (function) of class RoboidControl-python.Messages.ParticipantMsg.ParticipantMsg is not documented. d:/Python/RoboidControl-python/Messages/ParticipantMsg.py:41: warning: Member Serialized(buffer_ref, network_id) (function) of class RoboidControl-python.Messages.ParticipantMsg.ParticipantMsg is not documented. d:/Python/RoboidControl-python/Messages/ParticipantMsg.py:21: warning: Member network_id (variable) of class RoboidControl-python.Messages.ParticipantMsg.ParticipantMsg is not documented. +d:/Python/RoboidControl-python/SiteServer.py:42: warning: Member AddParticipant(self, ip_address, port) (function) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:49: warning: Member ProcessClientMsg(self, sender, msg) (function) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:56: warning: Member ProcessNetworkId(self, msg) (function) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:60: warning: Member Register(self, ThingClass, thing_type) (function) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:63: warning: Member Process(self, msg) (function) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:69: warning: Member ProcessThingMsg(self, msg) (function) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:20: warning: Member ip_address (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:21: warning: Member port (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:22: warning: Member publishInterval (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:23: warning: Member others (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:24: warning: Member network_id (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:25: warning: Member buffer (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:26: warning: Member thing_msg_constructors (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:29: warning: Member udp_socket (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:34: warning: Member thread (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:14: warning: Member name (variable) of class RoboidControl-python.SiteServer.SiteServer is not documented. +d:/Python/RoboidControl-python/SiteServer.py:18: warning: The following parameters of RoboidControl-python.SiteServer.SiteServer.__init__(self, port=7681, remote=False, udp_socket=None) are not documented: + parameter 'remote' + parameter 'udp_socket' d:/Python/RoboidControl-python/Thing.py:57: warning: Member update(self, currentTime) (function) of class RoboidControl-python.Thing.Thing is not documented. d:/Python/RoboidControl-python/Thing.py:60: warning: Member ProcessBinary(self, data) (function) of class RoboidControl-python.Thing.Thing is not documented. d:/Python/RoboidControl-python/Thing.py:38: warning: Member parent_id (variable) of class RoboidControl-python.Thing.Thing is not documented. diff --git a/Examples/BB2B.py b/Examples/BB2B.py index b37741d..adab8dc 100644 --- a/Examples/BB2B.py +++ b/Examples/BB2B.py @@ -1,3 +1,7 @@ +import sys +from os import path +sys.path.append(path.abspath(path.join(path.dirname(__file__), '..'))) + from Things.DifferentialDrive import DifferentialDrive from Things.TouchSensor import TouchSensor import time @@ -5,9 +9,9 @@ import time # The robot's propulsion is a differential drive bb2b = DifferentialDrive() # It has a touch sensor at the front left of the roboid -touch_left = TouchSensor(bb2b) +touch_left = TouchSensor(parent = bb2b) # and other one on the right -touch_right = TouchSensor(bb2b) +touch_right = TouchSensor(parent = bb2b) # Do forever: while True: diff --git a/Examples/BB2B_networking.py b/Examples/BB2B_networking.py new file mode 100644 index 0000000..327926b --- /dev/null +++ b/Examples/BB2B_networking.py @@ -0,0 +1,31 @@ +from LocalParticipant import LocalParticipant +from Things.DifferentialDrive import DifferentialDrive +from Things.TouchSensor import TouchSensor +import time + +# Create a local participant for handling communcation +# using default settings (UDP communciation over port 7681) +participant = LocalParticipant() +# The robot's propulsion is a differential drive +bb2b = DifferentialDrive(participant) +# It has a touch sensor at the front left of the roboid +touch_left = TouchSensor(bb2b) +# and other one on the right +touch_right = TouchSensor(bb2b) + +# Do forever: +while True: + # The left wheel turns forward when nothing is touched on the right side + # and turn backward when the roboid hits something on the right + wheel_speed_left = -600 if touch_right.touched_somthing else 600 + # The right wheel does the same, but instead is controlled by + # touches on the left side + wheel_speed_right = -600 if touch_left.touched_somthing else 600 + # When both sides are touching something, both wheels will turn backward + # and the roboid will move backwards + bb2b.SetWheelVelocity(wheel_speed_left, wheel_speed_right) + + # Update the roboid state + bb2b.Update(True) + # and sleep for 100ms + time.sleep(100) diff --git a/LinearAlgebra/Angle.py b/LinearAlgebra/Angle.py index 3fec226..5bb373b 100644 --- a/LinearAlgebra/Angle.py +++ b/LinearAlgebra/Angle.py @@ -1,10 +1,5 @@ import math class Angle: - @property - def Rad2Deg(self): - return 360 / (math.pi * 2) - - @property - def Deg2Rad(self): - return (math.pi * 2) / 360 \ No newline at end of file + Rad2Deg = 360 / (math.pi * 2) + Deg2Rad = (math.pi * 2) / 360 \ No newline at end of file diff --git a/LinearAlgebra/Direction.py b/LinearAlgebra/Direction.py index 5f89e22..24d04ff 100644 --- a/LinearAlgebra/Direction.py +++ b/LinearAlgebra/Direction.py @@ -2,8 +2,8 @@ import math class Direction: def __init__(self, horizontal=0, vertical=0): - self.horizontal = horizontal - self.vertical = vertical + self.horizontal: float = horizontal + self.vertical: float = vertical def __add__(self, other): return Direction(self.horizontal + other.x, self.vertical + other.y) diff --git a/LinearAlgebra/Spherical.py b/LinearAlgebra/Spherical.py index 110eea5..f32923f 100644 --- a/LinearAlgebra/Spherical.py +++ b/LinearAlgebra/Spherical.py @@ -3,8 +3,8 @@ from LinearAlgebra.Direction import Direction class Spherical: def __init__(self, distance, direction): - self.distance = distance - self.direction = direction + self.distance: float = distance + self.direction: Direction = direction # def __init__(self, distance, horizontal, vertical): # self.distance = distance diff --git a/README.md b/README.md index 8146233..3d9afa2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ -\mainpage Control Core for Python +\mainpage Roboid Control for Python -Control Core contain generic functionality for controlling Things \ No newline at end of file +Roboid Control support for Python applications +Supporting: +- Windows +- MacOS +- Linux +- MicroPython + +# Basic components + + +- \ref RoboidControl-python::Thing::Thing "Thing.Thing" +- \ref RoboidControl-python::LocalParticipant::LocalParticipant "LocalParticipant.LocalParticipant" +- \ref RoboidControl-python::SiteServer::SiteServer "SiteServer.SiteServer" \ No newline at end of file diff --git a/SiteServer.py b/SiteServer.py index 2d0ef18..35c9411 100644 --- a/SiteServer.py +++ b/SiteServer.py @@ -1,17 +1,23 @@ from LocalParticipant import LocalParticipant from Messages.ParticipantMsg import ParticipantMsg from Messages.NetworkIdMsg import NetworkIdMsg -from Sensors.TemperatureSensor import TemperatureSensor +from Things.TemperatureSensor import TemperatureSensor from Thing import Thing import socket import threading -class SiteServer(LocalParticipant): +class SiteServer(LocalParticipant): + """! A site server is a participant which provides a shared simulated environment + """ + name = "Site Server" - def __init__(self, ip_address="0.0.0.0", port=7681, remote=False, udp_socket = None): - self.ip_address = ip_address + def __init__(self, port=7681, remote=False, udp_socket = None): + """! Create a new site server + @param port The UDP port on which communication is received + """ + self.ip_address = "0.0.0.0" self.port = port self.publishInterval = 0 self.others = [] diff --git a/Thing.py b/Thing.py index d8533ac..a0b4635 100644 --- a/Thing.py +++ b/Thing.py @@ -43,13 +43,13 @@ class Thing: self.model_url = None ## The position of the thing in local space, in meters - self.position = Spherical.zero + self.position: Spherical = Spherical.zero ## The new orientation in local space - self.orientation = Quaternion.identity + self.orientation: Quaternion = Quaternion.identity ## The linear velocity of the thing in local space, in meters per second - self.linearVelocity = Spherical.zero + self.linear_velocity: Spherical = Spherical.zero ## The angular velocity of the thing in local space, in degrees per second - self.angularVelocity = Spherical.zero + self.angular_velocity: Spherical = Spherical.zero self.pose_updated = 0x00 # the bits indicate which fields have been updated diff --git a/Things/DifferentialDrive.py b/Things/DifferentialDrive.py index 04a3266..dc74f1d 100644 --- a/Things/DifferentialDrive.py +++ b/Things/DifferentialDrive.py @@ -16,8 +16,8 @@ class DifferentialDrive(Thing): ## The distance between the wheels in meters self.wheel_separation = 1.0 - self.wheel_left = None - self.wheel_right = None + self.wheel_left: Thing = None + self.wheel_right: Thing = None def SetDriveDimensions(self, wheel_diameter, wheel_separation): if wheel_diameter < 0: @@ -57,16 +57,18 @@ class DifferentialDrive(Thing): @copydoc Thing::Update """ # This assumes forward velocity only... - linear_velocity: Spherical = self.GetLinearVelocity().distance + linear_velocity: Spherical = self.linear_velocity.distance - angular_velocity: Spherical = self.GetAngularVelocity() + angular_velocity: Spherical = self.angular_velocity angular_speed: float = angular_velocity.distance * Angle.Deg2Rad # in radians/sec # Determine the rotation direction - if angular_velocity.direction.horizontal.InDegrees() < 0: + if angular_velocity.direction.horizontal < 0: angular_speed = -angular_speed - speed_left: float = (linear_velocity + angular_speed * self.wheel_left.GetPosition().distance) / self.wheel_radius * Angle.Rad2Deg - speed_right: float = (linear_velocity - angular_speed * self.wheel_right.GetPosition().distance) / self.wheel_radius * Angle.Rad2Deg + speed_left: float = 0 if self.wheel_left is None else \ + (linear_velocity + angular_speed * self.wheel_left.position.distance) / self.wheel_radius * Angle.Rad2Deg + speed_right: float = 0 if self.wheel_right is None else \ + (linear_velocity - angular_speed * self.wheel_right.position.distance) / self.wheel_radius * Angle.Rad2Deg self.SetWheelVelocity(speed_left, speed_right) diff --git a/Things/TouchSensor.py b/Things/TouchSensor.py index f202552..7e4ffd6 100644 --- a/Things/TouchSensor.py +++ b/Things/TouchSensor.py @@ -3,7 +3,7 @@ from Thing import Thing class TouchSensor(Thing): """! A sensor which can detect touches """ - def __init__(self, owner, parent): + def __init__(self, owner = None, parent = None): """! Create a touch sensor """ super().__init__(owner, parent)