diff --git a/tools/setup_hall_as_index.py b/tools/setup_hall_as_index.py index 87ec245f..bc1ad866 100644 --- a/tools/setup_hall_as_index.py +++ b/tools/setup_hall_as_index.py @@ -1,13 +1,17 @@ import odrive +from odrive.utils import dump_errors from odrive.enums import * import time print("Finding an odrive...") odrv = odrive.find_any() -axes = [odrv.axis0, odrv.axis1]; -# axes = [odrv.axis0]; +# axes = [odrv.axis0, odrv.axis1]; +axes = [odrv.axis0]; + +flip_index_search_direction = False +save_and_reboot = False print("Setting config...") # Settings to protect battery @@ -33,6 +37,7 @@ for ax in axes: ax.controller.config.pos_gain = 26 ax.config.lockin.current = 10 + ax.config.lockin.ramp_distance = 3.14 ax.config.lockin.vel = 15 ax.config.lockin.accel = 10 ax.config.lockin.finish_distance = 30 @@ -41,8 +46,8 @@ def wait_and_exit_on_error(ax): while ax.current_state != AXIS_STATE_IDLE: time.sleep(0.1) if ax.error != errors.axis.ERROR_NONE: - odrive.utils.dump_errors(odrv) - quit() + dump_errors(odrv, True) + exit() for axnum, ax in enumerate(axes): print("Calibrating motor {}...".format(axnum)) @@ -54,19 +59,24 @@ for axnum, ax in enumerate(axes): wait_and_exit_on_error(ax) print(" Direction is {}".format(ax.motor.config.direction)) + if flip_index_search_direction: + ax.config.lockin.ramp_distance = -ax.config.lockin.ramp_distance + ax.config.lockin.vel = -ax.config.lockin.vel + ax.config.lockin.accel = -ax.config.lockin.accel + print("Searching for index on motor {}...".format(axnum)) ax.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH wait_and_exit_on_error(ax) if (not ax.encoder.index_found): print("Failed finding index! Quitting.") - quit() + exit() print("Calibrating encoder offset on motor {}...".format(axnum)) ax.requested_state = AXIS_STATE_ENCODER_OFFSET_CALIBRATION wait_and_exit_on_error(ax) if (not ax.encoder.is_ready): print("Failed to calibrate encoder! Quitting") - quit() + exit() # If we get here there were no errors, so let's commit the values ax.motor.config.pre_calibrated = True @@ -79,8 +89,9 @@ for axnum, ax in enumerate(axes): #Everything should be good to go here, so let's save and reboot print("") print("All operations successful!") -odrv.save_configuration() -try: - odrv.reboot() -except odrive.fibre.ChannelBrokenException: - pass +if save_and_reboot: + odrv.save_configuration() + try: + odrv.reboot() + except odrive.fibre.ChannelBrokenException: + pass