Base
Module for the RobotBase abstract class.
This module defines an abstract base class, RobotBase, that provides a template for a robot
system integrating actuators and sensors. The class supports context management and defines
abstract methods for starting, stopping, and updating the robot's components.
RobotBase
¶
Bases: ABC, Generic[TActuator, TSensor]
Abstract base class representing a robot composed of actuators and sensors.
This class provides the basic structure for a robot, including methods to start, stop, and update its components. It also supports context management so that the robot can be used within a with-statement to automatically start and stop its components.
This class is generic and can be parameterized with actuator and sensor types that must be subclasses of ActuatorBase and SensorBase respectively.
Attributes:
| Name | Type | Description |
|---|---|---|
actuators |
dict[str, TActuator]
|
A dictionary mapping actuator names to actuator instances. |
sensors |
dict[str, TSensor]
|
A dictionary mapping sensor names to sensor instances. |
Source code in opensourceleg/robots/base.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
tag
property
¶
Get the unique identifier (tag) of the robot.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The robot's tag. |
Example
robot = MyRobot() robot.tag "my_robot"
__enter__()
¶
Enter the runtime context for the robot.
This method starts all actuators and sensors and returns the robot instance.
Returns:
| Name | Type | Description |
|---|---|---|
RobotBase |
RobotBase
|
The current robot instance. |
Example
with MyRobot() as robot: ... robot.update()
Source code in opensourceleg/robots/base.py
__exit__(exc_type, exc_val, exc_tb)
¶
Exit the runtime context for the robot.
This method stops all actuators and sensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
Any
|
The exception type, if an exception occurred. |
required |
exc_val
|
Any
|
The exception value, if an exception occurred. |
required |
exc_tb
|
Any
|
The traceback, if an exception occurred. |
required |
Source code in opensourceleg/robots/base.py
__init__(tag, actuators, sensors)
¶
Initialize the RobotBase instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
A unique identifier for the robot. |
required |
actuators
|
dict[str, TActuator]
|
A dictionary of actuators keyed by their names. |
required |
sensors
|
dict[str, TSensor]
|
A dictionary of sensors keyed by their names. |
required |
Source code in opensourceleg/robots/base.py
start()
abstractmethod
¶
Start all actuators and sensors.
For each actuator in the actuators dictionary, a debug message is logged and its start method is called. Similarly, for each sensor in the sensors dictionary, a debug message is logged and its start method is called.
Returns:
| Type | Description |
|---|---|
None
|
None |
Example
robot = MyRobot() robot.start()
Source code in opensourceleg/robots/base.py
stop()
abstractmethod
¶
Stop all actuators and sensors.
For each actuator in the actuators dictionary, a debug message is logged and its stop method is called. Similarly, for each sensor in the sensors dictionary, a debug message is logged and its stop method is called.
Returns:
| Type | Description |
|---|---|
None
|
None |
Example
robot = MyRobot() robot.start() ... # Do something with the robot robot.stop()
Source code in opensourceleg/robots/base.py
update()
abstractmethod
¶
Update all actuators and sensors.
This method calls the update method for each actuator and sensor to refresh their state.
Returns:
| Type | Description |
|---|---|
None
|
None |
Example
robot = MyRobot() robot.start() robot.update()