Loadcell
Module for interfacing with Loadcell amplifiers.
This module provides an implementation of a load cell amplifier (DephyLoadcellAmplifier) that inherits from LoadcellBase. It uses either an I2C interface via SMBus or a custom data callback function to communicate with a strain amplifier and processes raw ADC data to compute forces and moments.
Classes:
Name | Description |
---|---|
LoadcellNotRespondingException |
Exception raised when the load cell does not respond. |
DEPHY_AMPLIFIER_MEMORY_CHANNELS |
Enum representing memory channel addresses for load cell readings. |
DephyLoadcellAmplifier |
Concrete implementation of a load cell sensor that provides force and moment data. |
Dependencies
- numpy
- smbus2
- opensourceleg.logging
- opensourceleg.sensors.base
DEPHY_AMPLIFIER_MEMORY_CHANNELS
¶
Bases: int
, Enum
Enumeration of memory channel addresses used by the load cell.
Each channel corresponds to a specific high or low byte of the ADC data.
Source code in opensourceleg/sensors/loadcell.py
DephyLoadcellAmplifier
¶
Bases: LoadcellBase
Implementation of a load cell sensor using the Dephy Loadcell Amplifier.
This class communicates with the Dephy strain amplifier. It can connect via either I2C using the SMBus interface, or using custom data callbacks. It processes the raw ADC data, and computes forces (Fx, Fy, Fz) and moments (Mx, My, Mz) based on a provided calibration matrix and hardware configuration.
Class Attributes
ADC_RANGE (int): The maximum ADC value (212 - 1). OFFSET (float): The ADC mid-scale offset (half of 212).
Source code in opensourceleg/sensors/loadcell.py
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 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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
data: list[float]
property
¶
Get the latest processed load cell data.
Returns:
Type | Description |
---|---|
list[float]
|
list[float]: A 1D vector containing [Fx, Fy, Fz, Mx, My, Mz], where forces are in Newtons and moments in Nm. |
fx: float
property
¶
Get the latest force in the x (medial/lateral) direction in Newtons.
For the standard OSL setup, this value is positive towards the user's right.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Force (N) along the x-axis. |
fy: float
property
¶
Get the latest force in the y (anterior/posterior) direction in Newtons.
For the standard OSL setup, this value is positive in the posterior direction.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Force (N) along the y-axis. |
fz: float
property
¶
Get the latest force in the z (vertical) direction in Newtons.
For the standard OSL setup, this value is positive downwards. In quiet standing, a negative Fz value is expected.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Force (N) along the z-axis. |
is_calibrated: bool
property
¶
Indicates whether the load cell has been calibrated (zeroed).
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the calibration routine has been successfully completed; otherwise, False. |
is_streaming: bool
property
¶
Check if the load cell is currently streaming data.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if streaming; otherwise, False. |
mx: float
property
¶
Get the latest moment about the x (medial/lateral) axis in Nm.
For the standard OSL setup, this moment is positive towards the user's right.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Moment (Nm) about the x-axis. |
my: float
property
¶
Get the latest moment about the y (anterior/posterior) axis in Nm.
For the standard OSL setup, this moment is positive in the posterior direction.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Moment (Nm) about the y-axis. |
mz: float
property
¶
Get the latest moment about the z (vertical) axis in Nm.
For the standard OSL setup, this moment is positive towards the ground.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Moment (Nm) about the z-axis. |
__init__(calibration_matrix, tag='DephyLoadcellAmplifier', amp_gain=125.0, exc=5.0, bus=1, i2c_address=102, offline=False)
¶
Initialize the Dephy loadcell amplifier.
Validates the provided parameters and initializes internal variables for data acquisition, calibration, and streaming.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
calibration_matrix |
NDArray[double]
|
A 6x6 calibration matrix. |
required |
tag |
str
|
A tag for identifying the load cell instance. Defaults to "DephyLoadcellAmplifier". |
'DephyLoadcellAmplifier'
|
amp_gain |
float
|
Amplifier gain; must be greater than 0. Defaults to 125.0. |
125.0
|
exc |
float
|
Excitation voltage; must be greater than 0. Defaults to 5.0. |
5.0
|
bus |
int
|
I2C bus number to use. Defaults to 1. |
1
|
i2c_address |
int
|
I2C address of the strain amplifier. Defaults to 0x66. |
102
|
Raises:
Type | Description |
---|---|
TypeError
|
If calibration_matrix is not a 6x6 array. |
ValueError
|
If amp_gain or exc are not greater than 0. |
Source code in opensourceleg/sensors/loadcell.py
calibrate(number_of_iterations=2000, reset=False, data_callback=None)
¶
Perform a zeroing (calibration) routine for the load cell.
This method obtains an initial zero-load reading that is subtracted from subsequent measurements. If the sensor has already been calibrated and 'reset' is False, a log message is displayed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
number_of_iterations |
int
|
Number of iterations to average for calibration. Defaults to 2000. |
2000
|
reset |
bool
|
If True, forces recalibration by resetting the current calibration. Defaults to False. |
False
|
data_callback |
Optional[Callable[[], NDArray[uint8]]]
|
Optional callback to provide raw data. Defaults to None. |
None
|
Source code in opensourceleg/sensors/loadcell.py
reset()
¶
Reset the load cell calibration.
Resets the calibration offset to the zero value and marks the sensor as uncalibrated.
Source code in opensourceleg/sensors/loadcell.py
start()
¶
Start the load cell sensor.
If using I2C Mode, it opens the I2C connection using SMBus, waits briefly for hardware stabilization, and sets the streaming flag to True.
Source code in opensourceleg/sensors/loadcell.py
stop()
¶
Stop the load cell sensor.
Sets the streaming flag to False and closes the I2C connection if it is open.
update(calibration_offset=None, data_callback=None)
¶
Query the load cell for the latest data and update internal state.
Reads raw ADC data (either via a provided callback or by reading from I2C), converts it to engineering units using the calibration matrix, amplifier gain, and excitation voltage, and subtracts any calibration offset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
calibration_offset |
Optional[NDArray[double]]
|
An offset to subtract from the processed data. If None, uses the current calibration offset. |
None
|
data_callback |
Optional[Callable[..., NDArray[uint8]]]
|
A callback function to provide raw data. If not provided, the sensor's internal i2c method is used. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the update method fails due to misconfiguration. |
Source code in opensourceleg/sensors/loadcell.py
LoadcellNotRespondingException
¶
Bases: Exception
Exception raised when the load cell fails to respond.
Attributes:
Name | Type | Description |
---|---|---|
message |
str
|
Description of the error. |
Source code in opensourceleg/sensors/loadcell.py
__init__(message='Load cell unresponsive.')
¶
Initialize the LoadcellNotRespondingException.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
Error message. Defaults to "Load cell unresponsive.". |
'Load cell unresponsive.'
|