MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

float/math.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 2012, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
32 #ifndef _MATH_H_
33 #define _MATH_H_
34
40
41
42 // **************************************************************************
43 // the includes
44
45 #include "sw/modules/types/src/types.h"
46
51
52
53 // Include the algorithm overview defined in modules/<module>/docs/doxygen/doxygen.h
55
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61
62 // **************************************************************************
63 // the defines
64
67 #define MATH_Nm_TO_lbin_SF ((float_t)(8.8507457913))
68
71 #define MATH_TWO_OVER_THREE ((float_t)(0.66666666666666666666666666666667))
72
75 #define MATH_ONE_OVER_THREE ((float_t)(0.33333333333333333333333333333333))
76
79 #define MATH_ONE_OVER_PI ((float_t)(0.318309886183791))
80
83 #define MATH_ONE_OVER_SQRT_THREE ((float_t)(0.57735026918962576450914878050196))
84
87 #define MATH_ONE_OVER_FOUR_PI ((float_t)(0.07957747154594767))
88
91 #define MATH_ONE_OVER_TWO_PI ((float_t) (0.1591549430918954))
92
95 #define MATH_PI ((float_t)(3.1415926535897932384626433832795))
96
99 #define MATH_PI_PU ((float_t)(0.5))
100
103 #define MATH_TWO_PI ((float_t)(6.283185307179586))
104
107 #define MATH_TWO_PI_PU ((float_t)(1.0))
108
111 #define MATH_FOUR_PI ((float_t)(12.56637061435917))
112
115 #define MATH_FOUR_PI_PU ((float_t)(2.0))
116
119 #define MATH_PI_OVER_TWO ((float_t)(1.570796326794897))
120
123 #define MATH_PI_OVER_TWO_PU ((float_t)(0.25))
124
127 #define MATH_PI_OVER_FOUR ((float_t)(0.785398163397448))
128
131 #define MATH_PI_OVER_FOUR_PU ((float_t)(0.125))
132
133
134 // **************************************************************************
135 // the typedefs
136
139 typedef struct _MATH_vec2_
140 {
141
142 float_t value[2];
143
144 } MATH_vec2;
145
146
149 typedef struct _MATH_vec3_
150 {
151
152 float_t value[3];
153
154 } MATH_vec3;
155
156
157 // **************************************************************************
158 // the function prototypes
159
160
164 static inline float_t MATH_abs(const float_t in)
165 {
166 float_t out = in;
167
168
169 if(in < (float_t)0.0)
170 {
171 out = -in;
172 }
173
174 return(out);
175 } // end of MATH_abs() function
176
177
182 #ifdef __TMS320C28XX_CLA__
183 #pragma FUNC_ALWAYS_INLINE(MATH_incrAngle)
184 #endif
185 static inline float_t MATH_incrAngle(const float_t angle_rad,const float_t angleDelta_rad)
186 {
187 float_t angleNew_rad;
188
189
190 // increment the angle
191 angleNew_rad = angle_rad + angleDelta_rad;
192
193
194 // check for limits
195 if(angleNew_rad > MATH_PI)
196 {
197 angleNew_rad -= MATH_TWO_PI;
198 }
199 else if(angleNew_rad < (-MATH_PI))
200 {
201 angleNew_rad += MATH_TWO_PI;
202 }
203 else
204 {
205 // doing nothing as of now
206 ;
207 }
208
209 return(angleNew_rad);
210 } // end of MATH_incrAngle() function
211
212
218 static inline float_t MATH_sat(const float_t in,const float_t max,const float_t min)
219 {
220 float_t out = in;
221
222
223 if(in < min)
224 {
225 out = min;
226 }
227 else if(in > max)
228 {
229 out = max;
230 }
231 else
232 {
233 // do nothing as of now
234 ;
235 }
236
237 return(out);
238 } // end of MATH_sat() function
239
240
241 #ifdef __cplusplus
242 }
243 #endif // extern "C"
244
246 #endif // end of _MATH_H_ definition
247
248
types.h
Contains the public interface to the types definitions.
_MATH_vec2_
Defines a two element vector.
Definition: 32b/math.h:248
MATH_TWO_PI
#define MATH_TWO_PI
Defines 2*pi.
Definition: float/math.h:103
_MATH_vec3_::value
_iq value[3]
Definition: 32b/math.h:261
MATH_PI
#define MATH_PI
Defines pi.
Definition: float/math.h:95
MATH_sat
static float_t MATH_sat(const float_t in, const float_t max, const float_t min)
Saturates the input value between the minimum and maximum values.
Definition: float/math.h:218
_MATH_vec2_::value
_iq value[2]
Definition: 32b/math.h:251
_MATH_vec3_
Defines a three element vector.
Definition: 32b/math.h:258
MATH_abs
static float_t MATH_abs(const float_t in)
Finds the absolute value.
Definition: float/math.h:164
MATH_vec3
struct _MATH_vec3_ MATH_vec3
Defines a three element vector.
MATH_incrAngle
static float_t MATH_incrAngle(const float_t angle_rad, const float_t angleDelta_rad)
Increments an angle value and handles wrap-around.
Definition: float/math.h:185
MATH_vec2
struct _MATH_vec2_ MATH_vec2
Defines a two element vector.
float_t
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121