This is amazing. I folded together my simple known to work with this hardware example code with the essential elements for the smoothingsensor in the file Candas1 posted. Here is the result. I cannot get a potentiometer to read on the QVADRANS so I have to ramp the voltage up to avoid jerking on startup.
The commander would be something I should figure out of course, but I chopped out the velocity mode stuff because I want to keep it as elemental as possible. Block by block building forward. the commander and the velocity mode PID control stuff is additional components to be gotten working and integrated later if desired.
’ ’ ’
/**
*
- Torque control example using voltage control loop.
- Most of the low-end BLDC driver boards doesn’t have current measurement therefore SimpleFOC offers
- you a way to control motor torque by setting the voltage to the motor instead of the current.
- This makes the BLDC motor effectively a DC motor, and you can use it in a same way.
*/
#define polepairs 11
#define seconds_to_ramp
#include <Arduino.h>
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include <encoders/smoothing/SmoothingSensor.h>
BLDCMotor motor = BLDCMotor(polepairs);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB15);
// hall sensor instance
HallSensor sensor = HallSensor(PC6, PB11, PA3, polepairs);
SmoothingSensor smooth(sensor, motor);
// Interrupt routine intialisation
// channel A and B callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
// voltage set point variable
float target_voltage = 17;
void setup() {
pinMode(PC6, INPUT_PULLUP); // LED_BUILTIN
pinMode(PB11, INPUT_PULLUP);
pinMode(PA3, INPUT_PULLUP);
smooth.phase_correction = -_PI_6;
Serial.begin(115200);
// enable more verbose output for debugging
// comment out if not needed
// SimpleFOCDebug::enable(&Serial);
// initialize encoder sensor hardware
sensor.init();
sensor.enableInterrupts(doA, doB, doC);
// link the motor to the sensor
motor.linkSensor(&smooth);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 24;
driver.init();
// link driver
motor.linkDriver(&driver);
// aligning voltage
motor.voltage_sensor_align = 5;
// choose FOC modulation (optional)
motor.foc_modulation = FOCModulationType::SinePWM;
// set motion control loop to be used
motor.controller = MotionControlType::torque;
// initialize motor
motor.init();
// align sensor and start FOC
motor.initFOC();
for (float i = 0.0f; i < 600000.0f; i++){// assume 33 khz is what motor.loopfoc runs at if looped so 0.03 msec per loop so 600,000 should be 18 sec
motor.loopFOC();
motor.move(i*target_voltage/600000);
}
}
void loop() {
// main FOC algorithm function
// the faster you run this function the better
// Arduino UNO loop ~1kHz
// Bluepill loop ~10kHz
motor.loopFOC();
// Motion control function
// velocity, position or voltage (defined in motor.controller)
// this function can be run at much lower frequency than loopFOC() function
// You can also use motor.move() and set the motor.target in the code
motor.move(target_voltage);
}
’ ’ ’
I thought it would take a long time to get this working so I’m very grateful for the help, thanks guys, I promise to pay it forward by advancing the successor to the qvadrans (me and the guy who got that ball rolling decided for complicated reasons we should fork it and disconnect it from the past). Including by sending out free boards to people and stuff.
I have noticed that it glitches out increasingly at more than about 200 rpm, it sounds like a hard drive seeking randomly, twitching the motor around the table.
The non-smoothing sensor version of the code, previously posted, seems to be ok in this regard. I also noticed it draws more current than it did. It draws more than 250 mA even when unloaded.
There may be some kind of issue with the phase delay or something? The glitching appears to be random, I will check to see if it goes away when the motor is loaded.
hm, it appears to be unaffected by loading, and too random to be a coding thing. It seems like somethng is poorly grounded or there is an electrical noise issue, probably something with the hardware. I have 10 kohm pullups on the hall sensors. poking around with my finger reveals nothing useful.