Hello everyone! I use v2.0.2 shield to run the angle control of simpleFOC, and use the FOC current control inside. But after my operation, my motor spins wildly, I don’t know why? This is my code, thanks
#include <SimpleFOC.h>
MagneticSensorSPI sensor = MagneticSensorSPI(9, 14, 0x3FFF);
BLDCMotor motor = BLDCMotor(14);
BLDCDriver3PWM driver = BLDCDriver3PWM(10, 5, 6, 8);
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A1, A3);
float target_angle = 0;
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_angle, cmd); }
void onMotor(char* cmd){ command.motor(&motor,cmd); }
void setup() {
sensor.init();
motor.linkSensor(&sensor);
driver.voltage_power_supply = 12;
driver.init();
motor.linkDriver(&driver);
current_sense.gain_b *= -1;
current_sense.init();
motor.linkCurrentSense(¤t_sense);
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.controller = MotionControlType::angle;
motor.torque_controller = TorqueControlType::foc_current;
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 10;
motor.PID_velocity.D = 0;
motor.P_angle.P = 10;
motor.voltage_limit = 6;
motor.velocity_limit = 5;
motor.LPF_velocity.Tf = 0.01;
Serial.begin(115200);
motor.useMonitoring(Serial);
motor.init();
motor.initFOC();
command.add('T', doTarget, "target angle");
command.add('M',onMotor,"my motor");
Serial.println(F("Motor ready."));
Serial.println(F("Set the target angle using serial terminal:"));
_delay(1000);
}
void loop() {
motor.loopFOC();
motor.move(target_angle);
command.run();
}