Break after first command

Hi guys,

I am new to motor control.

I purchased a B-G431-ESC1 with an ex8101 105kv motor and a 600p/r rotary encoder.

I started loading the first code with simplefoc example for B-G431-ESC1

But I have a problem that I don’t understand, the motor initializes correctly but once I send the command to angle the motor runs for a few seconds and stops with the maximum amperage entered in the motor.current_limit

Can you give me some ideas on this problem?

Can we see your code?

it is my last code, if i send velocity command (“M10”). motor begin turn and stop after few degres

 * B-G431B-ESC1 position motion control example with encoder
#include <SimpleFOC.h>

// Motor instance
BLDCMotor motor = BLDCMotor(22, 0.186, 105);
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003, -64.0/7.0, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);

// encoder instance
Encoder encoder = Encoder(A_HALL2, A_HALL1, 600);

// Interrupt routine intialisation
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}

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

void setup() {
  // initialize encoder sensor hardware
  encoder.enableInterrupts(doA, doB); 

  // link the motor to the sensor
  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 12;
  // link the motor and the driver
  // link current sense and the driver

  // current sensing
  // no need for aligning
  currentSense.skip_align = true;

  // aligning voltage [V]
  motor.voltage_sensor_align = 1;
  // index search velocity [rad/s]
  motor.velocity_index_search = 3;

  // set motion control loop to be used
  motor.controller = MotionControlType::velocity;
  motor.torque_controller = TorqueControlType::voltage;
  motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

  // contoller configuration 
  // default parameters in defaults.h

  // velocity PI controller parameters
  motor.PID_velocity.P = 5;
  motor.PID_velocity.I = 0;
  // default voltage_power_supply
  motor.voltage_limit = 6;
  // jerk control using voltage voltage ramp
  // default value is 300 volts per sec  ~ 0.3V per millisecond
  motor.PID_velocity.output_ramp = 1000;
  // velocity low pass filtering time constant
  motor.LPF_velocity.Tf = 0.01;

  // use monitoring with serial 
  // comment out if not needed
  // initialize motor
  // align encoder and start FOC

  // add target command T
  command.add('M', doTarget, "target");

  Serial.println(F("Motor ready."));
  Serial.println(F("Set the target angle using serial terminal:"));

void loop() {
  // main FOC algorithm function

  // Motion control function

  // function intended to be used with serial plotter to monitor motor variables
  // significantly slowing the execution down!!!!
  // user communication;

Have you moved ticked off all the simpler steps/modes before getting to this stage?


  1. Sensor test (no driver)
  2. Openloop velocity (no linked sensor)
  3. Closed loop torque/voltage mode

I imagine you’ve done step 1 and 2, but have you done 3 (without any current sense code). That 3rd step requires no PIDs so is good closed loop ‘first test’.

I’m not great at current sense stuff but suspect torque mode = voltage isn’t using your current sensing (shouldn’t stop things working, just an observation)

If you have completed 3 then I’d probably move to something similar to what you have (closed loop velocity) but with no current sense. Then finally move back to something similar to your code base.