Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
fb7c0376
Unverified
Commit
fb7c0376
authored
6 years ago
by
Daniel Agar
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
systemlib hysteresis improve field packing and cleanup
parent
d7ba8cc3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib/systemlib/hysteresis/hysteresis.cpp
+24
-7
24 additions, 7 deletions
src/lib/systemlib/hysteresis/hysteresis.cpp
src/lib/systemlib/hysteresis/hysteresis.h
+11
-23
11 additions, 23 deletions
src/lib/systemlib/hysteresis/hysteresis.h
with
35 additions
and
30 deletions
src/lib/systemlib/hysteresis/hysteresis.cpp
+
24
−
7
View file @
fb7c0376
...
...
@@ -37,13 +37,21 @@
* @author Julian Oes <julian@oes.ch>
*/
#include
<px4_log.h>
#include
"systemlib/hysteresis/hysteresis.h"
#include
"hysteresis.h"
namespace
systemlib
{
void
Hysteresis
::
set_hysteresis_time_from
(
const
bool
from_state
,
const
hrt_abstime
new_hysteresis_time_us
)
{
if
(
from_state
==
true
)
{
_time_from_true_us
=
new_hysteresis_time_us
;
}
else
{
_time_from_false_us
=
new_hysteresis_time_us
;
}
}
void
Hysteresis
::
set_state_and_update
(
const
bool
new_state
)
...
...
@@ -66,10 +74,19 @@ Hysteresis::update()
{
if
(
_requested_state
!=
_state
)
{
if
(
hrt_elapsed_time
(
&
_last_time_to_change_state
)
>=
(
_state
?
_hysteresis_time_from_true_us
:
_hysteresis_time_from_false_us
))
{
_state
=
_requested_state
;
const
hrt_abstime
elapsed
=
hrt_elapsed_time
(
&
_last_time_to_change_state
);
if
(
_state
&&
!
_requested_state
)
{
// true -> false
if
(
elapsed
>=
_time_from_true_us
)
{
_state
=
false
;
}
}
else
if
(
!
_state
&&
_requested_state
)
{
// false -> true
if
(
elapsed
>=
_time_from_false_us
)
{
_state
=
true
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/lib/systemlib/hysteresis/hysteresis.h
+
11
−
23
View file @
fb7c0376
...
...
@@ -49,31 +49,17 @@ namespace systemlib
class
Hysteresis
{
public:
Hysteresis
(
bool
init_state
)
:
explicit
Hysteresis
(
bool
init_state
)
:
_state
(
init_state
),
_requested_state
(
init_state
),
_hysteresis_time_from_true_us
(
0
),
_hysteresis_time_from_false_us
(
0
),
_last_time_to_change_state
(
0
)
_requested_state
(
init_state
)
{}
Hysteresis
()
=
delete
;
// no default constructor
~
Hysteresis
()
{}
void
set_hysteresis_time_from
(
const
bool
from_state
,
const
hrt_abstime
new_hysteresis_time_us
)
{
if
(
from_state
==
true
)
{
_hysteresis_time_from_true_us
=
new_hysteresis_time_us
;
~
Hysteresis
()
=
default
;
}
else
{
_hysteresis_time_from_false_us
=
new_hysteresis_time_us
;
}
}
bool
get_state
()
const
{
return
_state
;
}
bool
get_state
()
const
{
return
_state
;
}
void
set_hysteresis_time_from
(
const
bool
from_state
,
const
hrt_abstime
new_hysteresis_time_us
);
void
set_state_and_update
(
const
bool
new_state
);
...
...
@@ -81,11 +67,13 @@ public:
private
:
hrt_abstime
_last_time_to_change_state
{
0
};
hrt_abstime
_time_from_true_us
{
0
};
hrt_abstime
_time_from_false_us
{
0
};
bool
_state
;
bool
_requested_state
;
hrt_abstime
_hysteresis_time_from_true_us
;
hrt_abstime
_hysteresis_time_from_false_us
;
hrt_abstime
_last_time_to_change_state
;
};
}
// namespace systemlib
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment