Hi All,
Hopefully someone can see what I’m doing wrong here as I’ve been banging my head against the wall for hours with this. I’m just trying to get a motor spinning in the velocity openloop mode, using the example code from the velocity openloop page, with the driver declaration changed to what I think is right for the B-G431B-ESC1 board.
This is my main.cpp:
// Open loop motor control example
#include <SimpleFOC.h>
// BLDC motor & driver instance
// BLDCMotor( pp number , phase resistance)
BLDCMotor motor = BLDCMotor(11 , 12.5, 100);
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 doLimitCurrent(char* cmd) { command.scalar(&motor.current_limit, cmd); }
void setup() {
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor current (provided resistance)
motor.current_limit = 0.5; // [Amps]
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
motor.init();
motor.initFOC();
// add target command T
command.add('T', doTarget, "target velocity");
command.add('C', doLimitCurrent, "current limit");
Serial.begin(115200);
Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
motor.loopFOC();
// open loop velocity movement
// using motor.current_limit and motor.velocity_limit
motor.move();
// user communication
command.run();
}
and this is my platformio.ini
[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
lib_archive = false
build_flags =
-D HAL_OPAMP_MODULE_ENABLED
lib_deps =
askuric/Simple FOC@ 2.3.2
With everthing as it is, I get nothing at all, no serial comms in the monitor, no activity on the outputs or drivers when measured on the scope. If I comment out motor.initFOC();
then I get serial comms and can send commands, but still no activity on the outputs or drivers regardless of what I set the speed to.
Can anyone see anything I’ve missed? Tried it on two different boards with the same result so I’m assuming it’s a software/config error. I’m using the builtin ST-LINK programmers on them if that makes a difference, running with the USB connected to the programmer and 12V bench PSU on the driver. It’s only pulling ~10mA with the motor connected so it’s certainly not “trying” to energise the motor.