Fix BB2B issues

This commit is contained in:
Pascal Serrarens 2025-03-12 10:05:26 +01:00
parent 3892c2baeb
commit 26678c4ab1
11 changed files with 112 additions and 31 deletions

View File

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

View File

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

View File

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

View File

@ -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
Rad2Deg = 360 / (math.pi * 2)
Deg2Rad = (math.pi * 2) / 360

View File

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

View File

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

View File

@ -1,3 +1,15 @@
\mainpage Control Core for Python
\mainpage Roboid Control for Python
Control Core contain generic functionality for controlling Things
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"

View File

@ -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):
"""! 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 = []

View File

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

View File

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

View File

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