B-G431-ESC1 Unable to Spin Motor in Closed Loop Velocity or Position


I am getting started with using PlatformIO and SimpleFOC to operate a BLDC motor with the B-G431-ESC1 and an AS5600. I currently am using this motor (BrotherHobby Avenger 2812 V3 Motor(CW)) that is 900kV, 14 P, and 87mohms of internal resistance.

I have been following the SimpleFOC tuning guide videos from the official Youtube (https://youtu.be/ENGGh0ajE2M?si=XkhZx6LyVNI1wkKv) and have currently gotten the open-loop velocity mode to work.

However, when I try to run the closed-loop velocity controller, the motor never spins or may jolt a slight movement like it is stalling and then proceed to not move either. I am pretty lost on what is so different in implementing the velocity controller that it completely prevents the motor from moving.

Here is the code I have been using to test:

#include "Arduino.h"
#include "SimpleFOC.h"
// #include "motorSetup.h"

#define CONSTANT_VELOCITY             5.00f
#define GOAL_POSITION                -2.50f
float target = 0.00;

// Init Motor
BLDCMotor motor(14, 0.087, 900);                                                               
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003f, -64.0f/7.0f, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);

// Init Encoder
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target, cmd); }

void serialLoop() {
    static String received_chars;

    while (Serial.available()) {
        char inChar = (char) Serial.read();
        received_chars += inChar;

        if (inChar == '\n'){
            target = received_chars.toFloat();
            Serial.print("Target = "); Serial.println(target);
            received_chars = "";

void setup() {
    // Set up Serial + I2C

    // // Set up encoder
    Serial.println("Sensor Ready!");

    // // Link Motor and Encoder
    Serial.println("Motor and Sensor Linked!");

    // // Set up motor driver
    driver.voltage_power_supply = 12;   // Voltage Supply
    Serial.println("Driver Ready!");

    // link current sense and the driver

    // // Set up Current Sensing
    // currentSense.init();
    // currentSense.skip_align = true;     // no need for aligning
    // motor.linkCurrentSense(&currentSense);

    // // Set up system limits
    motor.voltage_limit = 6.0;            // Volts
    motor.velocity_limit = 20;          // rad/s
    motor.voltage_sensor_align = 1;     // Limits volts during FOC calibration
    motor.current_limit = 8.0;          // Amps
    motor.PID_velocity.output_ramp = 1000;

    // // Set up Velocity PID Coefficients
    motor.PID_velocity.P = 0.20f;
    motor.PID_velocity.I = 20.0f;
    motor.PID_velocity.D = 0;
    motor.LPF_velocity.Tf = 0.01f;

    // // Set up Motor
    // motor.torque_controller = TorqueControlType::voltage;
    motor.controller = MotionControlType::velocity;      // For position control test
    motor.useMonitoring(Serial);                            // Target | Voltage | Current | Velocity | Angle
    motor.monitor_variables = _MON_TARGET | _MON_VOLT_Q | _MON_ANGLE | _MON_VEL | _MON_CURR_Q ;

    // command.add('T', doTarget, "target angle");
    Serial.println("Motor Ready!");


void loop() {

    // Update system
    // sensor.update();


    // Print statements
    // command.run();


I have been trying to chase this issue for multiple days and would appreciate any guidance!!
Thanks all!

Are you confident you have the pole pairs correct?

Have you done a sensor test on its own e.g

Manually turning the motor 360deg should show 2xpi radians in the output for above test.

If you’ve done that then it would be good to post the output from your code, the initFOC method prints a bunch of info that might help you/us work out what is going on.

I did that video 3 years ago and it could probably do with being replaced by someone with more experience than me i.e i think the recommended 1st step for closed loop is ‘torque mode using voltage’ as it is simplest (no PIDs to tune). See step 3: