RobotControl.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "RobotControl.h"
24 
26 
30 
31 namespace armarx
32 {
34  {
35  addState<Statechart_Robot>("RobotControl");
36  }
37 
39  {
41  }
42 
44  {
45  removeInstance(stateId);
46  robotFunctionalState = NULL;
47  }
48 
49  // this function creates an instance of the robot-statechart,
50  // so there is always one running-instance active that can
51  // be controlled by the GUI
53  {
54 
55 
56  task = new RunningTask< RobotControl >(this, &RobotControl::createStaticInstance);
57  task->start();
58  }
59 
60 
61  void RobotControl::hardReset(const Ice::Current&)
62  {
63  removeInstance(robotFunctionalState->getLocalUniqueId());
65  }
66 
68  {
70  }
71 
72  void RobotControl::createStaticInstance()
73  {
74  getObjectScheduler()->waitForObjectState(eManagedIceObjectStarted, 5000);
75  stateId = createRemoteStateInstance("RobotControl", NULL, "RobotStatechart", "");
76  std::map<int, StateBasePtr> stateList = getChildStatesByName(stateId, "Functional");
77  ARMARX_INFO << "Functional State Id:" << stateList.begin()->first << flush;
78  assert(stateList.size() > 0);
79  int robotFunctionalStateId = stateList.begin()->first;
80  robotFunctionalState = stateList.begin()->second;
81  callRemoteState(stateId, StringVariantContainerBaseMap());
82 
83  const std::string proxyName = getProperty<std::string>("XMLStatechartProfile").getValue() + getProperty<std::string>("proxyName").getValue();
84  const std::string stateName = getProperty<std::string>("stateName").getValue();
85  ARMARX_IMPORTANT << VAROUT(proxyName) << VAROUT(stateName);
86 
87  if (!proxyName.empty() && !stateName.empty())
88  {
89  auto statebase = robotFunctionalState->findSubstateByName("DynamicRemoteState");
90  ARMARX_CHECK_EXPRESSION(statebase);
91  DynamicRemoteStatePtr state = DynamicRemoteStatePtr::dynamicCast(statebase);
92 
93  if (!state)
94  {
95  ARMARX_ERROR << "dynamic state pointer null";
96  return;
97  }
98 
99  state->getObjectScheduler()->waitForObjectState(eManagedIceObjectStarted, 5000);
100  EventPtr evt = createEvent<EvLoadScenario>();
101  evt->eventReceiverName = "toAll";
102  evt->properties["proxyName"] = new SingleVariant(proxyName);
103  evt->properties["stateName"] = new SingleVariant(stateName);
104  issueEvent(robotFunctionalStateId, evt);
105  }
106  }
107 
108 
109 
111  {
112  }
114  {
115  //add substates
116  StateBasePtr stateFunctional = setInitState(addState<StateRobotControl>("Functional"));
117  StateBasePtr stateStopped = addState<State>("Stopped");
118  StateBasePtr stateFailure = addState<State>("Failure");
119 
120  // add transitions
121  addTransition<Failure>(stateFunctional, stateFailure);
122  addTransition<EvStopRobot>(stateFunctional, stateStopped);
123  addTransition<EvStartRobot>(stateStopped, stateFunctional);
124  addTransition<EvStartRobot>(stateFailure, stateFunctional);
125  }
126 
127 
128 
129 
131  {
132  // add substates
133  StateBasePtr stateIdling = addState<State>("Idling");
134  StateBasePtr stateRobotPreInitialized = addState<RobotPreInitialized>("RobotPreInitialized");
135  StateBasePtr stateRobotInitialized = addState<State>("RobotInitialized");
136  StateBasePtr stateScenarioRunning = addDynamicRemoteState("DynamicScenarioState");
137  StateBasePtr stateFatalError = addState<FailureState>("FatalError");
138 
139  setInitState(stateRobotInitialized);
140  // add transitions
141  addTransition<EvInit>(stateIdling, stateRobotPreInitialized);
142  addTransition<EvInitialized>(stateRobotPreInitialized, stateRobotInitialized);
143  addTransition<EvLoadScenario>(stateRobotInitialized, stateScenarioRunning,
144  PM::createMapping()->mapFromEvent("*", "*"));
145  addTransition<EvInit>(stateScenarioRunning, stateRobotPreInitialized);
146  addTransition<Success>(stateScenarioRunning, stateRobotInitialized);
147 
148  // failure transitions
149  addTransition<EvLoadingFailed>(stateScenarioRunning, stateFatalError);
150  addTransition<EvConnectionLost>(stateScenarioRunning, stateFatalError);
151  addTransition<EvInitFailed>(stateRobotPreInitialized, stateFatalError);
152  addTransitionFromAllStates<Failure>(stateFatalError);
153  }
154 
156  {
157  // install global running conditions for the robot (e.g. temperature < xx°C)
158  // KinematicUnitObserverInterfacePrx prx = getContext()->getProxy<KinematicUnitObserverInterfacePrx>("KinematicUnitObserver");
159  // installCondition<Failure>(Expression::create()
160  // ->add(channels::KinematicUnitObserver::jointTemperatures.getDatafield("KinematicUnitObserver", "NECK_JOINT0"), checks::KinematicUnitObserver::larger->getCheckStr(), 50.f));
161  }
162 
163 
164 
165 
167  {
168  }
169 
171  {
172  // issue init on remote components and install condition "RobotInitialized"
173  }
174 
175 }
armarx::RemoteStateOffererBase::createRemoteStateInstance
int createRemoteStateInstance(const std::string &stateName, const RemoteStateIceBasePrx &remoteStatePrx, const std::string &parentStateItentifierStr, const std::string &instanceName, const Ice::Current &context=Ice::emptyCurrent) override
Definition: RemoteStateOfferer.cpp:92
armarx::EventPtr
IceInternal::Handle< Event > EventPtr
Typedef of EventPtr as IceInternal::Handle<Event> for convenience.
Definition: Event.h:42
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::RobotControl::hardReset
void hardReset(const Ice::Current &=Ice::emptyCurrent) override
Definition: RobotControl.cpp:61
armarx::RobotPreInitialized::RobotPreInitialized
RobotPreInitialized()
Definition: RobotControl.cpp:166
armarx::RobotControl::onInitRemoteStateOfferer
void onInitRemoteStateOfferer() override
Pure virtual function, in which the states must be added, that should be remote-accessable.
Definition: RobotControl.cpp:33
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::RobotControl::robotFunctionalState
StateBasePtr robotFunctionalState
Refernce to the currently active Functionsl state.
Definition: RobotControl.h:67
armarx::RemoteStateOffererBase::removeInstance
void removeInstance(int stateId, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteStateOfferer.cpp:401
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::StateRobotControl::onEnter
void onEnter() override
Definition: RobotControl.cpp:155
armarx::RemoteStateOffererBase::issueEvent
void issueEvent(int receivingStateId, const EventBasePtr &evt, const Ice::Current &=Ice::emptyCurrent) override
Definition: RemoteStateOfferer.cpp:418
armarx::RemoteStateOffererBase::getChildStatesByName
std::map< int, StateBasePtr > getChildStatesByName(int parentId, std::string stateName)
Definition: RemoteStateOfferer.cpp:535
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::RobotControl::startRobotStatechart
void startRobotStatechart()
Definition: RobotControl.cpp:52
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::RobotControl::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RobotControl.cpp:67
armarx::RobotControl::onConnectRemoteStateOfferer
void onConnectRemoteStateOfferer() override
Virtual function, in which the user can fetch some proxies.
Definition: RobotControl.cpp:38
RobotControl.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::Statechart_Robot::defineSubstates
void defineSubstates() override
Definition: RobotControl.cpp:113
armarx::RobotControlContextProperties
Definition: RobotControl.h:35
armarx::RobotPreInitialized::onEnter
void onEnter() override
Definition: RobotControl.cpp:170
ExpressionException.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::StateRobotControl::defineSubstates
void defineSubstates() override
Definition: RobotControl.cpp:130
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::RemoteStateOffererBase::callRemoteState
void callRemoteState(int stateId, const StringVariantContainerBaseMap &properties, const Ice::Current &context=Ice::emptyCurrent) override
Definition: RemoteStateOfferer.cpp:170
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
DynamicRemoteState.h
armarx::Statechart_Robot::defineState
void defineState() override
Definition: RobotControl.cpp:110
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ManagedIceObject::getObjectScheduler
ArmarXObjectSchedulerPtr getObjectScheduler() const
Definition: ManagedIceObject.cpp:731
KinematicUnitObserver.h
armarx::RobotControl::onExitRemoteStateOfferer
void onExitRemoteStateOfferer() override
Virtual function, in which the user can implement some clean up.
Definition: RobotControl.cpp:43
ChannelRef.h