Hi all,
I’m very new to all of this, so was just wondering if anyone could let me know of any pitfalls with this approach.
This is the basic layout, but will have buttons on a switch, which i have left off for simplicity.
Firstly, I know this “works”. I have the basic setup on a breadboard, and it does work - but with a caveat…
On occasion, the motor will skip or get stuck in a short fast “forward and back” motion, as though it’s stuck between two magnets. However, I think think this is a bad connection on one of my buck converters, which I need to redo anyway. it’s either that, or a problem with the values in my code, or there’s a hardware issue i’m hoping someone can point out. Is there any specific drawback to this approach?
code and Pic below.
any feedback would be appreciated
#include <SimpleFOC.h>
// BLDCMotor(pole pair number, phase resistance (optional) );
BLDCMotor motor = BLDCMotor(11);
// BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&motor.target, cmd); }
void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
void setup() {
// use monitoring with serial
Serial.begin(115200);
// enable more verbose output for debugging
// comment out if not needed
SimpleFOCDebug::enable(&Serial);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
// limit the maximal dc voltage the driver can set
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver.voltage_limit = 6;
if(!driver.init()){
Serial.println("Driver init failed!");
return;
}
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// current = voltage / resistance, so try to be well under 1Amp
motor.voltage_limit = 12; // [V]
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
if(!motor.init()){
Serial.println("Motor init failed!");
return;
}
// set the target velocity [rad/s]
//motor.target = 3.48; // 33.3RPM
motor.target = 4.71; // 45RPM
// add target command T
command.add('T', doTarget, "target velocity");
command.add('L', doLimit, "voltage limit");
Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
// open loop velocity movement
motor.move();
// user communication
command.run();
}