// Open loop motor control example
#include <SimpleFOC.h>
// BLDC motor & driver instance
// BLDCMotor( pp number , phase resistance)
BLDCMotor motor = BLDCMotor(11 , 12.5, 100);
//BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB15);
// 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()
{
pinMode(PC13,OUTPUT);
// 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]
//motor.foc_modulation = FOCModulationType::SinePWM;
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
// 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()
{
digitalWrite(PC13,HIGH);
delay(100);
digitalWrite(PC13,LOW);
//delay(1000);
motor.loopFOC();
// open loop velocity movement
// using motor.current_limit and motor.velocity_limit
motor.move();
// user communication
command.run();
}