First of all, I would like to express my gratitude to the individuals responsible for creating this fantastic library. I am a university student in Japan, so I apologize in advance for any shortcomings in my English.
The system I am using consists of an Arduino Uno, a DRV8302 motor driver, an AS5600 magnetic sensor, and a SunnySky V2806 motor. The code I am using is based on a sample code provided in the documentation. The code I have implemented is nearly identical to the sample code.
/* ----- Pin setting -----
PC4 - Analog 4 - Encoder SDA
PC5 - Analog 5 - Encoder SCL
*/
#include <SimpleFOC.h>
// DRV8302 pins connections
// don't forget to connect the common ground pin
#define INH_A 5
#define INH_B 9
#define INH_C 11
#define INL_A 6
#define INL_B 10
#define INL_C 3
#define EN_GATE 8
#define M_PWM 6
#define M_OC 5
#define OC_ADJ 7
// motor instance
BLDCMotor motor = BLDCMotor(11);
// driver instance
BLDCDriver6PWM driver = BLDCDriver6PWM(INH_A, INL_A, INH_B, INL_B, INH_C, INL_C, EN_GATE);
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
// commander interface
Commander command = Commander(Serial);
void onMotor(char *cmd) { command.motor(&motor, cmd); }
void setup()
{
// configure i2C
Wire.setClock(400000);
// initialise magnetic sensor hardware
sensor.init();
// link the motor to the sensor
motor.linkSensor(&sensor);
// DRV8302 specific code
// M_OC - enable over-current protection
pinMode(M_OC, OUTPUT);
digitalWrite(M_OC, LOW);
// M_PWM - enable 6pwm mode (can be left open)
pinMode(M_PWM, OUTPUT);
digitalWrite(M_PWM, LOW);
// OD_ADJ - set the maximum over-current limit possible
// Better option would be to use voltage divisor to set exact value
pinMode(OC_ADJ, OUTPUT);
digitalWrite(OC_ADJ, HIGH);
// configure driver
driver.voltage_power_supply = 12;
driver.init();
motor.linkDriver(&driver);
// choose FOC modulation
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// set control loop type to be used
motor.controller = MotionControlType::torque;
// controller configuration based on the control type
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
// angle loop controller
motor.P_angle.P = 20;
// angle loop velocity limit
motor.velocity_limit = 50;
// default voltage_power_supply
motor.voltage_limit = 12;
// use monitoring with serial for motor init
// monitoring port
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the initial target value
motor.target = 2;
// define the motor id
command.add('M', onMotor, "motor");
_delay(1000);
}
// velocity set point variable
float target_velocity = 5; // 2Rad/s ~ 20rpm
void loop(){
// iterative setting FOC phase voltage
motor.loopFOC();
// iterative function setting the outer loop target
// velocity, position or voltage
// if target not set in parameter uses motor.target variable
motor.move(target_velocity);
// user communication
command.run();
}
Based on the serial monitor output, it appears to be functioning correctly, as shown below. However, in reality, the FAULT LED lights up and the operation comes to a halt, as demonstrated in the video (https://youtu.be/jb0efc9v35U).
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CCW
MOT: PP check: fail - estimated pp: 78.77
MOT: Zero elec. angle: 0.67
MOT: No current sense.
MOT: Ready.
I also attempted to run the “magnetic_sensor_i2c_example” code, which was mentioned in a previous question, but it didn’t seem to have any noticeable issues. I am unsure why this behavior is occurring.
I would greatly appreciate your assistance in resolving this matter.