Servo reference
robot.hardware.servos
Servo drivers.
Three interchangeable backends are available through the
:class:~robot.hardware.servos.factory.ServoControllerFactory:
mock- in-memory :class:MockServoBus(default, for tests and dev).gpio- :class:RaspberryPiGPIOServoController(Pi 5 header).pca9685- :class:PCA9685ServoController(16-channel I2C board).
The original :class:MockServoBus and :class:MockServo are still
imported from :mod:robot.hardware.servos.mock_servo for backward
compatibility - see the original scaffold.
__all__ = ['MockServo', 'MockServoBus', 'PCA9685ServoController', 'RaspberryPiGPIOServoController', 'ServoControllerFactory', 'wrap_servo_controller']
module-attribute
MockServo
dataclass
Records every move command.
Source code in src/robot/hardware/servos/mock_servo.py
angle
property
history = field(default_factory=list)
class-attribute
instance-attribute
max_angle = 180.0
class-attribute
instance-attribute
min_angle = 0.0
class-attribute
instance-attribute
name
instance-attribute
__init__(name, min_angle=0.0, max_angle=180.0, _angle=90.0, _released=False, history=list())
move_to(angle, duration_s=0.4)
async
Source code in src/robot/hardware/servos/mock_servo.py
MockServoBus
Holds a collection of :class:MockServo instances by logical name.
Source code in src/robot/hardware/servos/mock_servo.py
__init__(servos=None)
add(servo)
all()
all_angles()
get(name)
PCA9685ServoController
Drive up to 16 servos through a PCA9685 board over I2C.
Source code in src/robot/hardware/servos/pca9685_controller.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
BACKEND_NAME = 'pca9685'
class-attribute
instance-attribute
backend_name
property
__init__(config, *, device_factory=None)
Source code in src/robot/hardware/servos/pca9685_controller.py
all()
close()
async
Source code in src/robot/hardware/servos/pca9685_controller.py
get(name)
RaspberryPiGPIOServoController
Drive hobby servos directly from the Pi GPIO header using gpiozero.
Source code in src/robot/hardware/servos/gpio_controller.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
BACKEND_NAME = 'gpio'
class-attribute
instance-attribute
backend_name
property
__init__(config, *, servo_factory=None)
Source code in src/robot/hardware/servos/gpio_controller.py
all()
close()
async
get(name)
ServoControllerFactory
Build a :class:ServoController from a :class:ServosConfig.
Source code in src/robot/hardware/servos/factory.py
__init__(config, *, servo_factory=None, pca_device_factory=None)
Source code in src/robot/hardware/servos/factory.py
build()
Instantiate the controller for the configured backend.
Source code in src/robot/hardware/servos/factory.py
wrap_servo_controller(bus, *, backend_name)
Wrap bus in a :class:ServoController-shaped adapter.
Interface
robot.interfaces.servo
Servo interfaces.
This module exposes two complementary protocols:
- :class:
Servo- a single addressable servo channel. It is what the :class:~robot.services.executor.ActionExecutortalks to in order to move one servo. - :class:
ServoController- a bus that owns several :class:Servochannels. Different backends (mock,gpio,pca9685) all implement this protocol so the rest of the application never knows which one is in use.
Implementations may use PWM via direct GPIO, a PCA9685 board over I2C, or
a simulator. The only contract is that controller.get(name) returns a
:class:Servo that can be commanded.
__all__ = ['Servo', 'ServoController']
module-attribute
Servo
Bases: Protocol
A single addressable servo channel.
Source code in src/robot/interfaces/servo.py
angle
property
Current angle in degrees.
name
property
Logical name of the servo (e.g. "head_pan").
move_to(angle, duration_s=0.4)
async
ServoController
Bases: Protocol
A controller that owns a collection of :class:Servo channels.
A controller is selected at application boot by the
:class:~robot.hardware.servos.factory.ServoControllerFactory based on
the value of config.servo.backend. The rest of the application only
ever depends on this interface.
Source code in src/robot/interfaces/servo.py
backend_name
property
Human-readable backend identifier (e.g. "gpio", "pca9685").