Hi All, I have a NEMA17 motor (42BLS02) which works well in open-loop velocity mode, but refuses to move in closeloop velocity mode. I’m using voltage feedback. When I set a target velocity, I can see a commanded voltage(a voltage which is enough to move the motor in close-loop), but the motor does’t budge, and I see no modulated sinsoid on the scope whatsoever (just steady carriers)
-The indicated angle seems to be correct in magnitude(I rotate once, and it increases by 6.28), though I’m not 100% sure if the direction is right?
-I’m pretty experienced at PID tuning and I don’t think it’s that (I start with a very small “P” gain which gives some commanded voltage(a voltage which WILL move the motor in open-loop mode) but there’s no movement.
-I’ve never used Hall sensors (I normally use AS5600), so I might be doing somthing stupid.
Controller: NUCLEO-64 G431
Driver: SimpleFOC
Motor: 42BLS02, 4PP, 18V
Sensor: Hall 3phase.
#include <SimpleFOC.h>
// encoder instance
//MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
// PHASE A B C PP
HallSensor sensor = HallSensor(3, 2, 4, 4);
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
BLDCMotor motor = BLDCMotor(4, 1, 250);
// PHASE A B C En
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
// commander communication instance
Commander command = Commander(Serial);
// void doMotor(char* cmd) { command.motor(&motor, cmd); }
void doTarget(char* cmd) {command.scalar(&motor.target, cmd);}
void doLimit(char* cmd) {command.scalar(&motor.voltage_limit, cmd);}
void doMotor(char* cmd) { command.motor(&motor, cmd); }
void setup() {
sensor.init();
sensor.enableInterrupts(doA, doB, doC);
// link the motor to the sensor
motor.linkSensor(&sensor);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.voltage_limit = 4;
driver.init();
// link driver
motor.linkDriver(&driver);
// link current sense and the driver
//motor.controller = MotionControlType::torque;
motor.controller = MotionControlType::velocity;
// default voltage_power_supply
motor.voltage_sensor_align = 2;
motor.voltage_limit = 2;
motor.current_limit = 10;
motor.velocity_limit = 20;
// contoller configuration based on the controll type
motor.PID_velocity.P = 0.1;
motor.PID_velocity.I = 0.0;
motor.PID_velocity.D = 0;
motor.PID_velocity.output_ramp = 100;
motor.PID_velocity.limit = 20;
// angle loop controller
motor.P_angle.P = 20;
motor.LPF_velocity.Tf = 1;
// set the inital target value
motor.target = 0;
Serial.begin(921600); // WARNING: low value like 115200 cause distorted FOC
motor.useMonitoring(Serial);
motor.monitor_variables = _MON_TARGET | _MON_VOLT_Q | _MON_VOLT_D | _MON_CURR_Q | _MON_CURR_D | _MON_VEL | _MON_ANGLE; // monitor target velocity and angle
//motor.foc_modulation = SpaceVectorPWM;
// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// commnads
command.add(‘T’, doTarget, “target”); // ssss space
command.add(‘L’, doLimit, “voltage limit”);
command.add(‘M’,doMotor,“motor”);
_delay(1000);
}
void loop() {
// iterative setting FOC phase voltage
motor.loopFOC();
// iterative function setting the outter loop target
motor.move();
// motor monitoring
motor.monitor();
// user communication
command.run();
}