Skip to content

Commit be6a8fc

Browse files
feat(dephy): added torque_constant parameter to DephyActuator and DephyLegacyActuator. This allows the users to override the motor torque constant (NM_PER_AMP) when constructing DephyActuator in the control script. Additionally logs a warning and raises error when torque_constant is outside the range (0.08,0.25), since low values cause the motor to draw more current for the same torque.
1 parent 111d24a commit be6a8fc

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

opensourceleg/actuators/dephy.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141
IMPEDANCE_A = 0.00028444
4242
IMPEDANCE_C = 0.0007812
4343

44-
DEFAULT_MIN_TORQUE_CONSTANT = 0.07
44+
DEFAULT_MIN_TORQUE_CONSTANT = 0.08
45+
DEFAULT_MAX_TORQUE_CONSTANT = 0.25
4546

4647
DEPHY_ACTUATOR_CONSTANTS = MOTOR_CONSTANTS(
4748
MOTOR_COUNT_PER_REV=16384,
48-
NM_PER_AMP=0.145,
49+
NM_PER_AMP=0.1133,
4950
MAX_CASE_TEMPERATURE=80,
5051
MAX_WINDING_TEMPERATURE=110,
5152
)
@@ -139,19 +140,19 @@ def __init__(
139140
baud_rate: int = 230400,
140141
frequency: int = 500,
141142
debug_level: int = 4,
142-
torque_constant: float = 0.145, # old motor constant 0.1133 Nm/A
143+
torque_constant: float = 0.1133, # new motor constant 0.145 Nm/A
143144
dephy_log: bool = False,
144145
offline: bool = False,
145146
stop_motor_on_disconnect: bool = True,
146147
) -> None:
147-
if torque_constant <= DEFAULT_MIN_TORQUE_CONSTANT:
148+
if torque_constant < DEFAULT_MIN_TORQUE_CONSTANT or torque_constant > DEFAULT_MAX_TORQUE_CONSTANT:
148149
LOGGER.error(
149-
f"[{str.upper(tag)}] torque_constant={torque_constant} Nm/A is unusually low. "
150+
f"[{str.upper(tag)}] torque_constant={torque_constant} Nm/A is outside the valid range. "
150151
"Low torque constant will cause the motor to draw more current for the same torque. "
151-
"Verify your value: typical Dephy defaults are 0.1133 Nm/A (older motors)"
152+
"Verify your value: typical Dephy torque constants are 0.1133 Nm/A (older motors)"
152153
" and 0.145 Nm/A (newer motors)."
153154
)
154-
raise ValueError("Torque constant is too low")
155+
raise ValueError("Torque constant is outside the valid range")
155156
motor_constants = dataclasses.replace(DEPHY_ACTUATOR_CONSTANTS, NM_PER_AMP=torque_constant)
156157
ActuatorBase.__init__(
157158
self,
@@ -802,7 +803,6 @@ def motor_torque(self) -> float:
802803
>>> actuator.start()
803804
>>> print(f"Motor torque: {actuator.motor_torque} Nm")
804805
"""
805-
print(self.MOTOR_CONSTANTS.NM_PER_MILLIAMP)
806806
if self._data is not None:
807807
return float(self._data["mot_cur"] * self.MOTOR_CONSTANTS.NM_PER_MILLIAMP)
808808
else:
@@ -1236,18 +1236,18 @@ def __init__(
12361236
baud_rate: int = 230400,
12371237
frequency: int = 500,
12381238
debug_level: int = 4,
1239-
torque_constant: float = 0.145, # old motor constant 0.1133 Nm/A
1239+
torque_constant: float = 0.1133, # new motor constant 0.145 Nm/A
12401240
dephy_log: bool = False,
12411241
offline: bool = False,
12421242
) -> None:
1243-
if torque_constant <= DEFAULT_MIN_TORQUE_CONSTANT:
1243+
if torque_constant < DEFAULT_MIN_TORQUE_CONSTANT or torque_constant > DEFAULT_MAX_TORQUE_CONSTANT:
12441244
LOGGER.error(
1245-
f"[{str.upper(tag)}] torque_constant={torque_constant} Nm/A is unusually low. "
1245+
f"[{str.upper(tag)}] torque_constant={torque_constant} Nm/A is outside the valid range. "
12461246
"Low torque constant will cause the motor to draw more current for the same torque. "
1247-
"Verify your value: typical Dephy defaults are 0.1133 Nm/A (older motors)"
1247+
"Verify your value: typical Dephy torque constants are 0.1133 Nm/A (older motors)"
12481248
" and 0.145 Nm/A (newer motors)."
12491249
)
1250-
raise ValueError("Torque constant is too low")
1250+
raise ValueError("Torque constant is outside the valid range")
12511251
motor_constants = dataclasses.replace(DEPHY_ACTUATOR_CONSTANTS, NM_PER_AMP=torque_constant)
12521252
ActuatorBase.__init__(
12531253
self,

0 commit comments

Comments
 (0)