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