Skip to content

Commit 2489475

Browse files
author
camilo
committed
fix saturation on numa int/der wrappers
1 parent 12063dd commit 2489475

File tree

6 files changed

+55
-44
lines changed

6 files changed

+55
-44
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"maintainer": true
1717
}
1818
],
19-
"version": "1.4.0",
19+
"version": "1.4.1",
2020
"license": "MIT",
2121
"frameworks": "arduino",
2222
"platforms": "*"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=qlibs
2-
version=1.4.0
2+
version=1.4.1
33
license=MIT
44
author=J. Camilo Gomez C. <[email protected]>
55
maintainer=J. Camilo Gomez C. <[email protected]>

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required( VERSION 3.2 )
22
project( qlibs-cpp
3-
VERSION 1.4.0
3+
VERSION 1.4.1
44
DESCRIPTION "A collection of useful C++ libraries for embedded systems"
55
LANGUAGES CXX )
66

src/include/numa.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ namespace qlibs {
5050
class nState {
5151
private:
5252
real_t x[ 3 ] = { 0.0_re, 0.0_re, 0.0_re };
53+
real_t vmin{ -REAL_MAX };
54+
real_t vmax{ +REAL_MAX };
5355
void inline update( const real_t &s )
5456
{
5557
x[ 2 ] = x[ 1 ];
@@ -153,7 +155,18 @@ namespace qlibs {
153155
dMethod = m;
154156
}
155157

156-
/**
158+
/**
159+
* @brief Sets the saturation limits for the integrator output.
160+
* @param[in] minV The minimum value the output can reach.
161+
* @param[in] maxV The maximum value the output can reach.
162+
* @return @c true if the limits are valid and applied; @c false
163+
* otherwise (e.g., minV > maxV).
164+
* @note If not set, the output is unbounded.
165+
*/
166+
bool setSaturation( const real_t minV,
167+
const real_t maxV ) noexcept;
168+
169+
/**
157170
* @brief Get the value of the state.
158171
* @return The current value of the state.
159172
*/
@@ -222,8 +235,6 @@ namespace qlibs {
222235
class integrator : public nState, private nonCopyable {
223236
private:
224237
real_t dt;
225-
real_t min{ -REAL_MAX };
226-
real_t max{ +REAL_MAX };
227238
public:
228239
virtual ~integrator() {}
229240

@@ -240,15 +251,6 @@ namespace qlibs {
240251
integrator( const real_t timeStep,
241252
const real_t initialCondition = 0.0_re );
242253

243-
/**
244-
* @brief Sets the saturation limits for the integrator output.
245-
* @param[in] minV The minimum value the output can reach.
246-
* @param[in] maxV The maximum value the output can reach.
247-
* @return @c true if the limits are valid and applied; @c false
248-
* otherwise (e.g., minV > maxV).
249-
* @note If not set, the output is unbounded.
250-
*/
251-
bool setSaturation( const real_t minV, const real_t maxV ) noexcept;
252254

253255
/**
254256
* @brief Performs one step of numerical integration.

src/numa.cpp

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ real_t nState::integrate( const real_t s,
3232
default:
3333
break;
3434
}
35+
36+
if ( x[ 0 ] > vmax ) {
37+
x[ 0 ] = vmax;
38+
}
39+
else if ( x[ 0 ] < vmin ) {
40+
x[ 0 ] = vmin;
41+
}
42+
else {
43+
/*nothing to do*/
44+
}
45+
3546
if ( bUpdate ) {
3647
update( s );
3748
}
@@ -58,48 +69,46 @@ real_t nState::derive( const real_t s,
5869
default:
5970
break;
6071
}
72+
73+
if ( x[ 0 ] > vmax ) {
74+
x[ 0 ] = vmax;
75+
}
76+
else if ( x[ 0 ] < vmin ) {
77+
x[ 0 ] = vmin;
78+
}
79+
else {
80+
/*nothing to do*/
81+
}
82+
6183
if ( bUpdate ) {
6284
update( s );
6385
}
6486

6587
return ds;
6688
}
6789
/*===========================================================================*/
68-
integrator::integrator(const real_t timeStep, const real_t initialCondition )
69-
: dt( timeStep )
70-
{
71-
init( initialCondition, initialCondition, initialCondition );
72-
}
73-
/*===========================================================================*/
74-
bool integrator::setSaturation( const real_t minV,
75-
const real_t maxV ) noexcept
90+
bool nState::setSaturation( const real_t minV,
91+
const real_t maxV ) noexcept
7692
{
7793
bool retValue = false;
7894

7995
if ( maxV > minV ) {
80-
min = minV;
81-
max = maxV;
96+
vmin = minV;
97+
vmax = maxV;
8298
retValue = true;
8399
}
84100
return retValue;
85101
}
86102
/*===========================================================================*/
103+
integrator::integrator(const real_t timeStep, const real_t initialCondition )
104+
: dt( timeStep )
105+
{
106+
init( initialCondition, initialCondition, initialCondition );
107+
}
108+
/*===========================================================================*/
87109
real_t integrator::operator()( const real_t xDot )
88110
{
89-
real_t xt;
90-
91-
xt = integrate( xDot, dt );
92-
if ( xt > max ) {
93-
xt = max;
94-
}
95-
else if ( xt < min ) {
96-
xt = min;
97-
}
98-
else {
99-
/*nothing to do*/
100-
}
101-
102-
return xt;
111+
return integrate( xDot, dt );
103112
}
104113
/*===========================================================================*/
105114
real_t integrator::operator()() const

src/qlibs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @file qlibs.h
33
* @author J. Camilo Gomez C.
4-
* @version 1.4.0
4+
* @version 1.4.1
55
* @note This file is part of the qlibs++ distribution.
66
* @brief Global inclusion header
77
**/
@@ -41,8 +41,8 @@ This file is part of the QuarkTS++ OS distribution.
4141
#ifndef QLIBS_CPP_H
4242
#define QLIBS_CPP_H
4343

44-
#define QLIBS_CPP_VERSION "1.4.0"
45-
#define QLIBS_CPP_VERNUM ( 140 )
44+
#define QLIBS_CPP_VERSION "1.4.1"
45+
#define QLIBS_CPP_VERNUM ( 141 )
4646
#define QLIBS_CPP_CAPTION "qLibs++ " QLIBS_CPP_VERSION
4747

4848
#include <include/qlibs_types.hpp>
@@ -62,7 +62,7 @@ This file is part of the QuarkTS++ OS distribution.
6262

6363
namespace qlibs {
6464
namespace build {
65-
constexpr const uint32_t number = 2458;
65+
constexpr const uint32_t number = 2462;
6666
constexpr const char* date = __DATE__;
6767
constexpr const char* time = __TIME__;
6868
constexpr const char* std = "c++11";
@@ -72,7 +72,7 @@ This file is part of the QuarkTS++ OS distribution.
7272
constexpr const uint8_t number = QLIBS_CPP_VERNUM;
7373
constexpr const uint8_t mayor = 1U;
7474
constexpr const uint8_t minor = 4U;
75-
constexpr const uint8_t rev = 0U;
75+
constexpr const uint8_t rev = 1U;
7676
}
7777
namespace product {
7878
constexpr const char* author = "J. Camilo Gomez C.";

0 commit comments

Comments
 (0)