clarke.h
Go to the documentation of this file.
1  //#############################################################################
2 //
3 // FILE: clarke.h
4 //
5 // TITLE: C28x Clarke transform library
6 //
7 //#############################################################################
8 // $TI Release: MotorControl SDK v1.00.00.00 $
9 // $Release Date: Mon Mar 11 18:37:40 CDT 2019 $
10 // $Copyright:
11 // Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
12 //
13 // Redistribution and use in source and binary forms, with or without
14 // modification, are permitted provided that the following conditions
15 // are met:
16 //
17 // Redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // Redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the
23 // distribution.
24 //
25 // Neither the name of Texas Instruments Incorporated nor the names of
26 // its contributors may be used to endorse or promote products derived
27 // from this software without specific prior written permission.
28 //
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 // $
41 //#############################################################################
42 
43 #ifndef CLARKE_H
44 #define CLARKE_H
45 
46 //*****************************************************************************
47 //
48 // If building with a C++ compiler, make all of the definitions in this header
49 // have a C binding.
50 //
51 //*****************************************************************************
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #endif
56 
57 //*****************************************************************************
58 //
61 //
62 //*****************************************************************************
63 
65 
66 //*****************************************************************************
67 //
69 //
70 //*****************************************************************************
71 typedef struct _CLARKE_Obj_
72 {
75  uint_least8_t numSensors;
76 } CLARKE_Obj;
77 
78 //*****************************************************************************
79 //
81 //
82 //*****************************************************************************
83 typedef struct _CLARKE_Obj_ *CLARKE_Handle;
84 
85 //*****************************************************************************
86 //
87 // Prototypes for the APIs
88 //
89 //*****************************************************************************
90 //*****************************************************************************
91 //
97 //
98 //*****************************************************************************
99 static inline uint_least8_t
101 {
102  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
103 
104  return(obj->numSensors);
105 } // end of CLARKE_getNumSensors() function
106 
107 //*****************************************************************************
108 //
116 //
117 //*****************************************************************************
118 extern CLARKE_Handle
119 CLARKE_init(void *pMemory, const size_t numBytes);
120 
121 extern CLARKE_Handle
122 cla_CLARKE_init(void *pMemory, const size_t numBytes);
123 
124 //*****************************************************************************
125 //
135 //
136 //*****************************************************************************
137 static inline void
138 CLARKE_run(CLARKE_Handle handle, const MATH_Vec3 *pInVec, MATH_Vec2 *pOutVec)
139 {
140  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
141 
142  uint_least8_t numSensors = obj->numSensors;
143 
144  float32_t alpha_sf = obj->alpha_sf;
145  float32_t beta_sf = obj->beta_sf;
146 
147  //
148  // Perform the Clarke transform for either 2 or 3 sensor setups
149  //
150  if(numSensors == 3)
151  {
152  pOutVec->value[0] =
153  ((pInVec->value[0] *
154  (float32_t)2.0f) - (pInVec->value[1] + pInVec->value[2])) * alpha_sf;
155  pOutVec->value[1] = (pInVec->value[1] - pInVec->value[2]) * beta_sf;
156  }
157  else if(numSensors == 2)
158  {
159  pOutVec->value[0] = pInVec->value[0] * alpha_sf;
160  pOutVec->value[1] =
161  (pInVec->value[0] + (pInVec->value[1] * (float32_t)2.0f)) * beta_sf;
162  }
163 
164  return;
165 } // end of CLARKE_run() function
166 
167 //*****************************************************************************
168 //
178 //
179 //*****************************************************************************
180 static inline void
182  MATH_Vec2 *pOutVec)
183 {
184  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
185 
186  float32_t beta_sf = obj->beta_sf;
187 
188  pOutVec->value[0] = pInVec->value[0];
189 
190  pOutVec->value[1] =
191  (pInVec->value[0] + (pInVec->value[1] * (float32_t)2.0)) * beta_sf;
192 
193  return;
194 } // end of CLARKE_run_twoInput() function
195 
196 //*****************************************************************************
197 //
205 //
206 //*****************************************************************************
207 static inline void
208 CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
209 {
210  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
211 
212  obj->numSensors = numSensors;
213 
214  return;
215 } // end of CLARKE_setNumSensors() function
216 
217 //*****************************************************************************
218 //
228 //
229 //*****************************************************************************
230 static inline void
232  const float32_t beta_sf)
233 {
234  CLARKE_Obj *obj = (CLARKE_Obj *)handle;
235 
236  obj->alpha_sf = alpha_sf;
237  obj->beta_sf = beta_sf;
238 
239  return;
240 } // end of CLARKE_setScaleFactors() function
241 
242 //*****************************************************************************
243 //
244 // Close the Doxygen group.
246 //
247 //*****************************************************************************
248 
249 //*****************************************************************************
250 //
251 // Mark the end of the C bindings section for C++ compilers.
252 //
253 //*****************************************************************************
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif // end of CLARKE_H defines
CLARKE_run_twoInput
static void CLARKE_run_twoInput(CLARKE_Handle handle, const MATH_Vec2 *pInVec, MATH_Vec2 *pOutVec)
Runs the Clarke transform module for two inputs.
Definition: clarke.h:181
_MATH_Vec2_
Defines a two element vector.
Definition: math.h:218
CLARKE_getNumSensors
static uint_least8_t CLARKE_getNumSensors(CLARKE_Handle handle)
Gets the number of sensors.
Definition: clarke.h:100
CLARKE_Obj
struct _CLARKE_Obj_ CLARKE_Obj
Defines the CLARKE object.
float32_t
float float32_t
Definition: sfra_f32.h:42
cla_CLARKE_init
CLARKE_Handle cla_CLARKE_init(void *pMemory, const size_t numBytes)
_CLARKE_Obj_::alpha_sf
float32_t alpha_sf
the scale factor for the alpha component
Definition: clarke.h:73
CLARKE_setScaleFactors
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const float32_t alpha_sf, const float32_t beta_sf)
Sets the scale factors.
Definition: clarke.h:231
_CLARKE_Obj_::numSensors
uint_least8_t numSensors
the number of sensors
Definition: clarke.h:75
CLARKE_init
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
Initializes the Clarke transform module.
math.h
CLARKE_setNumSensors
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
Sets the number of sensors.
Definition: clarke.h:208
_MATH_Vec3_::value
float32_t value[3]
Definition: math.h:232
_CLARKE_Obj_
Defines the CLARKE object.
Definition: clarke.h:71
CLARKE_Handle
struct _CLARKE_Obj_ * CLARKE_Handle
Defines the CLARKE handle.
Definition: clarke.h:83
CLARKE_run
static void CLARKE_run(CLARKE_Handle handle, const MATH_Vec3 *pInVec, MATH_Vec2 *pOutVec)
Runs the Clarke transform module for three inputs.
Definition: clarke.h:138
_CLARKE_Obj_::beta_sf
float32_t beta_sf
the scale factor for the beta component
Definition: clarke.h:74
_MATH_Vec2_::value
float32_t value[2]
Definition: math.h:220
_MATH_Vec3_
Defines a three element vector.
Definition: math.h:230

Copyright 2023, Texas Instruments Incorporated