MotorWare f2806x Module API Documentation
float/offset.c
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--*/
37 
38 
39 // **************************************************************************
40 // the includes
41 
43 
44 
45 
46 // **************************************************************************
47 // the defines
48 
49 
50 // **************************************************************************
51 // the globals
52 
53 
54 // **************************************************************************
55 // the functions
56 
57 
59 {
60  OFFSET_Obj *obj = (OFFSET_Obj *)handle;
61  float_t b0;
62  float_t beta;
63 
64  b0 = FILTER_FO_get_b0(obj->filterHandle);
65 
66  beta = (float_t)2.0 * b0 / ((float_t)1.0 - b0);
67 
68  return(beta);
69 } // end of OFFSET_getBeta() function
70 
71 
72 OFFSET_Handle OFFSET_init(void *pMemory,const size_t numBytes)
73 {
74  OFFSET_Handle handle;
75  OFFSET_Obj *obj;
76 
77  if(numBytes < sizeof(OFFSET_Obj))
78  return((OFFSET_Handle)NULL);
79 
80  // assign the handle
81  handle = (OFFSET_Handle)pMemory;
82  obj = (OFFSET_Obj *)handle;
83 
84  obj->filterHandle = FILTER_FO_init(&(obj->filter),sizeof(obj->filter));
85 
86  return(handle);
87 } // end of OFFSET_init() function
88 
89 
90 void OFFSET_setBeta(OFFSET_Handle handle,const float_t beta_rad)
91 {
92  OFFSET_Obj *obj = (OFFSET_Obj *)handle;
93  float_t a1 = (beta_rad - (float_t)2.0) / (beta_rad + (float_t)2.0);
94  float_t b0 = beta_rad / (beta_rad + (float_t)2.0);
95  float_t b1 = b0;
96 
99 
100  return;
101 } // end of OFFSET_setBeta() function
102 
103 
104 void OFFSET_setInitCond(OFFSET_Handle handle,const float_t initCond)
105 {
106  OFFSET_Obj *obj = (OFFSET_Obj *)handle;
107 
108  FILTER_FO_setInitialConditions(obj->filterHandle,initCond,initCond);
109  obj->value = initCond;
110 
111  return;
112 } // end of OFFSET_setInitCond() function
113 
114 
115 void OFFSET_setOffset(OFFSET_Handle handle, float_t offsetValue)
116 {
117  OFFSET_Obj *obj = (OFFSET_Obj *)handle;
118 
119  obj->value = offsetValue;
120 
121  return;
122 } // end of OFFSET_setOffset() function
123 
124 // end of file
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
_iq value
the offset value (iq)
Definition: 32b/offset.h:85
void OFFSET_setOffset(OFFSET_Handle handle, float_t offsetValue)
Sets the offset value.
Definition: float/offset.c:115
FILTER_FO_Obj filter
the first order filter object used.
Definition: 32b/offset.h:87
FILTER_FO_Handle FILTER_FO_init(void *pMemory, const size_t numBytes)
Initializes the first-order filter.
Definition: 32b/filter_fo.c:94
void OFFSET_setBeta(OFFSET_Handle handle, const float_t beta_rad)
Sets the beta offset filter coefficient.
Definition: float/offset.c:90
void FILTER_FO_setNumCoeffs(FILTER_FO_Handle handle, const _iq b0, const _iq b1)
Sets the first-order filter numerator coefficients.
struct _OFFSET_Obj_ * OFFSET_Handle
Defines the OFFSET handle.
Definition: 32b/offset.h:95
static _iq FILTER_FO_get_b0(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b0.
void FILTER_FO_setInitialConditions(FILTER_FO_Handle handle, const _iq x1, const _iq y1)
Sets the initial conditions of the first-order filter.
void OFFSET_setInitCond(OFFSET_Handle handle, const float_t initCond)
Set the initial condition of the integrator or the value of y[n-1].
Definition: float/offset.c:104
FILTER_FO_Handle filterHandle
the first order filter handle.
Definition: 32b/offset.h:88
float_t OFFSET_getBeta(OFFSET_Handle handle)
Gets the beta offset filter coefficient.
Definition: float/offset.c:58
void FILTER_FO_setDenCoeffs(FILTER_FO_Handle handle, const _iq a1)
Sets the first-order filter denominator coefficients.
OFFSET_Handle OFFSET_init(void *pMemory, const size_t numBytes)
Initializes the offset.
Definition: float/offset.c:72
Contains the public interface to the offset (OFFSET) module routines.
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
Defines the offset (OFFSET) object.
Definition: 32b/offset.h:82