?
SimpleFOC教程目录:请点击
?
说明
本文主要是结合本店电机,通过配置的参数,快速实现对电机的控制。 店铺链接:https://item.taobao.com/item.htm?ft=t&id=643573104607 ?
一、SimpleMotor配置
1.1、云台电机
1.2、航模电机
?
二、ODrive配置
- 关于ODrive的配置网上有很多,本节只是尽可能用最少的配置让电机转起来,不保证参数为最佳设置,
- ODrive版本v0.5.1,
- ABZ和ABI的叫法不同,指的都是一种编码器。
?
2.1、5008航模电机标配AS5047P
2.1.1、接ABI接口
注意:速度PID只用了P参数,只是为了让电机转起来,非最佳配置
odrv0.vbus_voltage
odrv0.erase_configuration()
odrv0.axis0.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis0.encoder.config.mode = ENCODER_MODE_INCREMENTAL
odrv0.axis0.encoder.config.cpr = 4000
odrv0.axis0.controller.config.vel_gain = 0.05
odrv0.axis0.controller.config.vel_integrator_gain = 0
odrv0.axis0.controller.config.vel_limit = 100
odrv0.axis0.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis0.controller.config.vel_ramp_rate = 100
odrv0.axis0.motor.config.pole_pairs = 7
odrv0.axis0.motor.config.calibration_current = 5
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis0.error
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis0.controller.input_vel = 10
odrv0.axis0.controller.input_vel = 0
odrv0.axis0.requested_state = AXIS_STATE_IDLE
?
2.1.2、接SPI接口
SPI接M0端子,进入闭环后电机稍微动一下就报错,查看错误:ENCODER_ERROR_ABS_SPI_COM_FAIL, 百度后找到这个:https://www.bilibili.com/read/cv12631507/。 应该跟ODrive的电源是通过M0的DRV8301降压有关,用M1接口控制不再报错。 注意:速度PID只用了P参数,只是为了让电机转起来,非最佳配置
odrv0.erase_configuration()
odrv0.axis1.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis1.encoder.config.abs_spi_cs_gpio_pin = 4
odrv0.axis1.encoder.config.mode = ENCODER_MODE_SPI_ABS_AMS
odrv0.axis1.encoder.config.cpr = 2**14
odrv0.axis1.controller.config.vel_gain = 0.05
odrv0.axis1.controller.config.vel_integrator_gain = 0
odrv0.axis1.controller.config.vel_limit = 50
odrv0.axis1.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis1.controller.config.vel_ramp_rate = 100
odrv0.axis1.motor.config.pole_pairs = 7
odrv0.axis1.motor.config.calibration_current = 5
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis1.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis1.error
odrv0.axis1.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis1.controller.input_vel = 10
odrv0.axis1.controller.input_vel = 0
odrv0.axis1.requested_state = AXIS_STATE_IDLE
?
2.1.3、无感模式
去掉编码器接线,就是无感控制
odrv0.erase_configuration()
odrv0.axis0.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis0.controller.config.vel_gain = 0.02
odrv0.axis0.controller.config.vel_integrator_gain = 0.00
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.controller.config.vel_limit = 100
odrv0.axis0.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis0.controller.config.vel_ramp_rate = 100
odrv0.axis0.motor.config.current_lim = 20
odrv0.axis0.motor.config.direction = 1
odrv0.axis0.sensorless_estimator.config.pm_flux_linkage = 5.51328895422 / (7 * 335)
odrv0.axis0.motor.config.calibration_current = 5
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis0.requested_state = AXIS_STATE_MOTOR_CALIBRATION
odrv0.axis0.error
odrv0.axis0.controller.input_vel = 10
odrv0.axis0.requested_state = AXIS_STATE_SENSORLESS_CONTROL
odrv0.axis0.controller.input_vel = 50
odrv0.axis0.controller.input_vel = 0
odrv0.axis0.requested_state = AXIS_STATE_IDLE
?
2.2、3505航模电机标配AS5047P
2.2.1、接ABI接口
odrv0.erase_configuration()
odrv0.axis0.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis0.encoder.config.mode = ENCODER_MODE_INCREMENTAL
odrv0.axis0.encoder.config.cpr = 4000
odrv0.axis0.controller.config.vel_gain = 0.03
odrv0.axis0.controller.config.vel_integrator_gain = 0
odrv0.axis0.controller.config.vel_limit = 100
odrv0.axis0.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis0.controller.config.vel_ramp_rate = 100
odrv0.axis0.motor.config.pole_pairs = 10
odrv0.axis0.motor.config.calibration_current = 4
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis0.error
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis0.controller.input_vel = 10
odrv0.axis0.controller.input_vel = 0
odrv0.axis0.requested_state = AXIS_STATE_IDLE
?
2.2.2、接SPI接口
odrv0.erase_configuration()
odrv0.axis1.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis1.encoder.config.abs_spi_cs_gpio_pin = 4
odrv0.axis1.encoder.config.mode = ENCODER_MODE_SPI_ABS_AMS
odrv0.axis1.encoder.config.cpr = 2**14
odrv0.axis1.controller.config.vel_gain = 0.03
odrv0.axis1.controller.config.vel_integrator_gain = 0
odrv0.axis1.controller.config.vel_limit = 100
odrv0.axis1.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis1.controller.config.vel_ramp_rate = 100
odrv0.axis1.motor.config.pole_pairs = 10
odrv0.axis1.motor.config.calibration_current = 4
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis1.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis1.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis1.controller.input_vel = 10
odrv0.axis1.controller.input_vel = 0
odrv0.axis1.requested_state = AXIS_STATE_IDLE
?
2.2.3、无感模式
odrv0.erase_configuration()
odrv0.axis0.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis0.controller.config.vel_gain = 0.01
odrv0.axis0.controller.config.vel_integrator_gain = 0.00
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.controller.config.vel_limit = 100
odrv0.axis0.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis0.controller.config.vel_ramp_rate = 100
odrv0.axis0.motor.config.current_lim = 15
odrv0.axis0.motor.config.pole_pairs = 10
odrv0.axis0.motor.config.direction = 1
odrv0.axis0.sensorless_estimator.config.pm_flux_linkage = 5.51328895422 / (10 * 650)
odrv0.axis0.motor.config.calibration_current = 4
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis0.requested_state = AXIS_STATE_MOTOR_CALIBRATION
odrv0.axis0.controller.input_vel = 10
odrv0.axis0.requested_state = AXIS_STATE_SENSORLESS_CONTROL
odrv0.axis0.controller.input_vel = 50
odrv0.axis0.requested_state = AXIS_STATE_IDLE
//50=0.25A@12V //转速到60或者更高时,电机会发生错误并停止,无论接M0或M1都是这样 //查看错误:dump_errors(odrv0) 不接放电电阻时提示: axis:AXIS_ERROR_MOTOR_FAILED motor:MOTOR_ERROR_CURRENT_LIMIT_VIOLATION 接放电电阻时提示: axis:AXIS_ERROR_BRAKE_RESISTOR_DISARMED / AXIS_ERROR_MOTOR_FAILED motor:MOTOR_ERROR_DC_BUS_OVER_REGEN_CURRENT 总之速度不能设置的太高,具体原因不清楚
odrv0.erase_configuration()
odrv0.axis1.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis1.controller.config.vel_gain = 0.01
odrv0.axis1.controller.config.vel_integrator_gain = 0.00
odrv0.axis1.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis1.controller.config.vel_limit = 100
odrv0.axis1.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis1.controller.config.vel_ramp_rate = 100
odrv0.axis1.motor.config.current_lim = 15
odrv0.axis1.motor.config.pole_pairs = 10
odrv0.axis1.motor.config.direction = 1
odrv0.axis1.sensorless_estimator.config.pm_flux_linkage = 5.51328895422 / (10 * 650)
odrv0.axis1.motor.config.calibration_current = 4
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis1.requested_state = AXIS_STATE_MOTOR_CALIBRATION
odrv0.axis1.controller.input_vel = 10
odrv0.axis1.requested_state = AXIS_STATE_SENSORLESS_CONTROL
odrv0.axis1.controller.input_vel = 50
odrv0.axis1.requested_state = AXIS_STATE_IDLE
?
2.3、3505航模电机标配TLE5012B
2.3.1、接ABI接口
请参考2.2.1,TLE5012B的ABI接口配置与AS5047P的ABI接口配置,除了CPR需要修改,其它参数配置相同。 ?
2.3.2、无感模式
请参考2.2.3。 ?
2.4、2808航模电机标配AS5047P
2.4.1、接ABI接口
odrv0.erase_configuration()
odrv0.axis0.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis0.encoder.config.mode = ENCODER_MODE_INCREMENTAL
odrv0.axis0.encoder.config.cpr = 4000
odrv0.axis0.controller.config.vel_gain = 0.03
odrv0.axis0.controller.config.vel_integrator_gain = 0
odrv0.axis0.controller.config.vel_limit = 100
odrv0.axis0.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis0.controller.config.vel_ramp_rate = 100
odrv0.axis0.motor.config.pole_pairs = 7
odrv0.axis0.motor.config.calibration_current = 5
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis0.error
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis0.controller.input_vel = 10
odrv0.axis0.controller.input_vel = 0
odrv0.axis0.requested_state = AXIS_STATE_IDLE
?
2.4.2、接SPI接口
odrv0.erase_configuration()
odrv0.axis1.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis1.encoder.config.abs_spi_cs_gpio_pin = 4
odrv0.axis1.encoder.config.mode = ENCODER_MODE_SPI_ABS_AMS
odrv0.axis1.encoder.config.cpr = 2**14
odrv0.axis1.controller.config.vel_gain = 0.03
odrv0.axis1.controller.config.vel_integrator_gain = 0
odrv0.axis1.controller.config.vel_limit = 50
odrv0.axis1.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis1.controller.config.vel_ramp_rate = 100
odrv0.axis1.motor.config.pole_pairs = 7
odrv0.axis1.motor.config.calibration_current = 5
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis1.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis1.error
odrv0.axis1.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis1.controller.input_vel = 10
odrv0.axis1.controller.input_vel = 0
odrv0.axis1.requested_state = AXIS_STATE_IDLE
?
2.4.3、无感模式
odrv0.erase_configuration()
odrv0.axis0.controller.config.vel_gain = 0.01
odrv0.axis0.controller.config.vel_integrator_gain = 0
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.controller.config.vel_limit = 100
odrv0.axis0.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis0.controller.config.vel_ramp_rate = 100
odrv0.axis0.motor.config.current_lim = 20
odrv0.axis0.motor.config.pole_pairs = 7
odrv0.axis0.motor.config.direction = 1
odrv0.axis0.sensorless_estimator.config.pm_flux_linkage = 5.51328895422 / (7 * 630)
odrv0.axis0.motor.config.calibration_current = 4
odrv0.save_configuration()
odrv0.reboot()
odrv0.axis0.requested_state = AXIS_STATE_MOTOR_CALIBRATION
odrv0.axis0.error
odrv0.axis0.controller.input_vel = 10
odrv0.axis0.requested_state = AXIS_STATE_SENSORLESS_CONTROL
odrv0.axis0.controller.input_vel = 10
odrv0.axis0.requested_state = AXIS_STATE_IDLE
?
2.5、2808航模电机标配TLE5012B
2.5.1、接ABI接口
请参考2.4.1。TLE5012B的ABI接口配置与AS5047P的ABI接口配置,除了CPR需要修改,其它参数配置相同。 ?
2.5.2、无感模式
请参考2.4.3。 ? ?
|