Skip to content

Commit 1f86f73

Browse files
committed
add two demos for cost computation aspects
1 parent ee2d768 commit 1f86f73

File tree

5 files changed

+165
-2
lines changed

5 files changed

+165
-2
lines changed

demo/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ target_link_libraries(modular ${catkin_LIBRARIES})
2727
add_executable(pick_place_demo src/pick_place_demo.cpp src/pick_place_task.cpp)
2828
target_link_libraries(pick_place_demo ${catkin_LIBRARIES})
2929

30+
add_executable(alternative_path_costs src/alternative_path_costs.cpp)
31+
target_link_libraries(alternative_path_costs ${catkin_LIBRARIES})
32+
33+
add_executable(ik_clearance_cost src/ik_clearance_cost.cpp)
34+
target_link_libraries(ik_clearance_cost ${catkin_LIBRARIES})
35+
3036
install(TARGETS cartesian modular pick_place_demo
3137
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
3238
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}

demo/config/mtc.rviz

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Panels:
1717
- Class: moveit_task_constructor/Motion Planning Tasks
1818
Global Settings:
1919
Task View Settings:
20+
Show Computation Times: true
2021
Task Expansion: All Expanded
2122
Name: Motion Planning Tasks
2223
Tasks View:
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <ros/ros.h>
2+
3+
#include <moveit/planning_scene/planning_scene.h>
4+
5+
#include <moveit/task_constructor/task.h>
6+
#include <moveit/task_constructor/container.h>
7+
8+
#include <moveit/task_constructor/solvers/pipeline_planner.h>
9+
10+
#include <moveit/task_constructor/stages/connect.h>
11+
#include <moveit/task_constructor/stages/fixed_state.h>
12+
13+
#include <moveit/task_constructor/cost_terms.h>
14+
15+
using namespace moveit::task_constructor;
16+
17+
/* FixedState - Connect - FixedState */
18+
int main(int argc, char** argv) {
19+
ros::init(argc, argv, "mtc_tutorial");
20+
21+
Task t;
22+
t.stages()->setName("alternative path costs");
23+
t.loadRobotModel();
24+
25+
assert(t.getRobotModel()->getName() == "panda");
26+
27+
auto scene{ std::make_shared<planning_scene::PlanningScene>(t.getRobotModel()) };
28+
auto& robot_state{ scene->getCurrentStateNonConst() };
29+
robot_state.setToDefaultValues();
30+
robot_state.setToDefaultValues(robot_state.getJointModelGroup("panda_arm"), "extended");
31+
32+
auto initial{ std::make_unique<stages::FixedState>("start") };
33+
initial->setState(scene);
34+
t.add(std::move(initial));
35+
36+
auto pipeline{ std::make_shared<solvers::PipelinePlanner>() };
37+
38+
auto alternatives{ std::make_unique<Alternatives>("connect") };
39+
{
40+
auto connect{ std::make_unique<stages::Connect>(
41+
"path length", stages::Connect::GroupPlannerVector{ { "panda_arm", pipeline } }) };
42+
connect->setCostTerm(std::make_unique<cost::PathLength>()); // This is the default for Connect, specified for
43+
// demonstration purposes
44+
alternatives->add(std::move(connect));
45+
}
46+
{
47+
auto connect{ std::make_unique<stages::Connect>(
48+
"trajectory duration", stages::Connect::GroupPlannerVector{ { "panda_arm", pipeline } }) };
49+
connect->setCostTerm(std::make_unique<cost::TrajectoryDuration>());
50+
alternatives->add(std::move(connect));
51+
}
52+
{
53+
auto connect{ std::make_unique<stages::Connect>(
54+
"eef motion", stages::Connect::GroupPlannerVector{ { "panda_arm", pipeline } }) };
55+
connect->setCostTerm(std::make_unique<cost::LinkMotion>("panda_hand"));
56+
alternatives->add(std::move(connect));
57+
}
58+
{
59+
auto connect{ std::make_unique<stages::Connect>(
60+
"elbow motion", stages::Connect::GroupPlannerVector{ { "panda_arm", pipeline } }) };
61+
connect->setCostTerm(std::make_unique<cost::LinkMotion>("panda_link4"));
62+
alternatives->add(std::move(connect));
63+
}
64+
65+
t.add(std::move(alternatives));
66+
67+
auto goal_scene{ scene->diff() };
68+
goal_scene->getCurrentStateNonConst().setToDefaultValues(robot_state.getJointModelGroup("panda_arm"), "ready");
69+
auto goal = std::make_unique<stages::FixedState>("goal");
70+
goal->setState(goal_scene);
71+
t.add(std::move(goal));
72+
73+
try {
74+
t.plan(0);
75+
} catch (const InitStageException& e) {
76+
std::cout << e << std::endl;
77+
}
78+
79+
ros::spin();
80+
81+
return 0;
82+
}

demo/src/ik_clearance_cost.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <ros/ros.h>
2+
3+
#include <moveit/planning_scene/planning_scene.h>
4+
5+
#include <moveit/task_constructor/task.h>
6+
7+
#include <moveit/task_constructor/stages/fixed_state.h>
8+
#include <moveit/task_constructor/stages/compute_ik.h>
9+
10+
#include <moveit/task_constructor/cost_terms.h>
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+
19+
ros::AsyncSpinner spinner{ 1 };
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+
robot_state.setToDefaultValues(robot_state.getJointModelGroup("panda_arm"), "extended");
35+
36+
moveit_msgs::CollisionObject co;
37+
co.id = "obstacle";
38+
co.primitives.emplace_back();
39+
co.primitives[0].type = shape_msgs::SolidPrimitive::SPHERE;
40+
co.primitives[0].dimensions.resize(1);
41+
co.primitives[0].dimensions[0] = 0.1;
42+
co.header.frame_id = "world";
43+
co.primitive_poses.emplace_back();
44+
co.primitive_poses[0].orientation.w = 1.0;
45+
co.primitive_poses[0].position.z = 0.85;
46+
scene->processCollisionObjectMsg(co);
47+
48+
auto initial = std::make_unique<stages::FixedState>();
49+
initial->setState(scene);
50+
51+
auto ik = std::make_unique<stages::ComputeIK>();
52+
ik->insert(std::move(initial));
53+
ik->setGroup("panda_arm");
54+
ik->setTargetPose(Eigen::Translation3d(.3, 0, .35) * Eigen::AngleAxisd(M_PI, Eigen::Vector3d::UnitY()));
55+
ik->setTimeout(1.0);
56+
ik->setMaxIKSolutions(100);
57+
58+
auto cl_cost{ std::make_unique<cost::Clearance>() };
59+
cl_cost->cumulative = nh.param("cumulative", false); // sum up pairwise distances?
60+
cl_cost->with_world = nh.param("with_world", true); // consider distance to world objects?
61+
ik->setCostTerm(std::move(cl_cost));
62+
63+
t.add(std::move(ik));
64+
65+
try {
66+
t.plan(0);
67+
} catch (const InitStageException& e) {
68+
std::cout << e << std::endl;
69+
}
70+
71+
ros::waitForShutdown();
72+
73+
return 0;
74+
}

demo/src/pick_place_demo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ moveit_msgs::CollisionObject createObject() {
9999
}
100100

101101
int main(int argc, char** argv) {
102-
ROS_INFO_NAMED(LOGNAME, "Init moveit_task_constructor_demo");
103-
ros::init(argc, argv, "moveit_task_constructor_demo");
102+
ROS_INFO_NAMED(LOGNAME, "Init node");
103+
ros::init(argc, argv, "mtc_tutorial");
104104
ros::NodeHandle nh;
105105
ros::AsyncSpinner spinner(1);
106106
spinner.start();

0 commit comments

Comments
 (0)