I’m using a Mini board, v. 1.0, small BDUAV 2204-260KV motor from Amazon, AMT103 encoder. I trying for target angle and have modified an example. When run I get movement, all in the same direction, four times and then the motor stops and is free wheeling, Any suggestions on where I need to look? Here’s my code.
// Test_SimpleFOC
#include <SimpleFOC.h>
// motor instance
BLDCMotor motor = BLDCMotor(7); // Pole pair number, half the number of poles
// driver instance
// BLDCDriver3PWM( int phA, int phB, int phC, int en)
// - phA, phB, phC - A,B,C phase pwm pins
// - enable pin - (optional input)
BLDCDriver3PWM driver = BLDCDriver3PWM(11, 10, 9, 8);
// encoder instance
// Encoder(int encA, int encB , int cpr, int index)
// - encA, encB - encoder A and B pins
// - ppr - impulses per rotation (cpr=ppr*4)
// - index pin - (optional input)
Encoder encoder = Encoder(2, 3, 2048);
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
void setup() {
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// Quadrature mode enabling and disabling
// Quadrature::ON - CPR = 4xPPR - default
// Quadrature::OFF - CPR = PPR
encoder.quadrature = Quadrature::OFF;
// link the motor to the sensor
motor.linkSensor(&encoder);
// driver config
driver.init();
motor.linkDriver(&driver);
// set motion control loop to be used
motor.controller = MotionControlType::angle;
// controller configuration
// default parameters in defaults.h
// controller configuration based on the control type
// velocity PID controller parameters
// default P=0.5 I = 10 D =0
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0.001;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 1000;
motor.current_limit = 1.0;
// velocity low pass filtering
// default 5ms - try different values to see what is the best.
// the lower the less filtered
motor.LPF_velocity.Tf = 0.01;
// angle P controller - default P=20
motor.P_angle.P = 20;
// maximal velocity of the position control
// default 20
motor.velocity_limit = 4;
// default voltage_power_supply
motor.voltage_limit = 10;
// use monitoring with serial
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
Serial.println(“Motor ready.”);
_delay(1000);
}
// angle set point variable
float target_angle = 1;
// timestamp for changing direction
long timestamp_us = millis();
void loop() {
// each one second
if(millis() - timestamp_us > 1000) {
timestamp_us = millis();
// inverse angle
target_angle = -target_angle;
//target_angle += 0.1;
}
// main FOC algorithm function
motor.loopFOC();
// Motion control function
motor.move(target_angle);
// float position = encoder.getAngle();
// Serial.print("Position: ");
// Serial.println(position);
}