Hello.
I had problems with studio back when I was starting with an UNO, and was told to update to ST and it should fix it.
NUCLEO-64 G431RB
42BLS02 motor with hall sensor
Studio will work right very, very rarely. The bad behavior varies, sometimes it just locks up, sometimes it becomes unresponsive, sometimes it ignores what I type in, sometimes it ignore button preseses, sometimes it doesn;t pull in the right values from the embedded system.
BTW, what does “Pull params” mean? It seems to pull the embedded parameters into itself even if you don’t click this?
#include <SimpleFOC.h>
//#define CURSENS
#define HALLSENS
//
//
// MOTOR: 42BLS02
// DRIVE: SimpleFOC
// SENSOR:
//
// COMMENT:
//
//
#ifdef HALLSENS
// PHASE A B C PP
HallSensor sensor = HallSensor(3, 2, 4, 4);
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
#else
// encoder instance
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
#endif
BLDCMotor motor = BLDCMotor(4, 1, 250);
// PHASE A B C En
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
#ifdef CURSENS
// inline current sensor instance
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A2, _NC);
#endif
// 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); }
// instantiate the smoothing sensor, providing the real sensor as a constructor argument
SmoothingSensor smooth = SmoothingSensor(sensor, motor);
void setup() {
sensor.init();
#ifdef HALLSENS
sensor.enableInterrupts(doA, doB, doC);
#endif
// link the motor to the sensor
//motor.linkSensor(&sensor);
smooth.phase_correction = -_PI_6;
motor.linkSensor(&smooth);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.voltage_limit = 12;
driver.init();
// link driver
motor.linkDriver(&driver);
// link current sense and the driver
#ifdef CURSENS
current_sense.linkDriver(&driver);
// current sense init and linking
current_sense.init();
motor.linkCurrentSense(¤t_sense);
motor.torque_controller = TorqueControlType::foc_current;
// Q
motor.PID_current_q.P = 50;
motor.PID_current_q.I = 100;
motor.PID_current_q.D = 0;
motor.PID_current_q.limit = 10;
motor.PID_current_q.output_ramp = 500;
motor.LPF_current_q.Tf = 0.1;
// D
motor.PID_current_d.P = 0;
motor.PID_current_d.I = 0;
motor.PID_current_d.D = 0;
motor.PID_current_d.limit = 10;
motor.PID_current_d.output_ramp = 500;
motor.LPF_current_d.Tf = 0.1;
#endif
//motor.controller = MotionControlType::torque;
motor.controller = MotionControlType::torque;
// default voltage_power_supply
motor.voltage_sensor_align = 4;
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 = 0.2;
// 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();
}