MotorWare f2806x Module API Documentation
float/clarke.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2014, 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 _CLARKE_H_
33 #define _CLARKE_H_
34 
40 
41 
42 // **************************************************************************
43 // the includes
44 
45 // modules
47 
48 
53 
54 
55 // Include the algorithm overview defined in modules/<module>/docs/doxygen/doxygen.h
57 
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 
64 // **************************************************************************
65 // the defines
66 
67 
68 
69 // **************************************************************************
70 // the typedefs
71 
74 typedef struct _CLARKE_Obj_
75 {
78 
79  uint_least8_t numSensors;
80 
81 } CLARKE_Obj;
82 
83 
86 typedef struct _CLARKE_Obj_ *CLARKE_Handle;
87 
88 
89 // **************************************************************************
90 // the globals
91 
92 
93 // **************************************************************************
94 // the function prototypes
95 
99 static inline uint_least8_t CLARKE_getNumSensors(CLARKE_Handle handle)
100 {
101  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
102 
103  return(obj->numSensors);
104 } // end of CLARKE_getNumSensors() function
105 
106 
111 extern CLARKE_Handle CLARKE_init(void *pMemory,const size_t numBytes);
112 
113 
118 static inline void CLARKE_run(CLARKE_Handle handle,const MATH_vec3 *pInVec,MATH_vec2 *pOutVec)
119 {
120  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
121 
122  uint_least8_t numSensors = obj->numSensors;
123 
124  float_t alpha_sf = obj->alpha_sf;
125  float_t beta_sf = obj->beta_sf;
126 
127 
128  if(numSensors == 3)
129  {
130  pOutVec->value[0] = ( (pInVec->value[0] * (float_t)2.0) - (pInVec->value[1] + pInVec->value[2]) ) * alpha_sf;
131  pOutVec->value[1] = (pInVec->value[1] - pInVec->value[2]) * beta_sf;
132  }
133 
134  else if(numSensors == 2)
135  {
136  pOutVec->value[0] = pInVec->value[0] * alpha_sf;
137  pOutVec->value[1] = (pInVec->value[0] + (pInVec->value[1] * (float_t)2.0)) * beta_sf;
138  }
139  else
140  {
141  // assign value 0 if all conditions fail
142  pOutVec->value[0] = (float_t)0;
143  pOutVec->value[1] = (float_t)0;
144  }
145 
146  return;
147 } // end of CLARKE_run() function
148 
149 
154 static inline void CLARKE_run_twoInput(CLARKE_Handle handle,const MATH_vec2 *pInVec,MATH_vec2 *pOutVec)
155 {
156  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
157 
158  float_t beta_sf = obj->beta_sf;
159 
160 
161  pOutVec->value[0] = pInVec->value[0];
162 
163  pOutVec->value[1] = (pInVec->value[0] + (pInVec->value[1] * (float_t)2.0)) * beta_sf;
164 
165  return;
166 } // end of CLARKE_run_twoInput() function
167 
168 
172 static inline void CLARKE_setNumSensors(CLARKE_Handle handle,const uint_least8_t numSensors)
173 {
174  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
175 
176  obj->numSensors = numSensors;
177 
178  return;
179 } // end of CLARKE_setNumSensors() function
180 
181 
186 static inline void CLARKE_setScaleFactors(CLARKE_Handle handle,const float_t alpha_sf,const float_t beta_sf)
187 {
188  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
189 
190 
191  obj->alpha_sf = alpha_sf;
192  obj->beta_sf = beta_sf;
193 
194  return;
195 } // end of CLARKE_setScaleFactors() function
196 
197 
198 #ifdef __cplusplus
199 }
200 #endif // extern "C"
201 
203 #endif // end of _CLARKE_H_ definition
204 
Defines the CLARKE object.
Definition: 32b/clarke.h:75
Contains the public interface to the math (MATH) module routines.
Defines a two element vector.
Definition: 32b/math.h:248
_iq value[3]
Definition: 32b/math.h:261
_iq beta_sf
the scale factor for the beta component
Definition: 32b/clarke.h:78
float_t beta_sf
the scale factor for the beta component
Definition: float/clarke.h:77
_iq alpha_sf
the scale factor for the alpha component
Definition: 32b/clarke.h:77
struct _CLARKE_Obj_ CLARKE_Obj
Defines the CLARKE object.
_iq value[2]
Definition: 32b/math.h:251
Defines a three element vector.
Definition: 32b/math.h:258
static uint_least8_t CLARKE_getNumSensors(CLARKE_Handle handle)
Gets the number of sensors.
Definition: float/clarke.h:99
float_t alpha_sf
the scale factor for the alpha component
Definition: float/clarke.h:76
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
Initializes the Clarke transform module.
Definition: 32b/clarke.c:55
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const float_t alpha_sf, const float_t beta_sf)
Sets the scale factors.
Definition: float/clarke.h:186
uint_least8_t numSensors
the number of sensors
Definition: 32b/clarke.h:80
struct _CLARKE_Obj_ * CLARKE_Handle
Defines the CLARKE handle.
Definition: float/clarke.h:86
static void CLARKE_run_twoInput(CLARKE_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
Runs the Clarke transform module for two inputs.
Definition: float/clarke.h:154
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
Sets the number of sensors.
Definition: float/clarke.h:172
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
Runs the Clarke transform module for three inputs.
Definition: float/clarke.h:118
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121