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
27 
28 #include "../State.h"
29 
30 namespace armarx
31 {
32  DEFINEEVENT(EvCounterFulfilled)
33  DEFINEEVENT(EvCounterNotFulfilled)
34 
35  /**
36  * @class CounterStateTemplate
37  *
38  * Stateimplementation, that increments a given counter by one
39  * on the SystemObserver and installs 2 conditions with different events,
40  * which trigger on Counter-Threshold-Reached and Counter-Threshold-Not-Reached.
41  *
42  * You can pass your own events to this State as Template parameters.
43  * The first template parameter is the Event, that should be send on
44  * Counter-Threshold-Reached and the second template parameter is the Event,
45  * that should be send on Counter-Threshold-Not-Reached.
46  *
47  * @note If you want to use the Standardevents, just use the typedef
48  * @ref CounterState.
49  * @see @ref CounterState
50  */
51  template <class EventTypeConditionNotFulfilled = EvCounterNotFulfilled,
52  class EventTypeConditionFulfilled = EvCounterFulfilled>
55  CounterStateTemplate<EventTypeConditionNotFulfilled, EventTypeConditionFulfilled>>
56  {
57  void
59  {
60  this->addToInput("counterRef", VariantType::ChannelRef, false);
61  this->addToInput("counterThreshold", VariantType::Int, false);
62 
63  this->addToOutput("counterValue", VariantType::Int, false);
64  }
65 
66  void
68  {
69 
70  DataFieldIdentifierPtr counter =
71  State::getInput<ChannelRef>("counterRef")->getDataFieldIdentifier("value");
72  Literal notFullfilled(
73  *counter,
74  "smaller",
75  Literal::createParameterList(State::getInput<int>("counterThreshold")));
76 
77 
78  this->getContext()->systemObserverPrx->incrementCounter(
79  State::getInput<ChannelRef>("counterRef"));
80  cond1 = State::installCondition<EventTypeConditionNotFulfilled>(
81  notFullfilled, "Counter maximum not reached");
82  cond2 = State::installCondition<EventTypeConditionFulfilled>(!notFullfilled,
83  "Counter maximum reached");
84  }
85 
86  void
88  {
91  this->setOutput("counterValue",
92  *State::getInput<ChannelRef>("counterRef")->getDataField("value"));
93  }
94 
95  private:
96  ConditionIdentifier cond1, cond2;
97  };
98 
99  /**
100  * @ingroup StatechartGrp
101  * @brief CounterState is a typedef for the CounterStateTemplate, that uses
102  * the events EvCounterNotFulfilled and EvCounterFulfilled.
103  *
104  * @see CounterStateTemplate
105  */
107 } // namespace armarx
armarx::StateUtility::removeCondition
void removeCondition(ConditionIdentifier conditionId)
Utility function to remove an installed condition on the distributed conditionhandler.
Definition: StateUtil.cpp:148
armarx::StateTemplate
Definition: State.h:38
armarx::Literal::createParameterList
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition: Term.cpp:142
IceInternal::Handle< DataFieldIdentifier >
armarx::VariantType::ChannelRef
const VariantTypeId ChannelRef
Definition: ChannelRef.h:169
armarx::CounterStateTemplate
Definition: CounterState.h:53
armarx::CounterStateTemplate::onEnter
void onEnter()
Definition: CounterState.h:67
armarx::CounterStateTemplate::defineParameters
void defineParameters()
Definition: CounterState.h:58
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:917
armarx::Literal
Definition: Term.h:208
armarx::CounterStateTemplate::onExit
void onExit()
Definition: CounterState.h:87
armarx::DEFINEEVENT
DEFINEEVENT(EvInit) struct StateRun
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ChannelRef.h