Fixed circular dependencies

This commit is contained in:
Pascal Serrarens 2025-06-04 14:49:47 +02:00
parent 5afe23ac66
commit 27e7f10589
6 changed files with 32 additions and 17 deletions

View File

@ -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 .
```

View File

@ -28,4 +28,4 @@ while True:
# Update the roboid state
bb2b.Update(True)
# and sleep for 100ms
time.sleep(100)
time.sleep(0.100)

View File

@ -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
"""

View File

@ -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

View File

@ -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

View File

@ -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