AM263x Motor Control SDK  09.02.00
dcl_clamp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated - https://www.ti.com/
3  *
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
15  * distribution.
16  *
17  * * Neither the name of Texas Instruments Incorporated nor the names of
18  * its contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _DCL_CLAMP_H_
35 #define _DCL_CLAMP_H_
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
49 //--- Controller clamping functions ------------------------------------
50 
59 bool DCL_runClamp(float32_t *data, float32_t Umax, float32_t Umin)
60 {
61  float32_t orig = *(data);
62  *(data) = (*(data) > Umax) ? Umax : *(data);
63  *(data) = (*(data) < Umin) ? Umin : *(data);
64  return(((orig < Umax) && (orig > Umin)) ? false : true);
65 }
66 
76 {
77  float64_t orig = *(data);
78  *(data) = (*(data) > Umax) ? Umax : *(data);
79  *(data) = (*(data) < Umin) ? Umin : *(data);
80  return(((orig < Umax) && (orig > Umin)) ? false : true);
81 }
82 
89 #define DCL_runSat(data,Umax,Umin) (data > Umax) ? Umax : (data < Umin) ? Umin : data
90 
93 #ifdef __cplusplus
94 }
95 #endif // extern "C"
96 
97 #endif // _DCL_CLAMP_H_
_DCL_CODE_ACCESS
#define _DCL_CODE_ACCESS
Defines the scope of dcl functions.
Definition: dcl_common.h:63
DCL_runClampF64
_DCL_CODE_ACCESS bool DCL_runClampF64(float64_t *data, float64_t Umax, float64_t Umin)
Saturates a control variable and returns true if either limit is exceeded.
Definition: dcl_clamp.h:75
DCL_runClamp
_DCL_CODE_ACCESS bool DCL_runClamp(float32_t *data, float32_t Umax, float32_t Umin)
Saturates a control variable and returns true if either limit is exceeded.
Definition: dcl_clamp.h:59
float64_t
double float64_t
Definition: dcl_common.h:59
float32_t
float float32_t
Definition: dcl_common.h:58