Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_register(self, motors):
if not motors:
return
ids = [m.id for m in motors]
values = self.io.get_angle_limit(ids)
for m, val in zip(motors, values):
m.__dict__['lower_limit'], m.__dict__['upper_limit'] = val
for m in motors:
for var in ['lower_limit', 'upper_limit']:
m._read_synced[var].done()
class PosSpeedLoadDxlController(DxlController):
def __init__(self, io, motors, sync_freq):
DxlController.__init__(self, io, motors, sync_freq,
False, 'get', 'present_position')
def setup(self):
torques = self.io.is_torque_enabled(self.ids)
for m, c in zip(self.working_motors, torques):
m.compliant = not c
self._old_torques = torques
self._old_goals = {m.id: 0.0 for m in self.motors}
try:
values = self.io.get_goal_position_speed_load(self.ids)
positions, speeds, loads = zip(*values)
except ValueError:
raise DxlError("Couldn't initialize pos/speed/load sync loop!")
def __init__(self, io, motors):
controllers = [
PosSpeedLoadDxlController(io, motors, 50.),
AngleLimitRegisterController(io, motors, 10., False),
DxlController(io, motors, 1., False, 'get', 'present_voltage'),
DxlController(io, motors, 1., False, 'get', 'present_temperature')
]
pid_motors = [m for m in motors
if (m.model.startswith('MX') or
m.model.startswith('XL-320'))]
if pid_motors:
controllers.insert(0, DxlController(io, pid_motors, 10., False,
'set', 'pid_gain', 'pid'))
margin_slope_motors = [m for m in motors
if (m.model.startswith('AX') or
m.model.startswith('RX'))]
if margin_slope_motors:
controllers.append(DxlController(io, margin_slope_motors, 10, False,
'set', 'compliance_margin'))
controllers.append(DxlController(io, margin_slope_motors, 10, False,
]
pid_motors = [m for m in motors
if (m.model.startswith('MX') or
m.model.startswith('XL-320'))]
if pid_motors:
controllers.insert(0, DxlController(io, pid_motors, 10., False,
'set', 'pid_gain', 'pid'))
margin_slope_motors = [m for m in motors
if (m.model.startswith('AX') or
m.model.startswith('RX'))]
if margin_slope_motors:
controllers.append(DxlController(io, margin_slope_motors, 10, False,
'set', 'compliance_margin'))
controllers.append(DxlController(io, margin_slope_motors, 10, False,
'set', 'compliance_slope'))
MetaDxlController.__init__(self, io, motors, controllers)
return True
def set_register(self, motors):
""" Gets the value from :class:`~pypot.dynamixel.motor.DxlMotor` and sets it to the specified register. """
if not motors:
return
ids = [m.id for m in motors]
values = (m.__dict__[self.varname] for m in motors)
getattr(self.io, 'set_{}'.format(self.regname))(dict(zip(ids, values)))
for m in motors:
m._write_synced[self.varname].done()
class AngleLimitRegisterController(DxlController):
def __init__(self, io, motors, sync_freq, synchronous):
DxlController.__init__(self, io, motors, sync_freq,
synchronous, 'get', 'angle_limit')
self.varnames = ['lower_limit', 'upper_limit']
for m in motors:
for var in self.varnames:
m._read_synchronous[var] = self.synchronous
@property
def synced_motors(self):
motors = self.working_motors
if self.synchronous:
sync_motors = []
DxlController(io, motors, 10., True, 'get', 'present_voltage'),
DxlController(io, motors, 10., True, 'get', 'present_temperature')
]
pid_motors = [m for m in motors
if (m.model.startswith('MX') or
m.model.startswith('XL-320'))]
if pid_motors:
controllers.insert(0, DxlController(io, pid_motors, 10., True,
'set', 'pid_gain', 'pid'))
margin_slope_motors = [m for m in motors
if (m.model.startswith('AX') or
m.model.startswith('RX'))]
if margin_slope_motors:
controllers.append(DxlController(io, margin_slope_motors, 10., True,
'set', 'compliance_margin'))
controllers.append(DxlController(io, margin_slope_motors, 10., True,
'set', 'compliance_slope'))
led_motors = [m for m in motors if m.model.startswith('XL-320')]
if led_motors:
controllers.append(DxlController(io, led_motors, 5., False,
'set', 'LED_color', 'led'))
MetaDxlController.__init__(self, io, motors, controllers)
if pid_motors:
controllers.insert(0, DxlController(io, pid_motors, 10., True,
'set', 'pid_gain', 'pid'))
margin_slope_motors = [m for m in motors
if (m.model.startswith('AX') or
m.model.startswith('RX'))]
if margin_slope_motors:
controllers.append(DxlController(io, margin_slope_motors, 10., True,
'set', 'compliance_margin'))
controllers.append(DxlController(io, margin_slope_motors, 10., True,
'set', 'compliance_slope'))
led_motors = [m for m in motors if m.model.startswith('XL-320')]
if led_motors:
controllers.append(DxlController(io, led_motors, 5., False,
'set', 'LED_color', 'led'))
MetaDxlController.__init__(self, io, motors, controllers)
def __init__(self, io, motors):
controllers = [
PosSpeedLoadDxlController(io, motors, 50.),
AngleLimitRegisterController(io, motors, 10., True),
DxlController(io, motors, 10., True, 'get', 'present_voltage'),
DxlController(io, motors, 10., True, 'get', 'present_temperature')
]
pid_motors = [m for m in motors
if (m.model.startswith('MX') or
m.model.startswith('XL-320'))]
if pid_motors:
controllers.insert(0, DxlController(io, pid_motors, 10., True,
'set', 'pid_gain', 'pid'))
margin_slope_motors = [m for m in motors
if (m.model.startswith('AX') or
m.model.startswith('RX'))]
if margin_slope_motors:
controllers.append(DxlController(io, margin_slope_motors, 10., True,
'set', 'compliance_margin'))
controllers.append(DxlController(io, margin_slope_motors, 10., True,
def __init__(self, io, motors):
controllers = [
PosSpeedLoadDxlController(io, motors, 50.),
AngleLimitRegisterController(io, motors, 10., False),
DxlController(io, motors, 1., False, 'get', 'present_voltage'),
DxlController(io, motors, 1., False, 'get', 'present_temperature')
]
pid_motors = [m for m in motors
if (m.model.startswith('MX') or
m.model.startswith('XL-320'))]
if pid_motors:
controllers.insert(0, DxlController(io, pid_motors, 10., False,
'set', 'pid_gain', 'pid'))
margin_slope_motors = [m for m in motors
if (m.model.startswith('AX') or
m.model.startswith('RX'))]
if margin_slope_motors:
controllers.append(DxlController(io, margin_slope_motors, 10, False,
'set', 'compliance_margin'))
controllers.append(DxlController(io, margin_slope_motors, 10, False,
'set', 'compliance_slope'))
MetaDxlController.__init__(self, io, motors, controllers)
def __init__(self, io, motors):
controllers = [
PosSpeedLoadDxlController(io, motors, 50.),
AngleLimitRegisterController(io, motors, 10., True),
DxlController(io, motors, 10., True, 'get', 'present_voltage'),
DxlController(io, motors, 10., True, 'get', 'present_temperature')
]
pid_motors = [m for m in motors
if (m.model.startswith('MX') or
m.model.startswith('XL-320'))]
if pid_motors:
controllers.insert(0, DxlController(io, pid_motors, 10., True,
'set', 'pid_gain', 'pid'))
margin_slope_motors = [m for m in motors
if (m.model.startswith('AX') or
m.model.startswith('RX'))]
if margin_slope_motors:
controllers.append(DxlController(io, margin_slope_motors, 10., True,
'set', 'compliance_margin'))
def __init__(self, io, motors):
controllers = [
PosSpeedLoadDxlController(io, motors, 50.),
AngleLimitRegisterController(io, motors, 10., False),
DxlController(io, motors, 1., False, 'get', 'present_voltage'),
DxlController(io, motors, 1., False, 'get', 'present_temperature')
]
pid_motors = [m for m in motors
if (m.model.startswith('MX') or
m.model.startswith('XL-320'))]
if pid_motors:
controllers.insert(0, DxlController(io, pid_motors, 10., False,
'set', 'pid_gain', 'pid'))
margin_slope_motors = [m for m in motors
if (m.model.startswith('AX') or
m.model.startswith('RX'))]
if margin_slope_motors:
controllers.append(DxlController(io, margin_slope_motors, 10, False,
'set', 'compliance_margin'))