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 
31 namespace 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");
71  addTransition<EvConditionReached>(getInitState(), final, mapping);
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 
111  removeCondition(condId);
112  }
113  };
114 
115 
116 } // namespace armarx
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::StatechartInstallConditionExample::defineSubstates
void defineSubstates()
Definition: InstallConditionExample.h:61
armarx::stateInstallCondition::condId
ConditionIdentifier condId
Definition: InstallConditionExample.h:89
armarx::StateTemplate
Definition: State.h:38
armarx::ParameterMapping::createMapping
static ParameterMappingPtr createMapping()
Creates a new instance of a ParameterMapping. Since the constructors are private, this method must be...
Definition: ParameterMapping.cpp:573
armarx::stateInstallCondition::onExit
void onExit()
Definition: InstallConditionExample.h:108
armarx::stateInstallCondition
Definition: InstallConditionExample.h:87
armarx::Literal::createParameterList
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition: Term.cpp:142
armarx::InstallConditionExample
Definition: InstallConditionExample.h:34
Statechart.h
IceInternal::Handle< State >
armarx::stateInstallCondition::onEnter
void onEnter()
Definition: InstallConditionExample.h:92
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::StatechartInstallConditionExample::onEnter
void onEnter()
Definition: InstallConditionExample.h:82
armarx::StatechartContext
This class contains a statechart and provides the interfaces to distributed components.
Definition: StatechartContext.h:85
Component.h
armarx::StatechartInstallConditionExample
Definition: InstallConditionExample.h:52
armarx::StatechartInstallConditionExample::defineParameters
void defineParameters()
Definition: InstallConditionExample.h:75
armarx::Literal
Definition: Term.h:208
armarx::DEFINEEVENT
DEFINEEVENT(EvInit) struct StateRun
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::StatechartInstallConditionExample::defineState
void defineState()
Definition: InstallConditionExample.h:56
armarx::InstallConditionExample::getDefaultName
virtual std::string getDefaultName() const
Retrieve default name of component.
Definition: InstallConditionExample.h:40
ImportExportComponent.h