Goal: in a “dead zone” around the target angle the motor should be “off”*. High above and below torque mode is needed, so it´s active in that zone**.
But at a specific angle in that dead zone the motor should snap to a specific angle. For this, angle mode is activated shortly before it from both sides.
Problem: coming from higher angles towards the angle target it´s working (motor is forcing towards the target). Coming from lower angles the motor works → against ← (away from) the target.
The (essential) code:
#include <SimpleFOC.h>
float curr_pos = 0.00; // current position
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(5, 10, 6, 8);
// Sensor
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
void setup() {
// ## 1 Serial ##
Serial.begin(115200);
motor.useMonitoring(Serial);
// ## 2 Sensor ##
sensor.init();
motor.linkSensor(&sensor);
// ## 3 Driver ##
driver.voltage_power_supply = 12; // power supply voltage [V]
driver.init();
motor.linkDriver(&driver);
// ## 4 Control Types ##
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
motor.controller = MotionControlType::torque;
motor.phase_resistance = 12.6; // 12.6 Ohms
motor.torque_controller = TorqueControlType::voltage;
// ## 5 Controller Config ##
// controller configuration based on the control type
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 1000;
motor.voltage_limit = 4.00;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
// ANGLE mode setup
// angle loop controller
motor.P_angle.P = 20;
motor.velocity_limit = 20;
// ## 6 Current Sense ##
// ## 7 Initialise Motor ##
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the inital target value
motor.target = 2.0;
Serial.println("Motor ready.");
Serial.print("\n");
_delay(1000);
}
void loop() {
motor.loopFOC();
motor.move();
sensor.update();
curr_pos = (sensor.getAngle());
// no force ABOVE pos. 3.0
if (curr_pos > 3.0) {
motor.voltage_limit = 0;
motor.target = 2.9;
motor.controller = MotionControlType::torque;
}
// no force BELOW pos. 2.8
if (curr_pos < 2.8) {
motor.voltage_limit = 0;
motor.target = 2.9;
motor.controller = MotionControlType::torque;
}
// force towards pos. 2.9 when "near"
if (curr_pos > 2.8 && curr_pos < 3.0) {
motor.voltage_limit = 4;
motor.target = 2.9;
motor.controller = MotionControlType::angle;
}
}
Setup: Nucleo stm32 G474RE, simpleFOC Shield 3.1, AS5600, BLDC iPower 5108.
I´m playing around with this for hours now. I´ve got a feeling it´s me being stupid again, but I can´t find the fault.
*enabling/disabling motor doesn´t work, it´s just buzzing after activation not reacting to anything.
**leaving it in Angle Mode there doesn´t change the issue. Having everything in Torque Mode is leading to the same result.