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();
}