ik_clearance_cost.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 
4 
6 
9 
11 
12 using namespace moveit::task_constructor;
13 
14 /* ComputeIK(FixedState) */
15 int main(int argc, char** argv) {
16  ros::init(argc, argv, "mtc_tutorial");
17  ros::NodeHandle nh{ "~" };
18 
20  spinner.start();
21 
22  Task t;
23  t.stages()->setName("clearance IK");
24 
25  // announce new task (in case previous run was restarted)
26  ros::Duration(0.5).sleep();
27 
28  t.loadRobotModel();
29  assert(t.getRobotModel()->getName() == "panda");
30 
31  auto scene = std::make_shared<planning_scene::PlanningScene>(t.getRobotModel());
32  auto& robot_state = scene->getCurrentStateNonConst();
33  robot_state.setToDefaultValues();
34  [[maybe_unused]] bool found =
35  robot_state.setToDefaultValues(robot_state.getJointModelGroup("panda_arm"), "extended");
36  assert(found);
37 
38  moveit_msgs::CollisionObject co;
39  co.id = "obstacle";
40  co.primitives.emplace_back();
41  co.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
42  co.primitives[0].dimensions.resize(1);
43  co.primitives[0].dimensions[0] = 0.1;
44  co.header.frame_id = t.getRobotModel()->getModelFrame();
45  co.primitive_poses.emplace_back();
46  co.primitive_poses[0].orientation.w = 1.0;
47  co.primitive_poses[0].position.z = 0.85;
48  scene->processCollisionObjectMsg(co);
49 
50  auto initial = std::make_unique<stages::FixedState>();
51  initial->setState(scene);
52  initial->setIgnoreCollisions(true);
53 
54  auto ik = std::make_unique<stages::ComputeIK>();
55  ik->insert(std::move(initial));
56  ik->setGroup("panda_arm");
57  ik->setTargetPose(Eigen::Translation3d(.3, 0, .35) * Eigen::AngleAxisd(M_PI, Eigen::Vector3d::UnitY()));
58  ik->setTimeout(1.0);
59  ik->setMaxIKSolutions(100);
60 
61  auto cl_cost{ std::make_unique<cost::Clearance>() };
62  cl_cost->cumulative = nh.param("cumulative", false); // sum up pairwise distances?
63  cl_cost->with_world = nh.param("with_world", true); // consider distance to world objects?
64  ik->setCostTerm(std::move(cl_cost));
65 
66  t.add(std::move(ik));
67 
68  try {
69  t.plan(0);
70  } catch (const InitStageException& e) {
71  std::cout << e << '\n';
72  }
73 
75 
76  return 0;
77 }
main
int main(int argc, char **argv)
Definition: ik_clearance_cost.cpp:15
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
moveit::task_constructor::InitStageException
ros::AsyncSpinner
constrained.co
co
Definition: constrained.py:23
moveit::task_constructor::Task
spinner
void spinner()
moveit::task_constructor
task.h
compute_ik.h
planning_scene.h
cartesian.move
move
Definition: cartesian.py:34
ros::waitForShutdown
ROSCPP_DECL void waitForShutdown()
M_PI
#define M_PI
fixed_state.h
ros::Duration::sleep
bool sleep() const
cost_terms.h
t
dictionary t
ros::Duration
ros::NodeHandle


demo
Author(s): Robert Haschke , Simon Goldstein , Henning Kayser
autogenerated on Sat May 3 2025 02:40:30