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
28
30
31namespace armarx
32{
33 void
38
39 void
44
45 void
51
52 // this function creates an instance of the robot-statechart,
53 // so there is always one running-instance active that can
54 // be controlled by the GUI
55 void
57 {
58
59
60 task = new RunningTask<RobotControl>(this, &RobotControl::createStaticInstance);
61 task->start();
62 }
63
64 void
65 RobotControl::hardReset(const Ice::Current&)
66 {
67 removeInstance(robotFunctionalState->getLocalUniqueId());
69 }
70
76
77 void
78 RobotControl::createStaticInstance()
79 {
80 getObjectScheduler()->waitForObjectState(eManagedIceObjectStarted, 5000);
81 stateId = createRemoteStateInstance("RobotControl", NULL, "RobotStatechart", "");
82 std::map<int, StateBasePtr> stateList = getChildStatesByName(stateId, "Functional");
83 ARMARX_INFO << "Functional State Id:" << stateList.begin()->first << flush;
84 assert(stateList.size() > 0);
85 int robotFunctionalStateId = stateList.begin()->first;
86 robotFunctionalState = stateList.begin()->second;
87 callRemoteState(stateId, StringVariantContainerBaseMap());
88
89 const std::string proxyName = getProperty<std::string>("XMLStatechartProfile").getValue() +
90 getProperty<std::string>("proxyName").getValue();
91 const std::string stateName = getProperty<std::string>("stateName").getValue();
92 ARMARX_IMPORTANT << VAROUT(proxyName) << VAROUT(stateName);
93
94 if (!proxyName.empty() && !stateName.empty())
95 {
96 auto statebase = robotFunctionalState->findSubstateByName("DynamicRemoteState");
97 ARMARX_CHECK_EXPRESSION(statebase);
98 DynamicRemoteStatePtr state = DynamicRemoteStatePtr::dynamicCast(statebase);
99
100 if (!state)
101 {
102 ARMARX_ERROR << "dynamic state pointer null";
103 return;
104 }
105
106 state->getObjectScheduler()->waitForObjectState(eManagedIceObjectStarted, 5000);
108 evt->eventReceiverName = "toAll";
109 evt->properties["proxyName"] = new SingleVariant(proxyName);
110 evt->properties["stateName"] = new SingleVariant(stateName);
111 issueEvent(robotFunctionalStateId, evt);
112 }
113 }
114
115 void
119
120 void
122 {
123 //add substates
124 StateBasePtr stateFunctional = setInitState(addState<StateRobotControl>("Functional"));
125 StateBasePtr stateStopped = addState<State>("Stopped");
126 StateBasePtr stateFailure = addState<State>("Failure");
127
128 // add transitions
129 addTransition<Failure>(stateFunctional, stateFailure);
130 addTransition<EvStopRobot>(stateFunctional, stateStopped);
131 addTransition<EvStartRobot>(stateStopped, stateFunctional);
132 addTransition<EvStartRobot>(stateFailure, stateFunctional);
133 }
134
135 void
137 {
138 // add substates
139 StateBasePtr stateIdling = addState<State>("Idling");
140 StateBasePtr stateRobotPreInitialized =
141 addState<RobotPreInitialized>("RobotPreInitialized");
142 StateBasePtr stateRobotInitialized = addState<State>("RobotInitialized");
143 StateBasePtr stateScenarioRunning = addDynamicRemoteState("DynamicScenarioState");
144 StateBasePtr stateFatalError = addState<FailureState>("FatalError");
145
146 setInitState(stateRobotInitialized);
147 // add transitions
148 addTransition<EvInit>(stateIdling, stateRobotPreInitialized);
149 addTransition<EvInitialized>(stateRobotPreInitialized, stateRobotInitialized);
150 addTransition<EvLoadScenario>(stateRobotInitialized,
151 stateScenarioRunning,
152 PM::createMapping()->mapFromEvent("*", "*"));
153 addTransition<EvInit>(stateScenarioRunning, stateRobotPreInitialized);
154 addTransition<Success>(stateScenarioRunning, stateRobotInitialized);
155
156 // failure transitions
157 addTransition<EvLoadingFailed>(stateScenarioRunning, stateFatalError);
158 addTransition<EvConnectionLost>(stateScenarioRunning, stateFatalError);
159 addTransition<EvInitFailed>(stateRobotPreInitialized, stateFatalError);
161 }
162
163 void
165 {
166 // install global running conditions for the robot (e.g. temperature < xx°C)
167 // KinematicUnitObserverInterfacePrx prx = getContext()->getProxy<KinematicUnitObserverInterfacePrx>("KinematicUnitObserver");
168 // installCondition<Failure>(Expression::create()
169 // ->add(channels::KinematicUnitObserver::jointTemperatures.getDatafield("KinematicUnitObserver", "NECK_JOINT0"), checks::KinematicUnitObserver::larger->getCheckStr(), 50.f));
170 }
171
175
176 void
178 {
179 // issue init on remote components and install condition "RobotInitialized"
180 }
181
182} // namespace armarx
#define VAROUT(x)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
ArmarXObjectSchedulerPtr getObjectScheduler() const
static ParameterMappingPtr createMapping()
Creates a new instance of a ParameterMapping. Since the constructors are private, this method must be...
StateBasePtr robotFunctionalState
Refernce to the currently active Functionsl state.
void onConnectRemoteStateOfferer() override
Virtual function, in which the user can fetch some proxies.
void onExitRemoteStateOfferer() override
Virtual function, in which the user can implement some clean up.
void onInitRemoteStateOfferer() override
Pure virtual function, in which the states must be added, that should be remote-accessable.
PropertyDefinitionsPtr createPropertyDefinitions() override
void hardReset(const Ice::Current &=Ice::emptyCurrent) override
EventPtr createEvent()
Utility function to create a new Event.
Definition StateUtil.h:63
StateBasePtr addState(StateBasePtr pNewState)
Definition State.cpp:140
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
virtual RemoteStatePtr addDynamicRemoteState(std::string instanceName)
Function to add a new dynamic remote substate to this state.
Definition State.cpp:213
TransitionIceBase & addTransitionFromAllStates(StateIceBasePtr destinationState, ParameterMappingIceBasePtr mappingToNextStatesInput=nullptr, ParameterMappingIceBasePtr mappingToParentStatesLocal=nullptr, ParameterMappingIceBasePtr mappingToParentStatesOutput=nullptr)
Function to add a new transition from all substates to destinationState.
Definition State.h:577
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const LogSender::manipulator flush
Definition LogSender.h:251
IceInternal::Handle< DynamicRemoteState > DynamicRemoteStatePtr
IceInternal::Handle< Event > EventPtr
Typedef of EventPtr as IceInternal::Handle<Event> for convenience.
Definition Event.h:40
IceInternal::Handle< StateBase > StateBasePtr
Definition StateBase.h:49
int createRemoteStateInstance(const std::string &stateName, const RemoteStateIceBasePrx &remoteStatePrx, const std::string &parentStateItentifierStr, const std::string &instanceName, const Ice::Current &context=Ice::emptyCurrent) override
void removeInstance(int stateId, const Ice::Current &=Ice::emptyCurrent) override
void issueEvent(int receivingStateId, const EventBasePtr &evt, const Ice::Current &=Ice::emptyCurrent) override
std::map< int, StateBasePtr > getChildStatesByName(int parentId, std::string stateName)
void callRemoteState(int stateId, const StringVariantContainerBaseMap &properties, const Ice::Current &context=Ice::emptyCurrent) override
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void defineSubstates() override
Virtual function, in which substates, transition and mappings can be added.
void defineState() override
Virtual function, in which this state can be configured.
void defineSubstates() override
Virtual function, in which substates, transition and mappings can be added.