SimpleFOClibrary  2.1
BLDCMotor Class Reference

#include <BLDCMotor.h>

Inheritance diagram for BLDCMotor:
FOCMotor

Public Member Functions

 BLDCMotor (int pp, float R=NOT_SET)
 
void linkDriver (BLDCDriver *driver)
 
void init () override
 
void disable () override
 
void enable () override
 
int initFOC (float zero_electric_offset=NOT_SET, Direction sensor_direction=Direction::CW) override
 
void loopFOC () override
 
void move (float target=NOT_SET) override
 
- Public Member Functions inherited from FOCMotor
 FOCMotor ()
 
void linkSensor (Sensor *sensor)
 
void linkCurrentSense (CurrentSense *current_sense)
 
float shaftAngle ()
 
float shaftVelocity ()
 
float electricalAngle ()
 
void useMonitoring (Print &serial)
 
void monitor ()
 

Public Attributes

BLDCDriverdriver
 
float Ua
 
float Ub
 
float Uc
 Current phase voltages Ua,Ub and Uc set to motor. More...
 
float Ualpha
 
float Ubeta
 Phase voltages U alpha and U beta used for inverse Park and Clarke transform. More...
 
- Public Attributes inherited from FOCMotor
float target
 current target value - depends of the controller More...
 
float shaft_angle
 current motor angle More...
 
float electrical_angle
 current electrical angle More...
 
float shaft_velocity
 current motor velocity More...
 
float current_sp
 target current ( q current ) More...
 
float shaft_velocity_sp
 current target velocity More...
 
float shaft_angle_sp
 current target angle More...
 
DQVoltage_s voltage
 current d and q voltage set to the motor More...
 
DQCurrent_s current
 current d and q current measured More...
 
float voltage_sensor_align
 sensor and motor align voltage parameter More...
 
float velocity_index_search
 target velocity for index search More...
 
float phase_resistance
 motor phase resistance More...
 
int pole_pairs
 motor pole pairs number More...
 
float voltage_limit
 Voltage limitting variable - global limit. More...
 
float current_limit
 Current limitting variable - global limit. More...
 
float velocity_limit
 Velocity limitting variable - global limit. More...
 
int8_t enabled = 0
 enabled or disabled motor flag More...
 
FOCModulationType foc_modulation
 parameter derterniming modulation algorithm More...
 
int8_t modulation_centered = 1
 flag (1) centered modulation around driver limit /2 or (0) pulled to 0 More...
 
TorqueControlType torque_controller
 parameter determining the torque control type More...
 
MotionControlType controller
 parameter determining the control loop to be used More...
 
PIDController PID_current_q {DEF_PID_CURR_P,DEF_PID_CURR_I,DEF_PID_CURR_D,DEF_PID_CURR_RAMP, DEF_POWER_SUPPLY}
 parameter determining the q current PID config More...
 
PIDController PID_current_d {DEF_PID_CURR_P,DEF_PID_CURR_I,DEF_PID_CURR_D,DEF_PID_CURR_RAMP, DEF_POWER_SUPPLY}
 parameter determining the d current PID config More...
 
LowPassFilter LPF_current_q {DEF_CURR_FILTER_Tf}
 parameter determining the current Low pass filter configuration More...
 
LowPassFilter LPF_current_d {DEF_CURR_FILTER_Tf}
 parameter determining the current Low pass filter configuration More...
 
PIDController PID_velocity {DEF_PID_VEL_P,DEF_PID_VEL_I,DEF_PID_VEL_D,DEF_PID_VEL_RAMP,DEF_PID_VEL_LIMIT}
 parameter determining the velocity PID configuration More...
 
PIDController P_angle {DEF_P_ANGLE_P,0,0,1e10,DEF_VEL_LIM}
 parameter determining the position PID configuration More...
 
LowPassFilter LPF_velocity {DEF_VEL_FILTER_Tf}
 parameter determining the velocity Low pass filter configuration More...
 
LowPassFilter LPF_angle {0.0}
 parameter determining the angle low pass filter configuration More...
 
unsigned int motion_downsample = DEF_MOTION_DOWNSMAPLE
 parameter defining the ratio of downsampling for move commad More...
 
unsigned int motion_cnt = 0
 counting variable for downsampling for move commad More...
 
float sensor_offset
 user defined sensor zero offset More...
 
float zero_electric_angle = NOT_SET
 absolute zero electric angle - if available More...
 
int sensor_direction = NOT_SET
 if sensor_direction == Direction::CCW then direction will be flipped to CW More...
 
unsigned int monitor_downsample = DEF_MON_DOWNSMAPLE
 show monitor outputs each monitor_downsample calls More...
 
uint8_t monitor_variables = _MON_TARGET | _MON_VOLT_Q | _MON_VEL | _MON_ANGLE
 Bit array holding the map of variables the user wants to monitor. More...
 
Sensorsensor
 
CurrentSensecurrent_sense
 
Print * monitor_port
 Serial terminal variable if provided. More...
 

Detailed Description

BLDC motor class

Definition at line 15 of file BLDCMotor.h.

Constructor & Destructor Documentation

◆ BLDCMotor()

BLDCMotor::BLDCMotor ( int  pp,
float  R = NOT_SET 
)

BLDCMotor class constructor

Parameters
pppole pairs number
Rmotor phase resistance

Definition at line 6 of file BLDCMotor.cpp.

Member Function Documentation

◆ disable()

void BLDCMotor::disable ( )
overridevirtual

Motor disable function

Implements FOCMotor.

Definition at line 61 of file BLDCMotor.cpp.

◆ enable()

void BLDCMotor::enable ( )
overridevirtual

Motor enable function

Implements FOCMotor.

Definition at line 71 of file BLDCMotor.cpp.

◆ init()

void BLDCMotor::init ( )
overridevirtual

Motor hardware init function

Implements FOCMotor.

Definition at line 26 of file BLDCMotor.cpp.

◆ initFOC()

int BLDCMotor::initFOC ( float  zero_electric_offset = NOT_SET,
Direction  _sensor_direction = Direction::CW 
)
overridevirtual

Function initializing FOC algorithm and aligning sensor's and motors' zero position

FOC functions

Implements FOCMotor.

Definition at line 85 of file BLDCMotor.cpp.

◆ linkDriver()

void BLDCMotor::linkDriver ( BLDCDriver _driver)

Function linking a motor and a foc driver

Parameters
driverBLDCDriver class implementing all the hardware specific functions necessary PWM setting

Link the driver which controls the motor

Definition at line 21 of file BLDCMotor.cpp.

◆ loopFOC()

void BLDCMotor::loopFOC ( )
overridevirtual

Function running FOC algorithm in real-time it calculates the gets motor angle and sets the appropriate voltages to the phase pwm signals

  • the faster you can run it the better Arduino UNO ~1ms, Bluepill ~ 100us

Implements FOCMotor.

Definition at line 244 of file BLDCMotor.cpp.

◆ move()

void BLDCMotor::move ( float  target = NOT_SET)
overridevirtual

Function executing the control loops set by the controller parameter of the BLDCMotor.

Parameters
targetEither voltage, angle or velocity based on the motor.controller If it is not set the motor will use the target set in its variable motor.target

This function doesn't need to be run upon each loop execution - depends of the use case

Implements FOCMotor.

Definition at line 295 of file BLDCMotor.cpp.

Member Data Documentation

◆ driver

BLDCDriver* BLDCMotor::driver

BLDCDriver link:

  • 3PWM
  • 6PWM

Definition at line 37 of file BLDCMotor.h.

◆ Ua

float BLDCMotor::Ua

Definition at line 69 of file BLDCMotor.h.

◆ Ualpha

float BLDCMotor::Ualpha

Definition at line 70 of file BLDCMotor.h.

◆ Ub

float BLDCMotor::Ub

Definition at line 69 of file BLDCMotor.h.

◆ Ubeta

float BLDCMotor::Ubeta

Phase voltages U alpha and U beta used for inverse Park and Clarke transform.

Definition at line 70 of file BLDCMotor.h.

◆ Uc

float BLDCMotor::Uc

Current phase voltages Ua,Ub and Uc set to motor.

Definition at line 69 of file BLDCMotor.h.


The documentation for this class was generated from the following files: