#include <SimpleFOC.h>
MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4);
BLDCMotor motor = BLDCMotor(4);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8);
float target_angle = 0;
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_angle, cmd); }
void setup() {
sensor.init();//
motor.linkSensor(&sensor);//
driver.voltage_power_supply = 12;
driver.init();
motor.linkDriver(&driver);
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.controller = MotionControlType::angle;
motor.PID_velocity.P = 0.2f;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0;
motor.voltage_limit = 4;
motor.LPF_velocity.Tf = 0.01f;
motor.P_angle.P = 20;
motor.velocity_limit = 50;
Serial.begin(38400);
motor.useMonitoring(Serial);
motor.init();
motor.initFOC();
command.add(‘T’, doTarget, “target angle”);
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();
}
When using this code the motor is fixed but not moving.
What’s the matter?