Velocity open loop not working

Hi, I am trying to make a simple velocity open loop work with the B-G431B-ESC1 board, but its not working at all with PlatformIo, where I print the electrical angle, and it’s always “0.00”, and with Arduino IDE it turns in a weird way (it starts from an initial position, goes to something about 90 degrees in the rotor with the velocity proportional to the target velocity, and goes back to that initial position almost immediately). In Arduino IDE I can’t print the electrical angle because it complains about Serial2, so I just don’t use the commander.

#include <SimpleFOC.h>
#include <Arduino.h>

#define A_PHASE_UL PC13
#define A_PHASE_WL PB15
#define A_PHASE_UH PA8
#define A_PHASE_VH PA9
#define A_PHASE_WH PA10
#define A_PHASE_VL PA12

// Motor instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);

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

void setup() {
  driver.voltage_power_supply = 12;
  driver.init();
  motor.linkDriver(&driver);

  motor.voltage_limit = 0.5;  // [V]
  motor.controller = MotionControlType::velocity_openloop;

  // initialize motor
  motor.init();
  //motor.initFOC();

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

  Serial.begin(115200);
  motor.target = 10;
  char vel = '1';
  doTarget(&vel);
  delay(1000);
}

void loop() {
  //motor.loopFOC();
  motor.move();
  //Serial2.println(motor.electrical_angle);
  motor.target = 2;
  command.run();
}

It looks like you’ve got a mixture of openloop and closed loop code - although you have commented out the closed loop code.

If this line is uncommented then I’d expect you to observe it moving in the way you describe above - i.e. in one direction and then back to initial position.

Can you swap:

  motor.move();
  //Serial2.println(motor.electrical_angle);
  motor.target = 2;

for this:

motor.move(2);
//Serial2.println(motor.electrical_angle);
// motor.target = 2;

I changed to motor.move(2);, but nothing changed. Running the motor really slowly I realized that it wasn’t going back to the initial position, but actually, it got frozen for a while, and when it unfroze, it jumped to the position it should be if it continued running. So reviewing the configurations I realized that “USB support (if available):” was set to “CDC (generic ‘Serial’ supersede U(S)ART)” when it should be “none”. Just changing this, the motor started running fine.

I had the same case.
There are wrong platformio.ini examples for B-G431B-ESC1 in the forum.

It seems like it. Good to know the reason, thanks!