Hi Everyone,
I’m new to this forum. I wish to drive a brushless motor(customized, already attached the motor specs) with the B-G431B-ESC.
I have properly set up the Arduino IDE but the motor is not spinning even with a very simple program… Here’s my code. Really need your help.
#include <SimpleFOC.h>
#include <Arduino.h>
const int motorPolePairs = 4;
//Motor and driver instance
BLDCMotor motor = BLDCMotor(motorPolePairs);
BLDCDriver6PWM driver = BLDCDriver6PWM(PHASE_UH, PHASE_UL, PHASE_VH, PHASE_VL, PHASE_WH, PHASE_WL);
float targetSpeed = 20;
Commander command = Commander(Serial);
void doTarget(char *cmd) { command.scalar(&targetSpeed, cmd); }
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
sensor.init();
sensor.enableInterrupts(doA, doB, doC);
driver.voltage_power_supply = 12;
driver.init();
motor.phase_resistance = 0.1; // [Ohm]
motor.current_limit = 2; // [Amps] - if phase resistance defined
// motor.voltage_limit = 0.5; // [V] - if phase resistance not defined
motor.velocity_limit = 50; // [rad/s] 5 rad/s cca 50rpm
//Control loop setup
motor.controller = MotionControlType::velocity_openloop;
//Init motor
motor.linkSensor(&sensor);
motor.linkDriver(&driver);
motor.useMonitoring(Serial);
motor.init();
// add target command T
command.add('T', doTarget, "target");
command.add('t', doTarget, "target");
Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");
delay(1000);
}
void loop()
{
//Motor loop, as quick as possible
motor.move(targetSpeed);
//User communication
command.run();
//Monitoring
// motor.monitor();
}