 |
SimpleFOClibrary
2.1
|
Go to the documentation of this file.
89 if(
_isset(zero_electric_offset)){
99 if(
sensor) exit_flag *= alignSensor();
122 int BLDCMotor::alignCurrentSense() {
139 return exit_flag > 0;
143 int BLDCMotor::alignSensor() {
152 if(!exit_flag)
return exit_flag;
156 for (
int i = 0; i <=500; i++ ) {
164 for (
int i = 500; i >=0; i-- ) {
170 setPhaseVoltage(0, 0, 0);
173 if (mid_angle == end_angle) {
176 }
else if (mid_angle < end_angle) {
185 float moved = fabs(mid_angle - end_angle);
206 setPhaseVoltage(0, 0, 0);
214 int BLDCMotor::absoluteZeroSearch() {
224 angleOpenloop(1.5*
_2PI);
230 setPhaseVoltage(0, 0, 0);
364 void BLDCMotor::setPhaseVoltage(
float Uq,
float Ud,
float angle_el) {
374 static int trap_120_map[6][3] = {
375 {
_HIGH_IMPEDANCE,1,-1},{-1,1,
_HIGH_IMPEDANCE},{-1,
_HIGH_IMPEDANCE,1},{
_HIGH_IMPEDANCE,-1,1},{1,-1,
_HIGH_IMPEDANCE},{1,
_HIGH_IMPEDANCE,-1}
386 Ub = trap_120_map[sector][1] * Uq + center;
387 Uc = trap_120_map[sector][2] * Uq + center;
390 Ua = trap_120_map[sector][0] * Uq + center;
392 Uc = trap_120_map[sector][2] * Uq + center;
395 Ua = trap_120_map[sector][0] * Uq + center;
396 Ub = trap_120_map[sector][1] * Uq + center;
405 static int trap_150_map[12][3] = {
406 {
_HIGH_IMPEDANCE,1,-1},{-1,1,-1},{-1,1,
_HIGH_IMPEDANCE},{-1,1,1},{-1,
_HIGH_IMPEDANCE,1},{-1,-1,1},{
_HIGH_IMPEDANCE,-1,1},{1,-1,1},{1,-1,
_HIGH_IMPEDANCE},{1,-1,-1},{1,
_HIGH_IMPEDANCE,-1},{1,1,-1}
417 Ub = trap_150_map[sector][1] * Uq + center;
418 Uc = trap_150_map[sector][2] * Uq + center;
421 Ua = trap_150_map[sector][0] * Uq + center;
423 Uc = trap_150_map[sector][2] * Uq + center;
426 Ua = trap_150_map[sector][0] * Uq + center;
427 Ub = trap_150_map[sector][1] * Uq + center;
441 _ca =
_cos(angle_el);
442 _sa =
_sin(angle_el);
444 Ualpha = _ca * Ud - _sa * Uq;
445 Ubeta = _sa * Ud + _ca * Uq;
455 float Umin = min(
Ua, min(
Ub,
Uc));
492 sector = floor(angle_el /
_PI_3) + 1;
559 float BLDCMotor::velocityOpenloop(
float target_velocity){
561 unsigned long now_us =
_micros();
563 float Ts = (now_us - open_loop_timestamp) * 1e-6;
565 if(Ts <= 0 || Ts > 0.5) Ts = 1e-3;
580 open_loop_timestamp = now_us;
588 float BLDCMotor::angleOpenloop(
float target_angle){
590 unsigned long now_us =
_micros();
592 float Ts = (now_us - open_loop_timestamp) * 1e-6;
594 if(Ts <= 0 || Ts > 0.5) Ts = 1e-3;
614 open_loop_timestamp = now_us;
float current_sp
target current ( q current )
float zero_electric_angle
absolute zero electric angle - if available
virtual int needsSearch()
@ voltage
Torque control using voltage.
float voltage_limit
Voltage limitting variable - global limit.
float Ubeta
Phase voltages U alpha and U beta used for inverse Park and Clarke transform.
PIDController PID_current_d
parameter determining the d current PID config
@ angle
Position/angle motion control.
float voltage_limit
limiting voltage set to the motor
void _delay(unsigned long ms)
float electrical_angle
current electrical angle
float shaft_velocity_sp
current target velocity
@ velocity
Velocity motion control.
LowPassFilter LPF_current_d
parameter determining the current Low pass filter configuration
int initFOC(float zero_electric_offset=NOT_SET, Direction sensor_direction=Direction::CW) override
float shaft_velocity
current motor velocity
int8_t enabled
enabled or disabled motor flag
FOCModulationType foc_modulation
parameter derterniming modulation algorithm
float shaft_angle
current motor angle
float target
current target value - depends of the controller
virtual void setPwm(float Ua, float Ub, float Uc)=0
float phase_resistance
motor phase resistance
TorqueControlType torque_controller
parameter determining the torque control type
float _normalizeAngle(float angle)
int sensor_direction
if sensor_direction == Direction::CCW then direction will be flipped to CW
PIDController PID_current_q
parameter determining the q current PID config
@ foc_current
torque control using dq currents
DQCurrent_s getFOCCurrents(float angle_el)
@ SinePWM
Sinusoidal PWM modulation.
@ SpaceVectorPWM
Space vector modulation method.
float limit
Maximum output value.
float _electricalAngle(float shaft_angle, int pole_pairs)
DQCurrent_s current
current d and q current measured
@ dc_current
Torque control using DC current (one current magnitude)
float current_limit
Current limitting variable - global limit.
unsigned int motion_cnt
counting variable for downsampling for move commad
PIDController P_angle
parameter determining the position PID configuration
DQVoltage_s voltage
current d and q voltage set to the motor
virtual float getDCCurrent(float angle_el=0)
void move(float target=NOT_SET) override
int8_t modulation_centered
flag (1) centered modulation around driver limit /2 or (0) pulled to 0
CurrentSense * current_sense
virtual int driverAlign(BLDCDriver *driver, float voltage)=0
MotionControlType controller
parameter determining the control loop to be used
int pole_pairs
motor pole pairs number
Print * monitor_port
Serial terminal variable if provided.
LowPassFilter LPF_current_q
parameter determining the current Low pass filter configuration
float voltage_sensor_align
sensor and motor align voltage parameter
BLDCMotor(int pp, float R=NOT_SET)
PIDController PID_velocity
parameter determining the velocity PID configuration
void linkDriver(BLDCDriver *driver)
float velocity_limit
Velocity limitting variable - global limit.
unsigned int motion_downsample
parameter defining the ratio of downsampling for move commad
float velocity_index_search
target velocity for index search
float Uc
Current phase voltages Ua,Ub and Uc set to motor.
virtual void setPhaseState(int sa, int sb, int sc)=0
virtual float getAngle()=0
float shaft_angle_sp
current target angle