![]() |
SimpleFOClibrary
2.1
|
#include <FOCMotor.h>
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... | |
| Sensor * | sensor |
| CurrentSense * | current_sense |
| Print * | monitor_port |
| Serial terminal variable if provided. More... | |
Generic motor class
Definition at line 57 of file FOCMotor.h.
| FOCMotor::FOCMotor | ( | ) |
Default constructor - setting all variabels to default values
Definition at line 6 of file FOCMotor.cpp.
|
pure virtual |
Motor disable function
Implemented in StepperMotor, and BLDCMotor.
| float FOCMotor::electricalAngle | ( | ) |
Electrical angle calculation
Definition at line 68 of file FOCMotor.cpp.
|
pure virtual |
Motor enable function
Implemented in StepperMotor, and BLDCMotor.
|
pure virtual |
Motor hardware init function
Implemented in StepperMotor, and BLDCMotor.
|
pure virtual |
Function initializing FOC algorithm and aligning sensor's and motors' zero position
| zero_electric_offset | value of the sensors absolute position electrical offset in respect to motor's electrical 0 position. |
| sensor_direction | sensor natural direction - default is CW |
Implemented in StepperMotor, and BLDCMotor.
| void FOCMotor::linkCurrentSense | ( | CurrentSense * | _current_sense | ) |
Function linking a motor and current sensing
| current_sense | CurrentSense class wrapper for the FOC algorihtm to read the motor current measurements |
CurrentSense linking method
Definition at line 51 of file FOCMotor.cpp.
| void FOCMotor::linkSensor | ( | Sensor * | _sensor | ) |
Function linking a motor and a sensor
| sensor | Sensor class wrapper for the FOC algorihtm to read the motor angle and velocity |
Sensor linking method
Definition at line 44 of file FOCMotor.cpp.
|
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
Implemented in StepperMotor, and BLDCMotor.
| 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.
|
pure virtual |
Function executing the control loops set by the controller parameter of the BLDCMotor.
| target | Either 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.
| float FOCMotor::shaftAngle | ( | ) |
Shaft angle calculation in radians [rad]
Definition at line 56 of file FOCMotor.cpp.
| 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.
| void FOCMotor::useMonitoring | ( | Print & | ) |
Function providing BLDCMotor class with the Serial interface and enabling monitoring mode
| serial | Monitoring Serial class reference |
Monitoring functions
Definition at line 76 of file FOCMotor.cpp.
| MotionControlType FOCMotor::controller |
parameter determining the control loop to be used
Definition at line 164 of file FOCMotor.h.
| DQCurrent_s FOCMotor::current |
current d and q current measured
Definition at line 139 of file FOCMotor.h.
| float FOCMotor::current_limit |
Current limitting variable - global limit.
Definition at line 151 of file FOCMotor.h.
| CurrentSense* FOCMotor::current_sense |
CurrentSense link
Definition at line 210 of file FOCMotor.h.
| float FOCMotor::current_sp |
target current ( q current )
Definition at line 135 of file FOCMotor.h.
| float FOCMotor::electrical_angle |
current electrical angle
Definition at line 133 of file FOCMotor.h.
| int8_t FOCMotor::enabled = 0 |
enabled or disabled motor flag
Definition at line 155 of file FOCMotor.h.
| FOCModulationType FOCMotor::foc_modulation |
parameter derterniming modulation algorithm
Definition at line 158 of file FOCMotor.h.
| LowPassFilter FOCMotor::LPF_angle {0.0} |
parameter determining the angle low pass filter configuration
Definition at line 174 of file FOCMotor.h.
| 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.
| 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.
| LowPassFilter FOCMotor::LPF_velocity {DEF_VEL_FILTER_Tf} |
parameter determining the velocity Low pass filter configuration
Definition at line 173 of file FOCMotor.h.
| 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.
| unsigned int FOCMotor::monitor_downsample = DEF_MON_DOWNSMAPLE |
show monitor outputs each monitor_downsample calls
Definition at line 196 of file FOCMotor.h.
| Print* FOCMotor::monitor_port |
Serial terminal variable if provided.
Definition at line 213 of file FOCMotor.h.
| 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.
| unsigned int FOCMotor::motion_cnt = 0 |
counting variable for downsampling for move commad
Definition at line 176 of file FOCMotor.h.
| 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.
| 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.
| float FOCMotor::phase_resistance |
motor phase resistance
Definition at line 146 of file FOCMotor.h.
| PIDController FOCMotor::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
Definition at line 168 of file FOCMotor.h.
| PIDController FOCMotor::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
Definition at line 167 of file FOCMotor.h.
| PIDController FOCMotor::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
Definition at line 171 of file FOCMotor.h.
| int FOCMotor::pole_pairs |
motor pole pairs number
Definition at line 147 of file FOCMotor.h.
| Sensor* FOCMotor::sensor |
| 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.
| float FOCMotor::sensor_offset |
user defined sensor zero offset
Definition at line 179 of file FOCMotor.h.
| float FOCMotor::shaft_angle |
current motor angle
Definition at line 132 of file FOCMotor.h.
| float FOCMotor::shaft_angle_sp |
current target angle
Definition at line 137 of file FOCMotor.h.
| float FOCMotor::shaft_velocity |
current motor velocity
Definition at line 134 of file FOCMotor.h.
| float FOCMotor::shaft_velocity_sp |
current target velocity
Definition at line 136 of file FOCMotor.h.
| float FOCMotor::target |
current target value - depends of the controller
Definition at line 131 of file FOCMotor.h.
| TorqueControlType FOCMotor::torque_controller |
parameter determining the torque control type
Definition at line 163 of file FOCMotor.h.
| float FOCMotor::velocity_index_search |
target velocity for index search
Definition at line 143 of file FOCMotor.h.
| float FOCMotor::velocity_limit |
Velocity limitting variable - global limit.
Definition at line 152 of file FOCMotor.h.
| DQVoltage_s FOCMotor::voltage |
current d and q voltage set to the motor
Definition at line 138 of file FOCMotor.h.
| float FOCMotor::voltage_limit |
Voltage limitting variable - global limit.
Definition at line 150 of file FOCMotor.h.
| float FOCMotor::voltage_sensor_align |
sensor and motor align voltage parameter
Definition at line 142 of file FOCMotor.h.
| float FOCMotor::zero_electric_angle = NOT_SET |
absolute zero electric angle - if available
Definition at line 180 of file FOCMotor.h.