SimpleFOClibrary  2.1
foc_utils.h File Reference
#include "Arduino.h"

Go to the source code of this file.

Classes

struct  DQCurrent_s
 
struct  PhaseCurrent_s
 
struct  DQVoltage_s
 

Macros

#define _sign(a)   ( ( (a) < 0 ) ? -1 : ( (a) > 0 ) )
 
#define _round(x)   ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
 
#define _constrain(amt, low, high)   ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
 
#define _sqrt(a)   (_sqrtApprox(a))
 
#define _isset(a)   ( (a) != (NOT_SET) )
 
#define _2_SQRT3   1.15470053838
 
#define _SQRT3   1.73205080757
 
#define _1_SQRT3   0.57735026919
 
#define _SQRT3_2   0.86602540378
 
#define _SQRT2   1.41421356237
 
#define _120_D2R   2.09439510239
 
#define _PI   3.14159265359
 
#define _PI_2   1.57079632679
 
#define _PI_3   1.0471975512
 
#define _2PI   6.28318530718
 
#define _3PI_2   4.71238898038
 
#define _PI_6   0.52359877559
 
#define NOT_SET   -12345.0
 
#define _HIGH_IMPEDANCE   0
 
#define _HIGH_Z   _HIGH_IMPEDANCE
 
#define _ACTIVE   1
 

Functions

float _sin (float a)
 
float _cos (float a)
 
float _normalizeAngle (float angle)
 
float _electricalAngle (float shaft_angle, int pole_pairs)
 
float _sqrtApprox (float value)
 

Macro Definition Documentation

◆ _120_D2R

#define _120_D2R   2.09439510239

Definition at line 20 of file foc_utils.h.

◆ _1_SQRT3

#define _1_SQRT3   0.57735026919

Definition at line 17 of file foc_utils.h.

◆ _2_SQRT3

#define _2_SQRT3   1.15470053838

Definition at line 15 of file foc_utils.h.

◆ _2PI

#define _2PI   6.28318530718

Definition at line 24 of file foc_utils.h.

◆ _3PI_2

#define _3PI_2   4.71238898038

Definition at line 25 of file foc_utils.h.

◆ _ACTIVE

#define _ACTIVE   1

Definition at line 31 of file foc_utils.h.

◆ _constrain

#define _constrain (   amt,
  low,
  high 
)    ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))

Definition at line 10 of file foc_utils.h.

◆ _HIGH_IMPEDANCE

#define _HIGH_IMPEDANCE   0

Definition at line 29 of file foc_utils.h.

◆ _HIGH_Z

#define _HIGH_Z   _HIGH_IMPEDANCE

Definition at line 30 of file foc_utils.h.

◆ _isset

#define _isset (   a)    ( (a) != (NOT_SET) )

Definition at line 12 of file foc_utils.h.

◆ _PI

#define _PI   3.14159265359

Definition at line 21 of file foc_utils.h.

◆ _PI_2

#define _PI_2   1.57079632679

Definition at line 22 of file foc_utils.h.

◆ _PI_3

#define _PI_3   1.0471975512

Definition at line 23 of file foc_utils.h.

◆ _PI_6

#define _PI_6   0.52359877559

Definition at line 26 of file foc_utils.h.

◆ _round

#define _round (   x)    ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))

Definition at line 9 of file foc_utils.h.

◆ _sign

#define _sign (   a)    ( ( (a) < 0 ) ? -1 : ( (a) > 0 ) )

Definition at line 8 of file foc_utils.h.

◆ _sqrt

#define _sqrt (   a)    (_sqrtApprox(a))

Definition at line 11 of file foc_utils.h.

◆ _SQRT2

#define _SQRT2   1.41421356237

Definition at line 19 of file foc_utils.h.

◆ _SQRT3

#define _SQRT3   1.73205080757

Definition at line 16 of file foc_utils.h.

◆ _SQRT3_2

#define _SQRT3_2   0.86602540378

Definition at line 18 of file foc_utils.h.

◆ NOT_SET

#define NOT_SET   -12345.0

Definition at line 28 of file foc_utils.h.

Function Documentation

◆ _cos()

float _cos ( float  a)

Function approximating cosine calculation by using fixed size array

  • execution time ~50us (Arduino UNO)
Parameters
aangle in between 0 and 2PI

Definition at line 39 of file foc_utils.cpp.

◆ _electricalAngle()

float _electricalAngle ( float  shaft_angle,
int  pole_pairs 
)

Electrical angle calculation

Parameters
shaft_angle- shaft angle of the motor
pole_pairs- number of pole pairs

Definition at line 53 of file foc_utils.cpp.

◆ _normalizeAngle()

float _normalizeAngle ( float  angle)

normalizing radian angle to [0,2PI]

Parameters
angle- angle to be normalized

Definition at line 47 of file foc_utils.cpp.

◆ _sin()

float _sin ( float  a)

Function approximating the sine calculation by using fixed size array

  • execution time ~40us (Arduino UNO)
Parameters
aangle in between 0 and 2PI

Definition at line 14 of file foc_utils.cpp.

◆ _sqrtApprox()

float _sqrtApprox ( float  value)

Function approximating square root function

  • using fast inverse square root
Parameters
value- number

Definition at line 60 of file foc_utils.cpp.