PlanMotion.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 RobotSkillTemplates::MotionPlanningGroup
17  * @author Raphael Grimm ( ufdrv at student dot kit dot edu )
18  * @date 2016
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "PlanMotion.h"
24 
25 #include <algorithm>
26 
31 
32 using namespace armarx;
33 using namespace MotionPlanningGroup;
34 
35 // DO NOT EDIT NEXT LINE
36 PlanMotion::SubClassRegistry PlanMotion::Registry(PlanMotion::GetName(), &PlanMotion::CreateInstance);
37 
38 
39 
41 {
42  // put your user code for the enter-point here
43  // execution time should be short (<100ms)
44  resetTask();
45 }
46 
48 {
49  // resetTask();
50  // //called prior to any locking of a mutex -> no deadlock
51  // ARMARX_ON_SCOPE_EXIT
52  // {
53  // resetTask();
54  // };
55  // // put your user code for the execution-phase here
56  // // runs in seperate thread, thus can do complex operations
57  // // should check constantly whether isRunningTaskStopped() returns true
58 
59  // //setup cspace
60  // SimoxCSpacePtr cspaceSimox;
61  // if(in.getPlanPlatformMovement())
62  // {
63  // SimoxCSpaceWith2DPosePtr cspaceSimox2d = new SimoxCSpaceWith2DPose{getWorkingMemory()->getCommonStorage()};
64  // if(!in.isCSpacePlatformMovementBoundsMinSet())
65  // {
66  // ARMARX_ERROR_S << "platform movement should be planned, but the min movement bounds were not set.";
67  // emitFailure();
68  // return;
69  // }
70  // if(!in.isCSpacePlatformMovementBoundsMaxSet())
71  // {
72  // ARMARX_ERROR_S << "platform movement should be planned, but the max movement bounds were not set.";
73  // emitFailure();
74  // return;
75  // }
76  // cspaceSimox =cspaceSimox2d;
77  // Vector3fRange movBounds;
78  // movBounds.min.x = in.getCSpacePlatformMovementBoundsMin()->x;
79  // movBounds.min.y = in.getCSpacePlatformMovementBoundsMin()->y;
80  // movBounds.min.z = in.getCSpacePlatformMovementBoundsMin()->z;
81  // movBounds.max.x = in.getCSpacePlatformMovementBoundsMax()->x;
82  // movBounds.max.y = in.getCSpacePlatformMovementBoundsMax()->y;
83  // movBounds.max.z = in.getCSpacePlatformMovementBoundsMax()->z;
84  // cspaceSimox2d->setPoseBounds(movBounds);
85  // }
86  // else
87  // {
88  // cspaceSimox = new SimoxCSpace{getWorkingMemory()->getCommonStorage()};
89  // }
90  // //setup agent
91 
92 
93 
94  // /*
95 
96 
97  // ::std::string agentProjectName;
98  // ::std::string agentRelativeFilePath;
99  // ::armarx::PoseBasePtr agentPose;
100 
101 
102 
103 
104  // */
105  // AgentPlanningInformation agent;
106  // VirtualRobot::RobotPtr stateComponentRobot;
107  // memoryx::AgentInstancePtr agentInstance;
108 
109  // //do this before deriving init joint values from the robots
110  // if(in.isInitialJointValuesSet())
111  // {
112  // agent.initialJointValues = in.getInitialJointValues();
113  // }
114  // //get file path and optionally derive joint values
115  // if(in.isAgentProjectNameSet()&&in.isAgentRelativeFilePathSet())
116  // {
117  // agent.agentProjectName = in.getAgentProjectName();
118  // agent.agentRelativeFilePath = in.getAgentRelativeFilePath();
119  // }
120  // else if(in.isAgentInstanceSet())
121  // {
122  // //load from agent instance
123  // agentInstance = in.getAgentInstance();
124  // agent.agentRelativeFilePath = agentInstance->getAgentFilePath();
125  // //joints
126  // if(in.getInitalJointValuesFromAgent())
127  // {
128  // auto nodeValues = agentInstance->getSharedRobot()->getConfig();
129  // //override from initialJointValues, since probably is smaller
130  // std::swap(agent.initialJointValues, nodeValues);
131  // for(const auto& node: nodeValues)
132  // {
133  // agent.initialJointValues[node.first] = node.second;
134  // }
135  // }
136  // //pose
137  // agent.agentPose = agentInstance->getPose();
138  // }
139  // else
140  // {
141  // //load agent from robot state component
142  // stateComponentRobot = getRobot();
143  // agent.agentRelativeFilePath =stateComponentRobot->getFilename();
144  // //joints
145  // if(in.getInitalJointValuesFromAgent())
146  // {
147  // auto nodes = stateComponentRobot->getRobotNodes();
148  // for(const VirtualRobot::RobotNodePtr& node :nodes)
149  // {
150  // //does not update existing values!
151  // agent.initialJointValues.emplace(node->getName(), node->getJointValue());
152  // }
153  // }
154  // //pose
155  // agent.agentPose = new Pose{stateComponentRobot->getGlobalPose()};
156  // }
157  // ARMARX_VERBOSE_S << "Loading agent from project '" << agent.agentProjectName
158  // <<"' and path '" <<agent.agentRelativeFilePath<<"'";
159 
160  // //set agent pose if it is set by the user
161  // if(in.isInitialAgentPoseSet())
162  // {
163  // agent.agentPose = in.getInitialAgentPose();
164  // }
165  // else if(!agent.agentPose)
166  // {
167  // if(in.getPlanPlatformMovement())
168  // {
169  // //the pose is not used -> set some pose
170  // agent.agentPose = new Pose{};
171  // }
172  // else
173  // {
174  // //the agent pose is used, but not set
175  // ARMARX_ERROR_S << "the initial agent pose was not set. "
176  // <<"(either define it explicit by setting InitialAgentPose, "
177  // <<"implicit by loading a robot from an AgentInstance "
178  // <<"or RobotComponent or plan the platforms position by setting PlanPlatformMovement to true";
179  // emitFailure();
180  // return;
181  // }
182  // }
183 
184  // //joints to plan
185  // if(in.isCSpaceJointsExcludedFromPlanningSet())
186  // {
187  // agent.jointsExcludedFromPlanning = in.getCSpaceJointsExcludedFromPlanning();
188  // }
189  // if(in.isCSpaceKinemaicChainsSet())
190  // {
191  // agent.kinemaicChainNames = in.getCSpaceKinemaicChains();
192  // }
193  // if(in.isCSpacePlanningJointsSet())
194  // {
195  // agent.additionalJointsForPlanning = in.getCSpacePlanningJoints();
196  // }
197 
198  // if(agent.kinemaicChainNames.empty() && agent.additionalJointsForPlanning.empty())
199  // {
200  // ARMARX_ERROR_S << "no joints set for planning! (define CSpacePlanningJoints and/or CSpaceKinemaicChains)";
201  // emitFailure();
202  // return;
203  // }
204 
205  // //collision
206  // agent.collisionSetNames = in.getCollisionSetNames();
207 
208  // cspaceSimox->setAgent(agent);
209  // //objects
210  // cspaceSimox->addObjectsFromWorkingMemory(getWorkingMemory());
211 
212  // VectorXf start;
213  // if(in.isConfigStartSet())
214  // {
215  // start = in.getConfigStart();
216  // if(start.size() != static_cast<std::size_t>(cspaceSimox->getDimensionality()))
217  // {
218  // ARMARX_ERROR_S << "the start config has " << start.size() << "demensions, but the cspace has " << cspaceSimox->getDimensionality() << " dimensions.";
219  // emitFailure();
220  // return;
221  // }
222  // }
223  // else
224  // {
225  // if(agentInstance)
226  // {
227 
228  // }
229  // else if(stateComponentRobot)
230  // {
231 
232  // }
233  // else
234  // {
235  // ARMARX_ERROR_S << "no start configuration was set (either define ConfigStart explicit, or implicit by using an agent loaded from AgentInstance or RobotStateComponent";
236  // emitFailure();
237  // return;
238  // }
239  // }
240 
241  // VectorXf goal;
242  // RRTConnectTaskPtr rrt;
243 
244  // //create the task
245  // std::lock_guard< std::mutex> lock{taskMutex};
246  // task = getMotionPlanningServer()->enqueueTask(new RandomShortcutPostprocessorTask{rrt});
247  // //wait for the task to finish (we can't call wait, since we may want to abort)
248  // while(!isRunningTaskStopped() && task->finishedRunning())
249  // {
250  // //time does not need to respect the time server (this is just polling for a result)
251  // std::this_thread::sleep_for(std::chrono::milliseconds(20));
252  // }
253  // if(task->finishedRunning())
254  // {
255  // //the task found a path!
256  // PathWithCost p = task->getPathWithCost();
257  // TrajectoryPtr trajectory = new Trajectory{p.nodes, Ice::DoubleSeq{}, cspaceSimox->getAgentJointNames()};
258  // setOutput("Trajectory", trajectory);
259  // emitSuccess();
260  // return;
261  // }
262  // //no path was found!
263  // emitFailure();
264 }
265 
267 {
268  // put your user code for the breaking point here
269  // execution time should be short (<100ms)
270  resetTask();
271 }
272 
274 {
275  // put your user code for the exit point here
276  // execution time should be short (<100ms)
277  resetTask();
278 }
279 
281 {
282  // std::lock_guard< std::mutex> lock{taskMutex};
283  // if(task)
284  // {
285  // task->abortTask();
286  // task = nullptr;
287  // }
288 }
289 
290 
291 // DO NOT EDIT NEXT FUNCTION
293 {
294  return XMLStateFactoryBasePtr(new PlanMotion(stateData));
295 }
296 
armarx::MotionPlanningGroup::PlanMotion::resetTask
void resetTask()
Definition: PlanMotion.cpp:280
armarx::MotionPlanningGroup::PlanMotion::PlanMotion
PlanMotion(const XMLStateConstructorParams &stateData)
Definition: PlanMotion.h:36
armarx::MotionPlanningGroup::PlanMotion::onExit
void onExit() override
Definition: PlanMotion.cpp:273
OnScopeExit.h
ScaledCSpace.h
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
PlanMotion.h
armarx::MotionPlanningGroup::PlanMotion::run
void run() override
Definition: PlanMotion.cpp:47
armarx::MotionPlanningGroup::PlanMotion::Registry
static SubClassRegistry Registry
Definition: PlanMotion.h:51
IceInternal::Handle
Definition: forward_declarations.h:8
Task.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::MotionPlanningGroup::PlanMotion::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: PlanMotion.cpp:292
SimoxCSpace.h
armarx::MotionPlanningGroup::PlanMotion::onBreak
void onBreak() override
Definition: PlanMotion.cpp:266
armarx::MotionPlanningGroup::PlanMotion::onEnter
void onEnter() override
Definition: PlanMotion.cpp:40
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28