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  virtual public StatechartContext
36  {
37  public:
38  // inherited from Component
39 
40  virtual std::string getDefaultName() const
41  {
42  return "GraspPositionReached";
43  }
44  virtual void onInitStatechart();
45  virtual void onConnectStatechart();
46 
47 
48 
49  };
50 
51  DEFINEEVENT(EvConditionReached)
52  struct stateInstallCondition;
53  struct StatechartInstallConditionExample : StateTemplate<StatechartInstallConditionExample>
54  {
55 
56  void defineState()
57  {
58  }
59 
61  {
62  // add substates
63 
64  setInitState(addState<stateInstallCondition>("ApproachGraspPosition"));
65  StatePtr final = addState<SuccessState>("Success");
66 
67  // add transition
68  ParameterMappingPtr mapping = ParameterMapping::createMapping()->mapFromOutput("hand_x", "position_x");
69  addTransition<EvConditionReached>(getInitState(),
70  final, mapping);
71  }
72 
74  {
75  addToInput("hand_x", VariantType::Float, true);
76  addToOutput("hand_current_x", VariantType::Float, true);
77  }
78 
79 
80  void onEnter()
81  {
82  }
83  };
84 
85 
86 
87  struct stateInstallCondition : StateTemplate<stateInstallCondition>
88  {
89  ConditionIdentifier condId;
90  void onEnter()
91  {
92  Literal checkAngles1("Armar4Observer.jointangles.LeftArm_Joint1", "larger", Literal::createParameterList(1.5f));
93  Literal checkAngles2("Armar4Observer.jointangles.LeftArm_Joint2", "smaller", Literal::createParameterList(1.f));
94  Literal checkAngles3("Armar4Observer.jointangles.Torso_Joint2", "larger", Literal::createParameterList(0.5f));
95  condId = installCondition<EvConditionReached>((!checkAngles1 || !checkAngles2) && checkAngles3);
96  }
97  void onExit()
98  {
99 
100  removeCondition(condId);
101  }
102 
103 
104  };
105 
106 
107 
108 
109 }
110 
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::StatechartInstallConditionExample::defineSubstates
void defineSubstates()
Definition: InstallConditionExample.h:60
armarx::stateInstallCondition::condId
ConditionIdentifier condId
Definition: InstallConditionExample.h:89
armarx::StateTemplate
Definition: State.h:39
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:539
armarx::stateInstallCondition::onExit
void onExit()
Definition: InstallConditionExample.h:97
armarx::stateInstallCondition
Definition: InstallConditionExample.h:87
armarx::Literal::createParameterList
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition: Term.cpp:129
armarx::InstallConditionExample
Definition: InstallConditionExample.h:34
Statechart.h
IceInternal::Handle< State >
armarx::stateInstallCondition::onEnter
void onEnter()
Definition: InstallConditionExample.h:90
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::StatechartInstallConditionExample::onEnter
void onEnter()
Definition: InstallConditionExample.h:80
armarx::StatechartContext
This class contains a statechart and provides the interfaces to distributed components.
Definition: StatechartContext.h:89
Component.h
armarx::StatechartInstallConditionExample
Definition: InstallConditionExample.h:53
armarx::StatechartInstallConditionExample::defineParameters
void defineParameters()
Definition: InstallConditionExample.h:73
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:28
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