Created
January 4, 2022 09:40
-
-
Save YannickRiou/f84a52efa3acbdb061ce82b38a76c97e to your computer and use it in GitHub Desktop.
panda pick task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void motionPlanning::createPickTaskCustom(std::unique_ptr<moveit::task_constructor::Task>&pickTask, const std::string planGroup,const std::string object,const std::string supportId, std::vector<geometry_msgs::PoseStamped> graspPoses) | |
{ | |
pickTask->setRobotModel(kinematic_model_); | |
// Property and variable definitions | |
std::string pregrasp; | |
std::string postgrasp; | |
pickTask->setProperty("object",object); | |
pickTask->setProperty("group",planGroup); | |
pickTask->setProperty("eef","hand"); | |
eef_ = "hand"; | |
ikFrame_ = "panda_link8"; | |
pregrasp = "open"; | |
postgrasp = "close"; | |
// Increase precision to avoid collision | |
pipelinePlanner_->setProperty("longest_valid_segment_fraction",0.00001); | |
pipelinePlanner_->setPlannerId(PLANNER); | |
//Start state | |
Stage* current_state = nullptr; | |
auto initial = std::make_unique<stages::CurrentState>("current state"); | |
// Save state for future stages | |
current_state = initial.get(); | |
pickTask->add(std::move(initial)); | |
// ---------------------- open Hand ---------------------- // | |
{ | |
auto stage = std::make_unique<stages::MoveTo>("open hand", gripper_planner_); | |
stage->setGroup(eef_); | |
stage->setGoal(pregrasp); | |
stage->setTimeout(5.0); | |
current_state = stage.get(); | |
pickTask->add(std::move(stage)); | |
} | |
{ | |
// connect to pick | |
stages::Connect::GroupPlannerVector planners = {{planGroup, pipelinePlanner_},{eef_, gripper_planner_}}; | |
auto connect = std::make_unique<stages::Connect>("connect", planners); | |
connect->setCostTerm(std::make_unique<cost::TrajectoryDuration>()); | |
connect->properties().configureInitFrom(Stage::PARENT); | |
pickTask->add(std::move(connect)); | |
} | |
{ | |
auto grasp = std::make_unique<SerialContainer>("pick object"); | |
pickTask->properties().exposeTo(grasp->properties(), { "eef", "group"}); | |
grasp->properties().configureInitFrom(Stage::PARENT, { "eef", "group"}); | |
grasp->setProperty("eef",eef_); | |
{ | |
auto stage = std::make_unique<stages::MoveRelative>("approach object", cartesianPlanner_); | |
stage->properties().configureInitFrom(Stage::PARENT, { "group" }); | |
stage->setMinMaxDistance(0.01, 0.20); | |
stage->setIKFrame(ikFrame_); | |
geometry_msgs::Vector3Stamped vec; | |
vec.header.frame_id = "panda_link0"; | |
vec.vector.z = -1.0; | |
stage->setDirection(vec); | |
grasp->insert(std::move(stage)); | |
} | |
{ | |
auto stage = std::make_unique<stages::GenerateCustomPose>("Generate Custom Poses"); | |
stage->setCustomPoses(graspPoses); | |
stage->properties().configureInitFrom(Stage::PARENT); | |
stage->setMonitoredStage(current_state); | |
auto wrapper = std::make_unique<stages::ComputeIK>("grasp pose IK", std::move(stage) ); | |
wrapper->properties().configureInitFrom(Stage::PARENT, { "group" }); | |
wrapper->setMaxIKSolutions(10); | |
wrapper->setIKFrame(panda_hand_transform_,ikFrame_); | |
wrapper->properties().configureInitFrom(Stage::INTERFACE, { "target_pose" }); | |
wrapper->properties().configureInitFrom(Stage::PARENT, {"eef"}); | |
grasp->insert(std::move(wrapper)); | |
} | |
// ---------------------- Allow Collision (hand object) ---------------------- // | |
{ | |
auto stage = std::make_unique<stages::ModifyPlanningScene>("allow collision (hand,object)"); | |
stage->allowCollisions(object, pickTask->getRobotModel()->getJointModelGroup(eef_)->getLinkModelNamesWithCollisionGeometry(),true); | |
grasp->insert(std::move(stage)); | |
} | |
// ---------------------- Close Hand ---------------------- // | |
{ | |
auto stage = std::make_unique<stages::MoveTo>("close hand", gripper_planner_); | |
stage->setGroup(eef_); | |
stage->setGoal(postgrasp); | |
stage->setTimeout(5.0); | |
grasp->insert(std::move(stage)); | |
} | |
// ---------------------- Attach Object ---------------------- // | |
{ | |
auto stage = std::make_unique<stages::ModifyPlanningScene>("attach object"); | |
stage->attachObject(object, ikFrame_); | |
current_state = stage.get(); | |
grasp->insert(std::move(stage)); | |
} | |
// ---------------------- Allow Collision (object support) ---------------------- // | |
{ | |
auto stage = std::make_unique<stages::ModifyPlanningScene>("allow collision (object,support)"); | |
stage->allowCollisions({ object }, supportId, true); | |
grasp->insert(std::move(stage)); | |
} | |
// ---------------------- Lift object ---------------------- // | |
{ | |
auto stage = std::make_unique<stages::MoveRelative>("lift object", cartesianPlanner_); | |
stage->properties().configureInitFrom(Stage::PARENT, { "group" }); | |
stage->setMinMaxDistance(0.01, 0.05); | |
stage->setIKFrame(ikFrame_); | |
// Set upward direction | |
geometry_msgs::Vector3Stamped vec; | |
vec.header.frame_id = "panda_link0"; | |
vec.vector.z = 1.0; | |
stage->setDirection(vec); | |
grasp->insert(std::move(stage)); | |
} | |
// ---------------------- Forbid Collision (object support) ---------------------- // | |
{ | |
auto stage = std::make_unique<stages::ModifyPlanningScene>("forbid collision (object,surface)"); | |
stage->allowCollisions({ object }, supportId, false); | |
grasp->insert(std::move(stage)); | |
} | |
pickTask->add(std::move(grasp)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment