sudo pip3 install --upgrade odrive
odrivetool
つながらないときsudoをつけるとつながるかも
sudo odrivetool
dump_errors(odrv0)
# odrive firmware 0.6.6
import odrive
from odrive import enums
from odrive.pyfibre import fibre
from odrive import legacy_config
import fibre.libfibre
import time
import sys
args = sys.argv
CAN_ID = (3<<3) + int(args[1])
CUR_SOFT_MAX = 75
print("can_id:" + str(CAN_ID))
print('please connection odrive.')
dev = odrive.find_any()
print('connected with odrive')
try:
dev.erase_configuration()
except fibre.libfibre.ObjectLostError as e:
pass
time.sleep(2)
dev = odrive.find_any()
print('erased configration.')
dev.config.dc_bus_undervoltage_trip_level = 12 # 19.8 [V]
dev.config.dc_bus_overvoltage_trip_level = 35 # 26 [V]
dev.config.dc_max_positive_current = 1000
dev.config.dc_max_negative_current = -1000 # バッテリーに厳しいタイプの制御班
dev.axis0.controller.config.spinout_electrical_power_threshold = 500
dev.axis0.controller.config.spinout_mechanical_power_threshold = -500
# モーター設定、キャリブレーション
dev.axis0.config.motor.motor_type = enums.MotorType.HIGH_CURRENT
dev.axis0.config.motor.pole_pairs = 14
dev.axis0.config.motor.torque_constant = 1
dev.axis0.config.motor.resistance_calib_max_voltage = 2
dev.axis0.config.motor.calibration_current = 10
dev.axis0.requested_state = enums.AxisState.MOTOR_CALIBRATION
time.sleep(0.2)
while True:
if dev.axis0.procedure_result != 1:
break
time.sleep(0.2)
if (dev.axis0.active_errors != 0) or (dev.axis0.procedure_result != 0):
print("motor calibration error")
odrive.utils.dump_errors(dev)
exit()
else:
print("motor calibration success")
dev.axis0.config.motor.current_soft_max = CUR_SOFT_MAX # [A]
#dev.axis0.config.motor.current_hard_max = 1000 # [A] 脱調しても落ちないようにする設定
dev.axis0.config.motor.current_hard_max = 150 # [A] 脱調したらわかるようにする設定
# dev.config.inverter0.current_hard_max = 1000 # これで落ちてくれるほうが安全(逆回転しない)
dev.axis0.controller.config.vel_limit = 1000 # [turn/s]
# エンコーダー設定、キャリブレーション
dev.amt21_encoder_group0.config.enable = True
dev.axis0.config.load_encoder = enums.EncoderId.AMT21_ENCODER0
dev.axis0.config.commutation_encoder = enums.EncoderId.AMT21_ENCODER0
dev.axis0.requested_state = enums.AxisState.ENCODER_OFFSET_CALIBRATION
# save
try:
dev.save_configuration()
except fibre.libfibre.ObjectLostError as e:
pass
time.sleep(2)
dev = odrive.find_any()
print('saved')
# saved
dev.axis0.requested_state = enums.AxisState.ENCODER_OFFSET_CALIBRATION
time.sleep(0.2)
while True:
if dev.axis0.procedure_result != 1:
break
time.sleep(0.2)
if (dev.axis0.active_errors != 0) or (dev.axis0.procedure_result != 0):
print("enc calibration error")
odrive.utils.dump_errors(dev)
exit()
else:
print("enc calibration success")
# その他設定
dev.axis0.controller.config.control_mode = enums.CONTROL_MODE_VELOCITY_CONTROL
dev.axis0.config.startup_closed_loop_control = True
dev.axis0.controller.config.vel_gain = 10
dev.axis0.controller.config.vel_integrator_gain = 0
#can
dev.can.config.baud_rate = 1000000
dev.axis0.config.can.node_id = CAN_ID#axisのID CAN stdidの上位5bitに対応 (3<<(8-5))+MotorNumber推奨(MessageController的に)
dev.axis0.config.watchdog_timeout = 0.1
dev.axis0.config.enable_watchdog = True
# save#################################################################
try:
dev.save_configuration()
except fibre.libfibre.ObjectLostError as e:
pass
time.sleep(2)
dev = odrive.find_any()
print('saved')
# odrive firmware 0.6.6
import odrive
from odrive import enums
from odrive.pyfibre import fibre
from odrive import legacy_config
import fibre.libfibre
import sys
args = sys.argv
CAN_ID = (3<<3) + int(args[1])
print("CAN_ID:" + str(CAN_ID))
CUR_SOFT_MAX = 60
import time
print('please connection odrive.')
dev = odrive.find_any()
print('connected with odrive')
try:
dev.erase_configuration()
except fibre.libfibre.ObjectLostError as e:
pass
time.sleep(2)
dev = odrive.find_any()
print('erased configration.')
BATTERY_N_CELLS = 6
BATTERY_CAPACITY = 3.3 # [Ah]
dev.config.dc_bus_undervoltage_trip_level = 12 # 19.8 [V]
dev.config.dc_bus_overvoltage_trip_level = 35 # 26 [V]
dev.config.dc_max_positive_current = 1000
dev.config.dc_max_negative_current = -1000 # バッテリーに厳しいタイプの制御班
dev.axis0.controller.config.spinout_electrical_power_threshold = 500
dev.axis0.controller.config.spinout_mechanical_power_threshold = -500
# モーター設定、キャリブレーション
dev.axis0.config.motor.motor_type = enums.MotorType.HIGH_CURRENT
dev.axis0.config.motor.pole_pairs = 7
dev.axis0.config.motor.torque_constant = 1
dev.axis0.config.motor.resistance_calib_max_voltage = 2
dev.axis0.config.motor.calibration_current = 10
dev.axis0.requested_state = enums.AxisState.MOTOR_CALIBRATION
time.sleep(0.2)
while True:
if dev.axis0.procedure_result != 1:
break
time.sleep(0.2)
if (dev.axis0.active_errors != 0) or (dev.axis0.procedure_result != 0):
print("motor calibration error")
odrive.utils.dump_errors(dev)
exit()
else:
print("motor calibration success")
dev.axis0.config.motor.current_soft_max = 60 # [A]
dev.axis0.config.motor.current_hard_max = 1000 # [A]
dev.config.inverter0.current_hard_max = 200
dev.axis0.controller.config.vel_limit = 1000 # [turn/s]
# エンコーダー設定、キャリブレーション
dev.amt21_encoder_group0.config.enable = True
dev.axis0.config.load_encoder = enums.EncoderId.AMT21_ENCODER0
dev.axis0.config.commutation_encoder = enums.EncoderId.AMT21_ENCODER0
dev.axis0.requested_state = enums.AxisState.ENCODER_OFFSET_CALIBRATION
# save
try:
dev.save_configuration()
except fibre.libfibre.ObjectLostError as e:
pass
time.sleep(2)
dev = odrive.find_any()
print('saved')
# saved
dev.axis0.requested_state = enums.AxisState.ENCODER_OFFSET_CALIBRATION
time.sleep(0.2)
while True:
if dev.axis0.procedure_result != 1:
break
time.sleep(0.2)
if (dev.axis0.active_errors != 0) or (dev.axis0.procedure_result != 0):
print("enc calibration error")
odrive.utils.dump_errors(dev)
exit()
else:
print("enc calibration success")
# その他設定
dev.axis0.controller.config.control_mode = enums.CONTROL_MODE_VELOCITY_CONTROL
dev.axis0.config.startup_closed_loop_control = True
dev.axis0.controller.config.vel_gain = 10
dev.axis0.controller.config.vel_integrator_gain = 0
#can
dev.can.config.baud_rate = 1000000
dev.axis0.config.can.node_id = CAN_ID#axisのID CAN stdidの上位5bitに対応 (3<<(8-5))+MotorNumber推奨(MessageController的に)
dev.axis0.config.watchdog_timeout = 0.1
dev.axis0.config.enable_watchdog = True
# save#################################################################
try:
dev.save_configuration()
except fibre.libfibre.ObjectLostError as e:
pass
time.sleep(2)
dev = odrive.find_any()
print('saved')