27#include <VirtualRobot/MathTools.h>
28#include <VirtualRobot/Nodes/RobotNode.h>
29#include <VirtualRobot/RobotNodeSet.h>
46 const SimoxCSpaceBasePtr& cSpacePlatformBase,
47 const MotionPlanningData& mpd,
48 const Ice::Current&
c)
50 TrajectoryPtr jointTrajectory = calculateJointTrajectory(cSpaceBase, mpd,
c);
51 TrajectoryPtr platformTrajectory = calculatePlatformTrajectory(cSpacePlatformBase, mpd,
c);
52 return {platformTrajectory, jointTrajectory, mpd.rnsToUse, mpd.endeffector, mpd.grasp};
57 const SimoxCSpaceBasePtr& cSpacePlatformBase,
58 const MotionPlanningData& mpd,
59 const Ice::Current&
c)
61 VectorXf startCfg, goalCfg, startPos, goalPos;
63 Eigen::Vector3f rpyAgent;
65 SimoxCSpacePtr cSpacePlatform = SimoxCSpacePtr::dynamicCast(cSpacePlatformBase);
66 prepareJointCSpace(cSpace, mpd, &startCfg, &goalCfg, &scaledJointCSpace);
67 preparePlatformCSpace(
68 cSpacePlatform, mpd, &startPos, &goalPos, &scaledPlatformCSpace, &rpyAgent);
69 ARMARX_INFO <<
"Starting BiRRT for Joints and Platform";
72 startBiRRT(scaledJointCSpace, startCfg, goalCfg, 0.01);
74 startBiRRT(scaledPlatformCSpace, startPos, goalPos, 0.1);
76 Path jointTrajectoryPath = finishBiRRT(rspJointHandle, scaledJointCSpace,
"Joint");
78 Path posTrajectoryPath = finishBiRRT(rspPlatformHandle, scaledPlatformCSpace,
"Platform");
81 auto transformToGlobal = [&](armarx::VectorXf& pos2D)
83 Eigen::Vector2f globalPos =
84 Eigen::Rotation2Df(rpyAgent(2)) * Eigen::Vector2f(pos2D.at(0), pos2D.at(1));
85 pos2D.at(0) = globalPos[0] + cSpacePlatform->getAgent().agentPose->position->x;
86 pos2D.at(1) = globalPos[1] + cSpacePlatform->getAgent().agentPose->position->y;
89 for (
auto& e : posTrajectoryPath.nodes)
94 jointTrajectory = cSpace->pathToTrajectory(jointTrajectoryPath);
95 platformTrajectory = cSpacePlatform->pathToTrajectory(posTrajectoryPath);
96 return {platformTrajectory, jointTrajectory, mpd.rnsToUse, mpd.endeffector, mpd.grasp};
104 maxPostProcessingSteps = 50;
110 getProxy(mps,
"MotionPlanningServer");
111 getProxy(robotStateComponent,
"RobotStateComponent");
113 VirtualRobot::RobotIO::eStructure);
119 planningTasks.clear();
136 const armarx::MotionPlanningData& mpd,
137 const Ice::Current&
c)
140 return TrajectoryBasePtr::dynamicCast(
trajectory);
145 const armarx::MotionPlanningData& mpd,
146 const Ice::Current&
c)
149 return TrajectoryBasePtr::dynamicCast(
trajectory);
153 PlannedMotionProvider::calculateJointTrajectory(
const SimoxCSpaceBasePtr& cSpaceBase,
154 const MotionPlanningData& mpd,
155 const Ice::Current&
c)
161 prepareJointCSpace(cSpace, mpd, &startCfg, &goalCfg, &scaledJointCSpace);
163 startBiRRT(scaledJointCSpace, startCfg, goalCfg, 0.01);
164 Path jointTrajectoryPath = finishBiRRT(rspHandle, scaledJointCSpace,
"Joint");
165 return cSpace->pathToTrajectory(jointTrajectoryPath);
169 PlannedMotionProvider::calculatePlatformTrajectory(
const SimoxCSpaceBasePtr& cSpacePlatformBase,
170 const MotionPlanningData& mpd,
171 const Ice::Current&
c)
176 Eigen::Vector3f rpyAgent;
177 SimoxCSpacePtr cSpacePlatform = SimoxCSpacePtr::dynamicCast(cSpacePlatformBase);
178 preparePlatformCSpace(
179 cSpacePlatform, mpd, &startPos, &goalPos, &scaledPlatformCSpace, &rpyAgent);
181 RemoteHandle<MotionPlanningTaskControlInterfacePrx> rspHandle =
182 startBiRRT(scaledPlatformCSpace, startPos, goalPos, 0.1);
183 Path posTrajectoryPath = finishBiRRT(rspHandle, scaledPlatformCSpace,
"Platform");
185 auto transformToGlobal = [&](armarx::VectorXf& pos2D)
187 Eigen::Vector2f globalPos =
188 Eigen::Rotation2Df(rpyAgent(2)) * Eigen::Vector2f(pos2D.at(0), pos2D.at(1));
189 pos2D.at(0) = globalPos[0] + cSpacePlatform->getAgent().agentPose->position->x;
190 pos2D.at(1) = globalPos[1] + cSpacePlatform->getAgent().agentPose->position->y;
193 for (
auto& e : posTrajectoryPath.nodes)
195 transformToGlobal(e);
198 return cSpacePlatform->pathToTrajectory(posTrajectoryPath);
203 const armarx::VectorXf startPos,
204 const armarx::VectorXf goalPos,
206 bool doRandomShortcutPostProcessing)
209 MotionPlanningTaskBasePtr taskRRT =
216 RemoteHandle<MotionPlanningTaskControlInterfacePrx> handle;
217 if (!doRandomShortcutPostProcessing)
219 handle = mps->enqueueTask(taskRRT);
223 handle = mps->enqueueTask(
225 "RRTSmoothing" + IceUtil::generateUUID(),
228 maxPostProcessingSteps));
230 planningTasks.push_back(handle);
237 const std::string roboPart)
240 handle->waitForFinishedRunning();
242 << roboPart +
" trajectory planning took "
243 << IceUtil::Time::microSeconds(handle->getRunningTime()).toMilliSecondsDouble()
246 if (handle->getTaskStatus() == armarx::TaskStatus::ePlanningFailed)
248 throw RuntimeError(
" Motion Planning failed!");
252 << ((bool)(handle->getTaskStatus() == armarx::TaskStatus::ePlanningFailed)
255 ARMARX_INFO <<
"RRTConnectTask Planning status: " << handle->getTaskStatus();
257 auto posTrajectoryPath = handle->getPath();
259 scaledCSpace->unscalePath(posTrajectoryPath);
260 return posTrajectoryPath;
264 PlannedMotionProvider::preparePlatformCSpace(
SimoxCSpacePtr cSpacePlatform,
265 const MotionPlanningData& mpd,
266 VectorXf* storeStart,
269 Eigen::Vector3f* storeRpyAgent)
271 cSpacePlatform->setStationaryObjectMargin(
275 Eigen::Vector3f rpy, rpyAgent;
276 VirtualRobot::MathTools::eigen4f2rpy(PosePtr::dynamicCast(mpd.globalPoseStart)->toEigen(),
278 VirtualRobot::MathTools::eigen4f2rpy(
279 PosePtr::dynamicCast(cSpacePlatform->getAgent().agentPose)->toEigen(), rpyAgent);
280 armarx::VectorXf startPos{
281 mpd.globalPoseStart->position->x - cSpacePlatform->getAgent().agentPose->position->x,
282 mpd.globalPoseStart->position->y - cSpacePlatform->getAgent().agentPose->position->y,
285 Eigen::Vector2f localStartPos =
286 Eigen::Rotation2Df(-rpyAgent(2)) * Eigen::Vector2f(startPos.at(0), startPos.at(1));
287 startPos.at(0) = localStartPos(0);
288 startPos.at(1) = localStartPos(1);
289 VirtualRobot::MathTools::eigen4f2rpy(PosePtr::dynamicCast(mpd.globalPoseGoal)->toEigen(),
291 armarx::VectorXf goalPos{
292 mpd.globalPoseGoal->position->x - cSpacePlatform->getAgent().agentPose->position->x,
293 mpd.globalPoseGoal->position->y - cSpacePlatform->getAgent().agentPose->position->y,
295 Eigen::Vector2f localGoalPos =
296 Eigen::Rotation2Df(-rpyAgent(2)) * Eigen::Vector2f(goalPos.at(0), goalPos.at(1));
297 goalPos.at(0) = localGoalPos(0);
298 goalPos.at(1) = localGoalPos(1);
302 ScaledCSpacePtr scaledPlatformCSpace =
new ScaledCSpace(cSpacePlatform, {0.001, 0.001, 1});
303 scaledPlatformCSpace->scaleConfig(startPos);
304 scaledPlatformCSpace->scaleConfig(goalPos);
305 *storeStart = startPos;
306 *storeGoal = goalPos;
307 *storeScaledCSpace = scaledPlatformCSpace;
308 *storeRpyAgent = rpyAgent;
313 const MotionPlanningData& mpd,
314 VectorXf* storeStart,
321 Ice::FloatSeq cSpaceScaling;
322 for (VirtualRobot::RobotNodePtr node :
323 localRobot->getRobotNodeSet(mpd.rnsToUse)->getAllRobotNodes())
325 cSpaceScaling.push_back(node->isTranslationalJoint() ? 0.001f : 1.0f);
328 <<
VAROUT(mpd.globalPoseGoal->output());
330 armarx::VectorXf startCfg = cSpace->jointMapToVector(mpd.configStart);
331 armarx::VectorXf goalCfg = cSpace->jointMapToVector(mpd.configGoal);
334 ScaledCSpacePtr scaledJointCSpace =
new ScaledCSpace(cSpace, cSpaceScaling);
335 scaledJointCSpace->scaleConfig(startCfg);
336 scaledJointCSpace->scaleConfig(goalCfg);
337 *storeStart = startCfg;
338 *storeGoal = goalCfg;
339 *storeScaledCSpace = scaledJointCSpace;
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Brief description of class PlannedMotionProvider.
void onInitComponent() override
GraspingTrajectory planMotion(const SimoxCSpaceBasePtr &cSpaceBase, const SimoxCSpaceBasePtr &cSpacePlatformBase, const MotionPlanningData &mpd, const Ice::Current &c=Ice::emptyCurrent) override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
TrajectoryBasePtr planPlatformMotion(const SimoxCSpaceBasePtr &cSpacePlatformBase, const MotionPlanningData &mpd, const Ice::Current &c=Ice::emptyCurrent) override
void onConnectComponent() override
TrajectoryBasePtr planJointMotion(const SimoxCSpaceBasePtr &cSpaceBase, const MotionPlanningData &mpd, const Ice::Current &c=Ice::emptyCurrent) override
void onExitComponent() override
GraspingTrajectory planMotionParallel(const SimoxCSpaceBasePtr &cSpaceBase, const SimoxCSpaceBasePtr &cSpacePlatformBase, const MotionPlanningData &mpd, const Ice::Current &c) override
std::string getDefaultName() const override
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
The RemoteHandle class wrapps a ClientSideRemoteHandleControlBlock and can be used just as a Ice prox...
static VirtualRobot::RobotPtr createLocalCloneFromFile(RobotStateComponentInterfacePrx robotStatePrx, VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eFull)
This is a convenience function for createLocalClone, which automatically gets the filename from the R...
static float angleModPI(float value)
#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.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_VERBOSE
The logging level for verbose information.
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< ScaledCSpace > ScaledCSpacePtr
An ice handle to a ScaledCSpace.
IceInternal::Handle< Trajectory > TrajectoryPtr
rngshortcut::Task RandomShortcutPostprocessorTask
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< SimoxCSpace > SimoxCSpacePtr
An ice handle for a SimoxCSpace.