CounterState.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX::
19 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
20 * @date 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 #include "../State.h"
27 
29 
30 namespace armarx
31 {
32  DEFINEEVENT(EvCounterFulfilled)
33  DEFINEEVENT(EvCounterNotFulfilled)
34 
35 
36  /**
37  * @class CounterStateTemplate
38  *
39  * Stateimplementation, that increments a given counter by one
40  * on the SystemObserver and installs 2 conditions with different events,
41  * which trigger on Counter-Threshold-Reached and Counter-Threshold-Not-Reached.
42  *
43  * You can pass your own events to this State as Template parameters.
44  * The first template parameter is the Event, that should be send on
45  * Counter-Threshold-Reached and the second template parameter is the Event,
46  * that should be send on Counter-Threshold-Not-Reached.
47  *
48  * @note If you want to use the Standardevents, just use the typedef
49  * @ref CounterState.
50  * @see @ref CounterState
51  */
52  template <class EventTypeConditionNotFulfilled = EvCounterNotFulfilled, class EventTypeConditionFulfilled = EvCounterFulfilled>
54  StateTemplate< CounterStateTemplate<EventTypeConditionNotFulfilled, EventTypeConditionFulfilled> >
55  {
57  {
58  this->addToInput("counterRef", VariantType::ChannelRef, false);
59  this->addToInput("counterThreshold", VariantType::Int, false);
60 
61  this->addToOutput("counterValue", VariantType::Int, false);
62  }
63 
64  void onEnter()
65  {
66 
67  DataFieldIdentifierPtr counter = State::getInput<ChannelRef>("counterRef")->getDataFieldIdentifier("value");
68  Literal notFullfilled(*counter,
69  "smaller",
70  Literal::createParameterList(State::getInput<int>("counterThreshold")));
71 
72 
73  this->getContext()->systemObserverPrx->incrementCounter(State::getInput<ChannelRef>("counterRef"));
74  cond1 = State::installCondition<EventTypeConditionNotFulfilled>(notFullfilled, "Counter maximum not reached");
75  cond2 = State::installCondition<EventTypeConditionFulfilled>(!notFullfilled, "Counter maximum reached");
76 
77  }
78 
79 
80  void onExit()
81  {
84  this->setOutput("counterValue", *State::getInput<ChannelRef>("counterRef")->getDataField("value"));
85  }
86  private:
87  ConditionIdentifier cond1, cond2;
88  };
89 
90  /**
91  * @ingroup StatechartGrp
92  * @brief CounterState is a typedef for the CounterStateTemplate, that uses
93  * the events EvCounterNotFulfilled and EvCounterFulfilled.
94  *
95  * @see CounterStateTemplate
96  */
98 }
99 
armarx::StateUtility::removeCondition
void removeCondition(ConditionIdentifier conditionId)
Utility function to remove an installed condition on the distributed conditionhandler.
Definition: StateUtil.cpp:131
armarx::StateTemplate
Definition: State.h:39
armarx::Literal::createParameterList
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition: Term.cpp:129
IceInternal::Handle< DataFieldIdentifier >
armarx::VariantType::ChannelRef
const VariantTypeId ChannelRef
Definition: ChannelRef.h:162
armarx::CounterStateTemplate
Definition: CounterState.h:53
armarx::CounterStateTemplate::onEnter
void onEnter()
Definition: CounterState.h:64
armarx::CounterStateTemplate::defineParameters
void defineParameters()
Definition: CounterState.h:56
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::Literal
Definition: Term.h:208
armarx::CounterStateTemplate::onExit
void onExit()
Definition: CounterState.h:80
armarx::DEFINEEVENT
DEFINEEVENT(EvInit) struct StateRun
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ChannelRef.h