1.硬件连接
电机三相可以任意接odrive的三相
霍尔信号反馈:red->5v Yellow->A Blue->B Green->z Black->GND
2.Odrive配置
先清除之前配置:
odrv0.erase_configuration()
基本配置:
odrv0.config.brake_resistance = 2
odrv0.config.dc_bus_undervoltage_trip_level = 20
odrv0.config.dc_bus_overvoltage_trip_level = 35
odrv0.config.dc_max_positive_current = 13
odrv0.config.dc_max_negative_current = -13
odrv0.config.max_regen_current = 0
odrv0.axis0.motor.config.pole_pairs = 4
odrv0.axis0.motor.config.calibration_current = 5
odrv0.axis0.motor.config.resistance_calib_max_voltage = 10
odrv0.axis0.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis0.motor.config.current_control_bandwidth = 100
odrv0.axis0.motor.config.current_lim = 13
odrv0.axis0.motor.config.requested_current_range = 13
odrv0.axis0.encoder.config.mode = ENCODER_MODE_HALL
odrv0.axis0.encoder.config.cpr = 24
odrv0.axis0.encoder.config.bandwidth = 100
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.controller.config.vel_limit = 50
odrv0.axis0.controller.config.vel_gain = 0.2
odrv0.axis0.controller.config.vel_integrator_gain = 0.07
odrv0.axis0.controller.config.input_mode = INPUT_MODE_PASSTHROUGH
odrv0.axis0.controller.config.vel_ramp_rate = 10
odrv0.save_configuration()
odrv0.reboot()
电机和编码器校准:
odrv0.axis0.requested_state = AXIS_STATE_MOTOR_CALIBRATION
dump_errors(odrv0)
odrv0.axis0.requested_state = AXIS_STATE_ENCODER_OFFSET_CALIBRATION
dump_errors(odrv0)
odrv0.axis0.motor.config.pre_calibrated = True
odrv0.axis0.config.startup_encoder_offset_calibration =True
odrv0.axis0.config.startup_closed_loop_control = True
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis0.requested_state = AXIS_STATE_MOTOR_CALIBRATION #这一行检测电机然后会听到电机响的一声
dump_errors(odrv0) #检测是否有错误
odrv0.axis0.requested_state=AXIS_STATE_ENCODER_OFFSET_CALIBRATION#这一行检测编码器然后看到编码器左右运动,注意这时候不可以堵着电机,让电机左右活动幅度相同
dump_errors(odrv0) #检测是否有错误
odrv0.axis0.motor.config.pre_calibrated = True#打开上电检测电机
odrv0.axis0.config.startup_encoder_offset_calibration =True#打开上电检测编码器
odrv0.axis0.config.startup_closed_loop_control = True#打开上电进入闭环状态
odrv0.save_configuration()#保存配置
odrv0.reboot()#重新上电启动
控制电机:
给一个目标速度
odrv0.axis0.controller.input_vel = 4