Hi everyone, thanks for your help in advance!
I’m getting the B-G431B-ESC1 to run some simple skateboard hub motors that use hall sensors.
I’ve been messing around with the settings to try and get high torque at low speeds. I saw that it was reccomended to use motor.foc_modulation = FOCModulationType::Trapezoid_120
Unfortunately when I did this, my motor made a loud noise and the ESC doesn’t work anymore.
Later on (today) I tried using it again and it blew up another of my ESCs.
The code is attached below.
// Open loop motor control example
#include <SimpleFOC.h>
#define MAX_SPEED 20
#define PP 10
// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number);
BLDCMotor motor = BLDCMotor(PP, 0.8, 66);
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003f, -64.0f / 7.0f, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);
HallSensor sensor(A_HALL1, A_HALL2, A_HALL3, PP);
void hallA() {
sensor.handleA();
}
void hallB() {
sensor.handleB();
}
void hallC() {
sensor.handleC();
}
//target variable
float targetVelocity = 0;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) {
command.scalar(&targetVelocity, cmd);
}
// void doLimit(char* cmd) {
// command.scalar(&motor.voltage_limit, cmd);
// }
void setup() {
Serial.begin(115200);
//motor.useMonitoring(Serial);
// power supply voltage [V]
driver.voltage_power_supply = 22;
//driver.voltage_limit = 10;
driver.init();
currentSense.linkDriver(&driver);
// link the motor and the driver
motor.linkDriver(&driver);
sensor.enableInterrupts(hallA, hallB, hallC);
sensor.init();
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// current = voltage / resistance, so try to be well under 1Amp
//motor.voltage_limit = 5; // [V]
motor.current_limit = 3;
motor.voltage_sensor_align = 2;
// open loop control config
motor.controller = MotionControlType::velocity;
// Voltage torque control has more torque at low speeds
motor.torque_controller = TorqueControlType::foc_current;
motor.foc_modulation = FOCModulationType::Trapezoid_120;
motor.LPF_angle.Tf = 0.4;
// init motor hardware
motor.init();
currentSense.init();
motor.linkCurrentSense(¤tSense);
motor.linkSensor(&sensor);
motor.initFOC();
// add target command T
command.add('T', doTarget, "target velocity");
// command.add('L', doLimit, "voltage limit");
Serial.begin(115200);
Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
// foc and motion controls
motor.loopFOC();
motor.move(targetVelocity);
command.run();
}