#include<Arduino.h>#include<SimpleFOC.h>// Define motor driver pins#define PWM_A 9#define PWM_B 6#define PWM_C 5#define ENABLE_PIN 4// Create the BLDC driver objectBLDCDriver3PWMdriver(PWM_A,PWM_B,PWM_C,ENABLE_PIN);// Create the BLDC motor objectBLDCMotormotor=BLDCMotor(11);// 7 pole pairs (estimate for GM3506)// Create an open-loop velocity controlvoidsetup(){Serial.begin(9600);// Initialize driverdriver.voltage_power_supply=12;// Set to your supply voltagedriver.init();// Link driver to motormotor.linkDriver(&driver);// Open-loop velocity modemotor.voltage_limit=6;// Limit voltage to half supplymotor.controller=MotionControlType::velocity_openloop;// Initialize motormotor.init();Serial.println("Motor Ready!");}voidloop(){motor.move(1);motor.loopFOC();}
Note
In velocity_openloop mode the speed depends on supply voltage and motor parameters.
#include<Arduino.h>#include<SimpleFOC.h>// Define motor driver pins#define PWM_A 9#define PWM_B 6#define PWM_C 5#define ENABLE_PIN 4// Create the BLDC driver objectBLDCDriver3PWMdriver(PWM_A,PWM_B,PWM_C,ENABLE_PIN);// Create the BLDC motor objectBLDCMotormotor=BLDCMotor(11);// 7 pole pairs (estimate for GM3506)MagneticSensorSPIas5047u=MagneticSensorSPI(10,14,0x3FFF);// Create an open-loop velocity controlvoidsetup(){Serial.begin(115200);as5047u.init();Serial.println("as5047u ready");// Initialize driverdriver.voltage_power_supply=12;// Set to your supply voltagedriver.init();// Link driver to motormotor.linkDriver(&driver);// Open-loop velocity modemotor.voltage_limit=6;// Limit voltage to half supplymotor.controller=MotionControlType::velocity_openloop;// Initialize motormotor.init();Serial.println("Motor Ready!");}voidloop(){motor.move(1);motor.loopFOC();as5047u.update();// display the angle and the angular velocity to the terminalSerial.print(as5047u.getAngle());Serial.print("\t");Serial.println(as5047u.getVelocity());}