MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

float/pid.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
42 #include "sw/modules/pid/src/float/pid.h"
43
44
45 // **************************************************************************
46 // the defines
47
48
49 // **************************************************************************
50 // the globals
51
52
53 // **************************************************************************
54 // the functions
55
56 void PID_getDerFilterParams(PID_Handle handle,
57 float_t *b0,float_t *b1,float_t *a1,
58 float_t *x1,float_t *y1)
59 {
60 PID_Obj *obj = (PID_Obj *)handle;
61
62 *b0 = FILTER_FO_get_b0(obj->derFilterHandle);
63 *b1 = FILTER_FO_get_b1(obj->derFilterHandle);
64 *a1 = FILTER_FO_get_a1(obj->derFilterHandle);
65 *x1 = FILTER_FO_get_x1(obj->derFilterHandle);
66 *y1 = FILTER_FO_get_y1(obj->derFilterHandle);
67
68 return;
69 } // end of PID_getDerFilterParams() function
70
71
72 PID_Handle PID_init(void *pMemory,const size_t numBytes)
73 {
74 PID_Handle handle;
75 PID_Obj *obj;
76
77
78 if(numBytes < sizeof(PID_Obj))
79 return((PID_Handle)NULL);
80
81 // assign the handle
82 handle = (PID_Handle)pMemory;
83
84 // assign a pointer
85 obj = (PID_Obj *)handle;
86
87 // initialize the derivative filter object
88 obj->derFilterHandle = FILTER_FO_init(&(obj->derFilter),sizeof(obj->derFilter));
89
90 return(handle);
91 } // end of PID_init() function
92
93
94 void PID_setDerFilterParams(PID_Handle handle,
95 const float_t b0,const float_t b1,const float_t a1,
96 const float_t x1,const float_t y1)
97 {
98 PID_Obj *obj = (PID_Obj *)handle;
99
100
101 FILTER_FO_setNumCoeffs(obj->derFilterHandle,b0,b1);
102 FILTER_FO_setDenCoeffs(obj->derFilterHandle,a1);
103 FILTER_FO_setInitialConditions(obj->derFilterHandle,x1,y1);
104
105 return;
106 } // end of PID_setDerFilterParams() function
107
108
109 // end of file
PID_setDerFilterParams
void PID_setDerFilterParams(PID_Handle handle, const float_t b0, const float_t b1, const float_t a1, const float_t x1, const float_t y1)
Sets the derivative filter parameters.
Definition: float/pid.c:94
FILTER_FO_get_y1
static _iq FILTER_FO_get_y1(FILTER_FO_Handle handle)
Gets the first-order filter output value at time sample n=-1.
Definition: 32b/filter_fo.h:148
FILTER_FO_init
FILTER_FO_Handle FILTER_FO_init(void *pMemory, const size_t numBytes)
Initializes the first-order filter.
Definition: 32b/filter_fo.c:94
FILTER_FO_setNumCoeffs
void FILTER_FO_setNumCoeffs(FILTER_FO_Handle handle, const _iq b0, const _iq b1)
Sets the first-order filter numerator coefficients.
Definition: 32b/filter_fo.c:133
_PID_Obj_::derFilterHandle
FILTER_FO_Handle derFilterHandle
the derivative filter handle
Definition: float/pid.h:90
FILTER_FO_get_b1
static _iq FILTER_FO_get_b1(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b1.
Definition: 32b/filter_fo.h:126
FILTER_FO_get_b0
static _iq FILTER_FO_get_b0(FILTER_FO_Handle handle)
Gets the first-order filter numerator coefficient b0.
Definition: 32b/filter_fo.h:115
PID_Handle
struct _PID_Obj_ * PID_Handle
Defines the PID handle.
Definition: 32b/pid.h:93
pid.h
Contains the public interface to the Proportional-Integral-Derivative (PID) controller module routine...
FILTER_FO_setInitialConditions
void FILTER_FO_setInitialConditions(FILTER_FO_Handle handle, const _iq x1, const _iq y1)
Sets the initial conditions of the first-order filter.
Definition: 32b/filter_fo.c:120
_PID_Obj_::derFilter
FILTER_FO_Obj derFilter
the derivative filter object
Definition: float/pid.h:91
PID_init
PID_Handle PID_init(void *pMemory, const size_t numBytes)
Initializes the PID controller.
Definition: float/pid.c:72
PID_getDerFilterParams
void PID_getDerFilterParams(PID_Handle handle, float_t *b0, float_t *b1, float_t *a1, float_t *x1, float_t *y1)
Gets the derivative filter parameters.
Definition: float/pid.c:56
FILTER_FO_setDenCoeffs
void FILTER_FO_setDenCoeffs(FILTER_FO_Handle handle, const _iq a1)
Sets the first-order filter denominator coefficients.
Definition: 32b/filter_fo.c:109
FILTER_FO_get_x1
static _iq FILTER_FO_get_x1(FILTER_FO_Handle handle)
Gets the first-order filter input value at time sample n=-1.
Definition: 32b/filter_fo.h:137
_PID_Obj_
Defines the PID controller object.
Definition: 32b/pid.h:74
FILTER_FO_get_a1
static _iq FILTER_FO_get_a1(FILTER_FO_Handle handle)
Gets the first-order filter denominator coefficient a1.
Definition: 32b/filter_fo.h:104
float_t
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121