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
30namespace 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
71 State::getInput<ChannelRef>("counterRef")->getDataFieldIdentifier("value");
72 Literal notFullfilled(
73 *counter,
74 "smaller",
76
77
78 this->getContext()->systemObserverPrx->incrementCounter(
79 State::getInput<ChannelRef>("counterRef"));
81 notFullfilled, "Counter maximum not reached");
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
#define DEFINEEVENT(NEWEVENT)
this macro declares a new event-class derived vom Event, to have a compiletime check for typos in eve...
Literals are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:209
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition Term.cpp:142
ContextType * getContext() const
Definition StateBase.h:71
void removeCondition(ConditionIdentifier conditionId)
Utility function to remove an installed condition on the distributed conditionhandler.
ConditionIdentifier installCondition(const Term &condition, const EventPtr evt, const std::string &desc="")
Utility function to install a condition on the distributed conditionhandler.
void setOutput(std::string const &key, const Variant &value)
setOuput() sets an output parameter of this state.
Definition State.cpp:482
bool addToInput(const std::string &key, const ContainerType &type, bool optional, VariantContainerBasePtr defaultValue=VariantContainerBasePtr())
Adds a key,type-pair to the input parameters.
Definition State.cpp:309
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getInput(const std::string &key) const
getInput can be used to access a specific input parameter.
Definition State.h:620
bool addToOutput(const std::string &key, VariantTypeId type, bool optional)
Adds a key,type-pair to the output parameters.
Definition State.cpp:319
CounterStateTemplate< EvCounterNotFulfilled, EvCounterFulfilled > CounterState
CounterState is a typedef for the CounterStateTemplate, that uses the events EvCounterNotFulfilled an...
const VariantTypeId Int
Definition Variant.h:917
const VariantTypeId ChannelRef
Definition ChannelRef.h:169
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< DataFieldIdentifier > DataFieldIdentifierPtr
Typedef of DataFieldIdentifierPtr as IceInternal::Handle<DataFieldIdentifier> for convenience.
Stateimplementation, that increments a given counter by one on the SystemObserver and installs 2 cond...
void onEnter()
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void defineParameters()
Virtual function, in which input/local/output parameters can be specified.
void onExit()
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...