Skip to content

Commit f5aab9c

Browse files
committed
Add Event::setOnlyUp
1 parent 5733488 commit f5aab9c

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

include/sot/core/event.hh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <dynamic-graph/pool.h>
2525
#include <dynamic-graph/command-bind.h>
2626
#include <dynamic-graph/command-getter.h>
27+
#include <dynamic-graph/command-setter.h>
2728

2829
#include <sot/core/config.hh>
2930

@@ -57,6 +58,12 @@ namespace dynamicgraph {
5758
" Get list of signals\n";
5859
addCommand ("list", new command::Getter<Event, std::string>
5960
(*this, &Event::getSignalsByName, docstring));
61+
62+
docstring =
63+
"\n"
64+
" Triggers an event only when condition goes from False to True\n";
65+
addCommand ("setOnlyUp", new command::Setter<Event, bool>
66+
(*this, &Event::setOnlyUp, docstring));
6067
}
6168

6269
~Event () {}
@@ -87,6 +94,11 @@ namespace dynamicgraph {
8794
return oss.str();
8895
}
8996

97+
void setOnlyUp (const bool& up)
98+
{
99+
onlyUp_ = up;
100+
}
101+
90102
private:
91103
typedef SignalBase<int>* Trigger_t;
92104
typedef std::vector<Trigger_t> Triggers_t;
@@ -95,11 +107,14 @@ namespace dynamicgraph {
95107
{
96108
const bool& val = conditionSIN (time);
97109
ret = (val != lastVal_);
110+
bool trigger = onlyUp_ ? (!lastVal_ && val) : ret;
98111
if (ret) {
99112
lastVal_ = val;
100-
for (Triggers_t::const_iterator _s = triggers.begin();
101-
_s != triggers.end(); ++_s)
102-
(*_s)->recompute (time);
113+
if (trigger) {
114+
for (Triggers_t::const_iterator _s = triggers.begin();
115+
_s != triggers.end(); ++_s)
116+
(*_s)->recompute (time);
117+
}
103118
}
104119
return ret;
105120
}
@@ -109,7 +124,7 @@ namespace dynamicgraph {
109124
Triggers_t triggers;
110125
SignalPtr <bool, int> conditionSIN;
111126

112-
bool lastVal_;
127+
bool lastVal_, onlyUp_;
113128
};
114129
} // namespace sot
115130
} // namespace dynamicgraph

0 commit comments

Comments
 (0)