From 27e7f1058935b0eb8f7b12da097f3c53c941cb0a Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 4 Jun 2025 14:49:47 +0200 Subject: [PATCH] Fixed circular dependencies --- README.md | 14 ++++++++++++-- RoboidControl/Examples/BB2B.py | 2 +- RoboidControl/Participant.py | 16 ++++++++++------ RoboidControl/Thing.py | 9 +++++---- RoboidControl/Things/DifferentialDrive.py | 4 ++-- RoboidControl/Things/TouchSensor.py | 4 ++-- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index f0a003e..479e974 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,18 @@ Supporting: # Install -- Go to the root folder of this repository (the folder containing this `README.md` and `setup.py`) -- Execute the command. +You can install the package directly from the git server using pip: +``` +pip install git+https://git.passer.life/RoboidControl/RoboidControl-python.git +``` +If you want to use a specific branch, you can use +``` +pip install git+https://git.passer.life/RoboidControl/RoboidControl-python.git@v0.4_dev +``` + +Alternatively you can clone the repo to a folder in you project. +Then you can install it by going to the root folder of the repository (the folder containing this `README.md` and `setup.py`) +and execute the command. ``` pip install . ``` diff --git a/RoboidControl/Examples/BB2B.py b/RoboidControl/Examples/BB2B.py index 27c223e..2ab970c 100644 --- a/RoboidControl/Examples/BB2B.py +++ b/RoboidControl/Examples/BB2B.py @@ -28,4 +28,4 @@ while True: # Update the roboid state bb2b.Update(True) # and sleep for 100ms - time.sleep(100) + time.sleep(0.100) diff --git a/RoboidControl/Participant.py b/RoboidControl/Participant.py index 0899d11..adc208b 100644 --- a/RoboidControl/Participant.py +++ b/RoboidControl/Participant.py @@ -1,4 +1,4 @@ -from RoboidControl.Thing import Thing +#from RoboidControl.Thing import Thing from typing import Union, Optional @@ -13,7 +13,7 @@ class Participant: # region Init - #local_participant = None + local_participant = None def __init__(self, ip_address: str = None, port: int = None) -> None: """! Create a new participant with the given communcation info @@ -30,16 +30,20 @@ class Participant: self.network_id: int = 0 ## The things managed by this participant - self.things: set[Thing] = set() + self.things: set['Thing'] = set() + from RoboidControl.Thing import Thing Thing.CreateRoot(self) self.buffer: bytearray = bytearray(256) + def GetLocalParticipant(): + return Participant.local_participant + def ReplaceLocalParticipant(newParticipant: 'Participant'): Participant.localParticipant = newParticipant - def Get(self, thing_id: int) -> Optional[Thing]: + def Get(self, thing_id: int) -> Optional['Thing']: """! Get the thing with the given properties @param thing_id The ID of the thing @@ -50,7 +54,7 @@ class Participant: return thing return None - def Add(self, thing: Thing, check_id: bool = True): + def Add(self, thing: 'Thing', check_id: bool = True): """! Add a new thing for this participant. @param thing The thing to add @param check_id If true, the thing.id is regenerated if it is zero @@ -63,7 +67,7 @@ class Participant: if found_thing == None: self.things.add(thing) - def Remove(self, thing: Thing) -> None: + def Remove(self, thing: 'Thing') -> None: """! Remove a thing for this participant @param thing The thing to remove """ diff --git a/RoboidControl/Thing.py b/RoboidControl/Thing.py index c1713eb..1686f01 100644 --- a/RoboidControl/Thing.py +++ b/RoboidControl/Thing.py @@ -74,7 +74,8 @@ class Thing: # self.owner.Add(self) missing???? else: if parent is None: - self.SetParent(Thing.LocalRoot()) + from RoboidControl.Participant import Participant + self.SetParent(Participant.local_participant.root) else: self.SetParent(parent) @@ -110,9 +111,9 @@ class Thing: def CreateRoot(owner: 'Participant'): owner.root = Thing(owner = owner) - def LocalRoot() -> 'Thing': - participant = participant.localParticipant - return participant.root + # def LocalRoot() -> 'Thing': + # participant = Participant.GetLocalParticipant() + # return participant.root # endregion Init diff --git a/RoboidControl/Things/DifferentialDrive.py b/RoboidControl/Things/DifferentialDrive.py index 2e8b3c4..aa20b8b 100644 --- a/RoboidControl/Things/DifferentialDrive.py +++ b/RoboidControl/Things/DifferentialDrive.py @@ -7,10 +7,10 @@ class DifferentialDrive(Thing): """! A thing which can move itself using a differential drive system @sa @link https://en.wikipedia.org/wiki/Differential_wheeled_robot @endlink """ - def __init__(self, owner = None, parent = None, thing_id = 0): + def __init__(self, owner = None, parent = None): """! Create a differential drive """ - super().__init__(owner = owner, parent = parent, thing_type = Thing.Type.DifferentialDrive, thing_id = thing_id) + super().__init__(owner = owner, parent = parent) ## The radius of a wheel in meters self.wheel_radius = 1.0 diff --git a/RoboidControl/Things/TouchSensor.py b/RoboidControl/Things/TouchSensor.py index c996c84..85a2c73 100644 --- a/RoboidControl/Things/TouchSensor.py +++ b/RoboidControl/Things/TouchSensor.py @@ -6,8 +6,8 @@ class TouchSensor(Thing): def __init__(self, owner = None, parent = None, thing_id = 0): """! Create a touch sensor """ - super().__init__(owner = owner, parent = parent, thing_type = Thing.Type.TouchSensor, thing_id = thing_id) - + super().__init__(owner = owner, parent = parent) + self.type = Thing.Type.TouchSensor ## Value which is true when the sensor is touching something, false otherwise self.touched_something = False