Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to ignore fatal errors #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, dxl_io, controller_namespace, port_namespace):
self.compliance_margin = rospy.get_param(self.controller_namespace + '/joint_compliance_margin', None)
self.compliance_punch = rospy.get_param(self.controller_namespace + '/joint_compliance_punch', None)
self.torque_limit = rospy.get_param(self.controller_namespace + '/joint_torque_limit', None)
self.ignored_errors = rospy.get_param(self.controller_namespace + '/ignored_errors', None)

self.__ensure_limits()

Expand Down Expand Up @@ -136,6 +137,9 @@ def set_compliance_punch(self, punch):
def set_torque_limit(self, max_torque):
raise NotImplementedError

def set_ignored_errors(self, errs):
raise NotImplementedError

def process_set_speed(self, req):
self.set_speed(req.speed)
return [] # success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def initialize(self):
rospy.loginfo("Setting acceleration of %d to %d" % (self.motor_id, self.acceleration))
self.dxl_io.set_acceleration(self.motor_id, self.acceleration)

if self.ignored_errors is not None:
self.set_ignored_errors(self.ignored_errors)

self.joint_max_speed = rospy.get_param(self.controller_namespace + '/joint_max_speed', self.MAX_VELOCITY)

if self.joint_max_speed < self.MIN_VELOCITY: self.joint_max_speed = self.MIN_VELOCITY
Expand Down Expand Up @@ -159,6 +162,9 @@ def set_torque_limit(self, max_torque):
mcv = (self.motor_id, raw_torque_val)
self.dxl_io.set_multi_torque_limit([mcv])

def set_ignored_errors(self, errs):
self.dxl_io.set_ignored_errors(self.motor_id, errs)

def set_acceleration_raw(self, acc):
if acc < 0: acc = 0
elif acc > 254: acc = 254
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def initialize(self):
if self.compliance_punch is not None: self.set_compliance_punch(self.compliance_punch)
if self.torque_limit is not None: self.set_torque_limit(self.torque_limit)

if self.ignored_errors is not None:
self.set_ignored_errors(self.ignored_errors)

self.joint_max_speed = rospy.get_param(self.controller_namespace + '/joint_max_speed', self.MAX_VELOCITY)

if self.joint_max_speed < self.MIN_VELOCITY: self.joint_max_speed = self.MIN_VELOCITY
Expand Down Expand Up @@ -175,6 +178,10 @@ def set_torque_limit(self, max_torque):
mcv_slave = (self.slave_id, raw_torque_val)
self.dxl_io.set_multi_torque_limit([mcv_master, mcv_slave])

def set_ignored_errors(self, errs):
self.dxl_io.set_ignored_errors(self.master_id, errs)
self.dxl_io.set_ignored_errors(self.slave_id, errs)

def process_motor_states(self, state_list):
if self.running:
states = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def initialize(self):
if self.compliance_punch is not None: self.set_compliance_punch(self.compliance_punch)
if self.torque_limit is not None: self.set_torque_limit(self.torque_limit)

if self.ignored_errors is not None:
self.set_ignored_errors(self.ignored_errors)

self.joint_max_speed = rospy.get_param(self.controller_namespace + '/joint_max_speed', self.MAX_VELOCITY)

if self.joint_max_speed < self.MIN_VELOCITY: self.joint_max_speed = self.MIN_VELOCITY
Expand Down Expand Up @@ -149,6 +152,9 @@ def set_torque_limit(self, max_torque):
mcv = (self.motor_id, raw_torque_val)
self.dxl_io.set_multi_torque_limit([mcv])

def set_ignored_errors(self, errs):
self.dxl_io.set_ignored_errors(self.motor_id, errs)

def process_motor_states(self, state_list):
if self.running:
state = filter(lambda state: state.id == self.motor_id, state_list.motor_states)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def initialize(self):
if self.compliance_punch is not None: self.set_compliance_punch(self.compliance_punch)
if self.torque_limit is not None: self.set_torque_limit(self.torque_limit)

if self.ignored_errors is not None:
self.set_ignored_errors(self.ignored_errors)

self.joint_max_speed = rospy.get_param(self.controller_namespace + '/joint_max_speed', self.MAX_VELOCITY)

if self.joint_max_speed < self.MIN_VELOCITY: self.joint_max_speed = self.MIN_VELOCITY
Expand Down Expand Up @@ -162,6 +165,11 @@ def set_torque_limit(self, max_torque):
self.dxl_io.set_multi_torque_limit([mcv_master, mcv_slave])


def set_ignored_errors(self, errs):
self.dxl_io.set_ignored_errors(self.master_id, errs)
self.dxl_io.set_ignored_errors(self.slave_id, errs)


def process_motor_states(self, state_list):
if self.running:
states = {}
Expand Down
31 changes: 24 additions & 7 deletions dynamixel_driver/src/dynamixel_driver/dynamixel_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, port, baudrate, readback_echo=False):
self.ser = serial.Serial(port, baudrate, timeout=0.015)
self.port_name = port
self.readback_echo = readback_echo
self.ignored_errors = {}
except SerialOpenError:
raise SerialOpenError(port, baudrate)

Expand Down Expand Up @@ -973,6 +974,18 @@ def get_led(self, servo_id):
return bool(response[5])


def set_ignored_errors(self, servo_id, errs):
"""
Sets which errors are ignored.
errs is a list of ignored errors' names.
"""
try:
self.ignored_errors[servo_id]
except KeyError:
self.ignored_errors[servo_id] = 0
for err in errs:
self.ignored_errors[servo_id] += eval(err)

def exception_on_error(self, error_code, servo_id, command_failed):
global exception
exception = None
Expand All @@ -982,25 +995,29 @@ def exception_on_error(self, error_code, servo_id, command_failed):
msg = 'Communcation Error ' + ex_message
exception = NonfatalErrorCodeError(msg, 0)
return
if not error_code & DXL_OVERHEATING_ERROR == 0:
try:
detectable_errs = 0xff & ~self.ignored_errors[servo_id]
except KeyError:
detectable_errs = 0xff
if not error_code & DXL_OVERHEATING_ERROR & detectable_errs == 0:
msg = 'Overheating Error ' + ex_message
exception = FatalErrorCodeError(msg, error_code)
if not error_code & DXL_OVERLOAD_ERROR == 0:
if not error_code & DXL_OVERLOAD_ERROR & detectable_errs == 0:
msg = 'Overload Error ' + ex_message
exception = FatalErrorCodeError(msg, error_code)
if not error_code & DXL_INPUT_VOLTAGE_ERROR == 0:
if not error_code & DXL_INPUT_VOLTAGE_ERROR & detectable_errs == 0:
msg = 'Input Voltage Error ' + ex_message
exception = NonfatalErrorCodeError(msg, error_code)
if not error_code & DXL_ANGLE_LIMIT_ERROR == 0:
if not error_code & DXL_ANGLE_LIMIT_ERROR & detectable_errs == 0:
msg = 'Angle Limit Error ' + ex_message
exception = NonfatalErrorCodeError(msg, error_code)
if not error_code & DXL_RANGE_ERROR == 0:
if not error_code & DXL_RANGE_ERROR & detectable_errs == 0:
msg = 'Range Error ' + ex_message
exception = NonfatalErrorCodeError(msg, error_code)
if not error_code & DXL_CHECKSUM_ERROR == 0:
if not error_code & DXL_CHECKSUM_ERROR & detectable_errs == 0:
msg = 'Checksum Error ' + ex_message
exception = NonfatalErrorCodeError(msg, error_code)
if not error_code & DXL_INSTRUCTION_ERROR == 0:
if not error_code & DXL_INSTRUCTION_ERROR & detectable_errs == 0:
msg = 'Instruction Error ' + ex_message
exception = NonfatalErrorCodeError(msg, error_code)

Expand Down