InstallConditionExample.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 ArmarXCore::StatechartExamples::InstallConditionExample
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
30
31namespace armarx
32{
33
35 {
36 public:
37 // inherited from Component
38
39 virtual std::string
41 {
42 return "GraspPositionReached";
43 }
44
45 virtual void onInitStatechart();
46 virtual void onConnectStatechart();
47 };
48
49 DEFINEEVENT(EvConditionReached)
50 struct stateInstallCondition;
51
52 struct StatechartInstallConditionExample : StateTemplate<StatechartInstallConditionExample>
53 {
54
55 void
57 {
58 }
59
60 void
62 {
63 // add substates
64
65 setInitState(addState<stateInstallCondition>("ApproachGraspPosition"));
66 StatePtr final = addState<SuccessState>("Success");
67
68 // add transition
69 ParameterMappingPtr mapping =
70 ParameterMapping::createMapping()->mapFromOutput("hand_x", "position_x");
72 }
73
74 void
76 {
77 addToInput("hand_x", VariantType::Float, true);
78 addToOutput("hand_current_x", VariantType::Float, true);
79 }
80
81 void
83 {
84 }
85 };
86
87 struct stateInstallCondition : StateTemplate<stateInstallCondition>
88 {
89 ConditionIdentifier condId;
90
91 void
93 {
94 Literal checkAngles1("Armar4Observer.jointangles.LeftArm_Joint1",
95 "larger",
97 Literal checkAngles2("Armar4Observer.jointangles.LeftArm_Joint2",
98 "smaller",
100 Literal checkAngles3("Armar4Observer.jointangles.Torso_Joint2",
101 "larger",
103 condId = installCondition<EvConditionReached>((!checkAngles1 || !checkAngles2) &&
104 checkAngles3);
105 }
106
107 void
109 {
110
112 }
113 };
114
115
116} // namespace armarx
#define ARMARXCOMPONENT_IMPORT_EXPORT
#define DEFINEEVENT(NEWEVENT)
this macro declares a new event-class derived vom Event, to have a compiletime check for typos in eve...
virtual std::string getDefaultName() const
Retrieve default name of component.
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
static ParameterMappingPtr createMapping()
Creates a new instance of a ParameterMapping. Since the constructors are private, this method must be...
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.
StateBasePtr addState(StateBasePtr pNewState)
Definition State.cpp:140
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
StateBasePtr setInitState(StateBasePtr initState, ParameterMappingPtr initialStateMapping=ParameterMappingPtr())
Sets the initial substate of this state.
Definition State.cpp:354
TransitionIceBase & addTransition(EventPtr event, StateIceBasePtr sourceState, StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput=nullptr, ParameterMappingIceBasePtr mappingToParentStatesLocal=nullptr, ParameterMappingIceBasePtr mappingToParentStatesOutput=nullptr)
Definition State.cpp:250
bool addToOutput(const std::string &key, VariantTypeId type, bool optional)
Adds a key,type-pair to the output parameters.
Definition State.cpp:319
StateBasePtr getInitState() const
Getter for the initial state. The initial state is automatically entered, when this state is entered.
Definition State.cpp:107
const VariantTypeId Float
Definition Variant.h:919
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< State > StatePtr
Definition State.h:44
IceInternal::Handle< ParameterMapping > ParameterMappingPtr
void defineState()
Virtual function, in which this state can be configured.
void onEnter()
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void defineSubstates()
Virtual function, in which substates, transition and mappings can be added.
void defineParameters()
Virtual function, in which input/local/output parameters can be specified.
void onEnter()
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void onExit()
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...