SimpleFOClibrary  2.1
FOCMotor Class Referenceabstract

#include <FOCMotor.h>

Inheritance diagram for FOCMotor:
BLDCMotor StepperMotor

Public Member Functions

 FOCMotor ()
 
virtual void init ()=0
 
virtual void disable ()=0
 
virtual void enable ()=0
 
void linkSensor (Sensor *sensor)
 
void linkCurrentSense (CurrentSense *current_sense)
 
virtual int initFOC (float zero_electric_offset=NOT_SET, Direction sensor_direction=Direction::CW)=0
 
virtual void loopFOC ()=0
 
virtual void move (float target=NOT_SET)=0
 
float shaftAngle ()
 
float shaftVelocity ()
 
float electricalAngle ()
 
void useMonitoring (Print &serial)
 
void monitor ()
 

Public Attributes

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

Generic motor class

Definition at line 57 of file FOCMotor.h.

Constructor & Destructor Documentation

◆ FOCMotor()

FOCMotor::FOCMotor ( )

Default constructor - setting all variabels to default values

Definition at line 6 of file FOCMotor.cpp.

Member Function Documentation

◆ disable()

virtual void FOCMotor::disable ( )
pure virtual

Motor disable function

Implemented in StepperMotor, and BLDCMotor.

◆ electricalAngle()

float FOCMotor::electricalAngle ( )

Electrical angle calculation

Definition at line 68 of file FOCMotor.cpp.

◆ enable()

virtual void FOCMotor::enable ( )
pure virtual

Motor enable function

Implemented in StepperMotor, and BLDCMotor.

◆ init()

virtual void FOCMotor::init ( )
pure virtual

Motor hardware init function

Implemented in StepperMotor, and BLDCMotor.

◆ initFOC()

virtual int FOCMotor::initFOC ( float  zero_electric_offset = NOT_SET,
Direction  sensor_direction = Direction::CW 
)
pure virtual

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

  • If zero_electric_offset parameter is set the alignment procedure is skipped
Parameters
zero_electric_offsetvalue of the sensors absolute position electrical offset in respect to motor's electrical 0 position.
sensor_directionsensor natural direction - default is CW

Implemented in StepperMotor, and BLDCMotor.

◆ linkCurrentSense()

void FOCMotor::linkCurrentSense ( CurrentSense _current_sense)

Function linking a motor and current sensing

Parameters
current_senseCurrentSense class wrapper for the FOC algorihtm to read the motor current measurements

CurrentSense linking method

Definition at line 51 of file FOCMotor.cpp.

◆ linkSensor()

void FOCMotor::linkSensor ( Sensor _sensor)

Function linking a motor and a sensor

Parameters
sensorSensor class wrapper for the FOC algorihtm to read the motor angle and velocity

Sensor linking method

Definition at line 44 of file FOCMotor.cpp.

◆ loopFOC()

virtual void FOCMotor::loopFOC ( )
pure virtual

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

Implemented in StepperMotor, and BLDCMotor.

◆ monitor()

void FOCMotor::monitor ( )

Utility function intended to be used with serial plotter to monitor motor variables significantly slowing the execution down!!!!

Definition at line 83 of file FOCMotor.cpp.

◆ move()

virtual void FOCMotor::move ( float  target = NOT_SET)
pure virtual

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

Implemented in StepperMotor, and BLDCMotor.

◆ shaftAngle()

float FOCMotor::shaftAngle ( )

Shaft angle calculation in radians [rad]

Definition at line 56 of file FOCMotor.cpp.

◆ shaftVelocity()

float FOCMotor::shaftVelocity ( )

Shaft angle calculation function in radian per second [rad/s] It implements low pass filtering

Definition at line 62 of file FOCMotor.cpp.

◆ useMonitoring()

void FOCMotor::useMonitoring ( Print &  print)

Function providing BLDCMotor class with the Serial interface and enabling monitoring mode

Parameters
serialMonitoring Serial class reference

Monitoring functions

Definition at line 76 of file FOCMotor.cpp.

Member Data Documentation

◆ controller

MotionControlType FOCMotor::controller

parameter determining the control loop to be used

Definition at line 164 of file FOCMotor.h.

◆ current

DQCurrent_s FOCMotor::current

current d and q current measured

Definition at line 139 of file FOCMotor.h.

◆ current_limit

float FOCMotor::current_limit

Current limitting variable - global limit.

Definition at line 151 of file FOCMotor.h.

◆ current_sense

CurrentSense* FOCMotor::current_sense

CurrentSense link

Definition at line 210 of file FOCMotor.h.

◆ current_sp

float FOCMotor::current_sp

target current ( q current )

Definition at line 135 of file FOCMotor.h.

◆ electrical_angle

float FOCMotor::electrical_angle

current electrical angle

Definition at line 133 of file FOCMotor.h.

◆ enabled

int8_t FOCMotor::enabled = 0

enabled or disabled motor flag

Definition at line 155 of file FOCMotor.h.

◆ foc_modulation

FOCModulationType FOCMotor::foc_modulation

parameter derterniming modulation algorithm

Definition at line 158 of file FOCMotor.h.

◆ LPF_angle

LowPassFilter FOCMotor::LPF_angle {0.0}

parameter determining the angle low pass filter configuration

Definition at line 174 of file FOCMotor.h.

◆ LPF_current_d

LowPassFilter FOCMotor::LPF_current_d {DEF_CURR_FILTER_Tf}

parameter determining the current Low pass filter configuration

Definition at line 170 of file FOCMotor.h.

◆ LPF_current_q

LowPassFilter FOCMotor::LPF_current_q {DEF_CURR_FILTER_Tf}

parameter determining the current Low pass filter configuration

Definition at line 169 of file FOCMotor.h.

◆ LPF_velocity

LowPassFilter FOCMotor::LPF_velocity {DEF_VEL_FILTER_Tf}

parameter determining the velocity Low pass filter configuration

Definition at line 173 of file FOCMotor.h.

◆ modulation_centered

int8_t FOCMotor::modulation_centered = 1

flag (1) centered modulation around driver limit /2 or (0) pulled to 0

Definition at line 159 of file FOCMotor.h.

◆ monitor_downsample

unsigned int FOCMotor::monitor_downsample = DEF_MON_DOWNSMAPLE

show monitor outputs each monitor_downsample calls

Definition at line 196 of file FOCMotor.h.

◆ monitor_port

Print* FOCMotor::monitor_port

Serial terminal variable if provided.

Definition at line 213 of file FOCMotor.h.

◆ monitor_variables

uint8_t FOCMotor::monitor_variables = _MON_TARGET | _MON_VOLT_Q | _MON_VEL | _MON_ANGLE

Bit array holding the map of variables the user wants to monitor.

Definition at line 198 of file FOCMotor.h.

◆ motion_cnt

unsigned int FOCMotor::motion_cnt = 0

counting variable for downsampling for move commad

Definition at line 176 of file FOCMotor.h.

◆ motion_downsample

unsigned int FOCMotor::motion_downsample = DEF_MOTION_DOWNSMAPLE

parameter defining the ratio of downsampling for move commad

Definition at line 175 of file FOCMotor.h.

◆ P_angle

PIDController FOCMotor::P_angle {DEF_P_ANGLE_P,0,0,1e10,DEF_VEL_LIM}

parameter determining the position PID configuration

Definition at line 172 of file FOCMotor.h.

◆ phase_resistance

float FOCMotor::phase_resistance

motor phase resistance

Definition at line 146 of file FOCMotor.h.

◆ PID_current_d

parameter determining the d current PID config

Definition at line 168 of file FOCMotor.h.

◆ PID_current_q

parameter determining the q current PID config

Definition at line 167 of file FOCMotor.h.

◆ PID_velocity

parameter determining the velocity PID configuration

Definition at line 171 of file FOCMotor.h.

◆ pole_pairs

int FOCMotor::pole_pairs

motor pole pairs number

Definition at line 147 of file FOCMotor.h.

◆ sensor

Sensor* FOCMotor::sensor

Sensor link:

Definition at line 206 of file FOCMotor.h.

◆ sensor_direction

int FOCMotor::sensor_direction = NOT_SET

if sensor_direction == Direction::CCW then direction will be flipped to CW

Definition at line 181 of file FOCMotor.h.

◆ sensor_offset

float FOCMotor::sensor_offset

user defined sensor zero offset

Definition at line 179 of file FOCMotor.h.

◆ shaft_angle

float FOCMotor::shaft_angle

current motor angle

Definition at line 132 of file FOCMotor.h.

◆ shaft_angle_sp

float FOCMotor::shaft_angle_sp

current target angle

Definition at line 137 of file FOCMotor.h.

◆ shaft_velocity

float FOCMotor::shaft_velocity

current motor velocity

Definition at line 134 of file FOCMotor.h.

◆ shaft_velocity_sp

float FOCMotor::shaft_velocity_sp

current target velocity

Definition at line 136 of file FOCMotor.h.

◆ target

float FOCMotor::target

current target value - depends of the controller

Definition at line 131 of file FOCMotor.h.

◆ torque_controller

TorqueControlType FOCMotor::torque_controller

parameter determining the torque control type

Definition at line 163 of file FOCMotor.h.

◆ velocity_index_search

float FOCMotor::velocity_index_search

target velocity for index search

Definition at line 143 of file FOCMotor.h.

◆ velocity_limit

float FOCMotor::velocity_limit

Velocity limitting variable - global limit.

Definition at line 152 of file FOCMotor.h.

◆ voltage

DQVoltage_s FOCMotor::voltage

current d and q voltage set to the motor

Definition at line 138 of file FOCMotor.h.

◆ voltage_limit

float FOCMotor::voltage_limit

Voltage limitting variable - global limit.

Definition at line 150 of file FOCMotor.h.

◆ voltage_sensor_align

float FOCMotor::voltage_sensor_align

sensor and motor align voltage parameter

Definition at line 142 of file FOCMotor.h.

◆ zero_electric_angle

float FOCMotor::zero_electric_angle = NOT_SET

absolute zero electric angle - if available

Definition at line 180 of file FOCMotor.h.


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