Skip to content

Commit e2116fb

Browse files
author
camilo
committed
fix to numa & pid
1 parent 76d51e6 commit e2116fb

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
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.2.0",
19+
"version": "1.2.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.2.0
2+
version=1.2.1
33
license=MIT
44
author=J. Camilo Gomez C. <[email protected]>
55
maintainer=J. Camilo Gomez C. <[email protected]>

src/include/numa.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,23 @@ namespace qlibs {
8989
* @brief Perform a numerical integration step.
9090
* @param[in] s The input signal
9191
* @param[in] dt The time-step given in seconds.
92+
* @param[in] bUpdate Flag to update the states ( @c true by default).
9293
* @return The current value of the integration step.
9394
*/
9495
real_t integrate( const real_t s,
95-
const real_t dt ) noexcept;
96+
const real_t dt,
97+
const bool bUpdate = true ) noexcept;
9698

9799
/**
98100
* @brief Perform a numerical derivation step by using the delta rule.
99101
* @param[in] s The input signal
100102
* @param[in] dt The time-step given in seconds.
103+
* @param[in] bUpdate Flag to update the states ( @c true by default).
101104
* @return The current value of the derivation step.
102105
*/
103106
real_t derive( const real_t s,
104-
const real_t dt ) noexcept;
107+
const real_t dt,
108+
const bool bUpdate = true ) noexcept;
105109

106110
/**
107111
* @brief Set integration method .

src/numa.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ using namespace qlibs;
44

55
/*===========================================================================*/
66
void nState::init( const real_t x0,
7-
const real_t sn_1,
8-
const real_t sn_2 ) noexcept
7+
const real_t sn_1,
8+
const real_t sn_2 ) noexcept
99
{
1010
x[ 0 ] = x0;
1111
x[ 1 ] = sn_1;
1212
x[ 2 ] = sn_2;
1313
}
1414
/*===========================================================================*/
1515
real_t nState::integrate( const real_t s,
16-
const real_t dt ) noexcept
16+
const real_t dt,
17+
const bool bUpdate ) noexcept
1718
{
1819
switch( iMethod ) {
1920
case INTEGRATION_RECTANGULAR:
@@ -31,30 +32,36 @@ real_t nState::integrate( const real_t s,
3132
default:
3233
break;
3334
}
34-
update( s );
35+
if ( bUpdate ) {
36+
update( s );
37+
}
3538

3639
return x[ 0 ];
3740
}
3841
/*===========================================================================*/
3942
real_t nState::derive( const real_t s,
40-
const real_t dt ) noexcept
43+
const real_t dt,
44+
const bool bUpdate ) noexcept
4145
{
46+
float ds = 0.0F;
47+
4248
switch( dMethod ) {
4349
case DERIVATION_2POINTS:
44-
x[ 0 ] = ( s - x[ 1 ] )/dt;
50+
ds = ( s - x[ 1 ] )/dt;
4551
break;
4652
case DERIVATION_BACKWARD:
47-
x[ 0 ] = ( ( 3.0_re*s ) - ( 4.0_re*x[ 1 ] ) + x[ 2 ] )/( 2.0_re*dt );
53+
ds = ( ( 3.0_re*s ) - ( 4.0_re*x[ 1 ] ) + x[ 2 ] )/( 2.0_re*dt );
4854
break;
4955
case DERIVATION_FORWARD:
50-
x[ 0 ] = ( ( 4.0_re*x[ 1 ] ) - ( 3.0_re*x[ 2 ] ) - s )/( 2.0_re*dt );
56+
ds = ( ( 4.0_re*x[ 1 ] ) - ( 3.0_re*x[ 2 ] ) - s )/( 2.0_re*dt );
5157
break;
5258
default:
5359
break;
5460
}
61+
if ( bUpdate ) {
62+
update( s );
63+
}
5564

56-
update( s );
57-
58-
return x[ 0 ];
65+
return ds;
5966
}
6067
/*===========================================================================*/

src/pid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ real_t pidController::control( const real_t w,
265265
if ( ffmath::absf( e ) <= epsilon ) {
266266
e = 0.0_re;
267267
}
268-
ie = c_state.integrate( e + u1, dt );
268+
ie = c_state.integrate( e + u1, dt, false );
269269
de = c_state.derive( ( c*w ) - y , dt );
270270
D = de + beta*( D - de ); /*derivative filtering*/
271271
v = ( kc*( ( b*w ) - y ) ) + ( ki*ie ) + ( kd*D ); /*compute PID action*/

src/qlibs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.2.0"
45-
#define QLIBS_CPP_VERNUM ( 120U )
44+
#define QLIBS_CPP_VERSION "1.2.1"
45+
#define QLIBS_CPP_VERNUM ( 121U )
4646
#define QLIBS_CPP_CAPTION "qLibs++" QLIBS_CPP_VERSION
4747

4848
#include <include/qlibs_types.hpp>

0 commit comments

Comments
 (0)