Skip to content

Commit 75d0800

Browse files
author
kut
committed
cleanup, use trajectory adjustment function
1 parent b30006e commit 75d0800

File tree

1 file changed

+3
-64
lines changed

1 file changed

+3
-64
lines changed

src/moveit_custom_api.cpp

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
/// TODO:
2-
/// [x] Wrap moveToNamedPose in multiple trials as well
3-
/// [x] Try to merge plan and execute functions (and hence number of trial loops)
4-
/// [x] Incorporate gripper functionality
5-
/// [x] Change up and down motion from target pose movement to cartesian pose move to ensure smooth trajectory
6-
/// [] Try with moveit pick and place interface instead - Requires implementation of prismatic joints in URDF and controllers for the same
72
/// [] Test the test piece collission object add/remove functionality more, including trajectories - Test object currently left nehind when the place operation is done. Fix this.
83

9-
104
#include "ur_manipulation/moveit_custom_api.hpp"
115

126
#include <std_msgs/Header.h>
@@ -75,39 +69,10 @@ void MoveitCustomApi::executeCartesianTrajForWaypoints(std::vector<geometry_msgs
7569
{
7670
fraction = move_group->computeCartesianPath(waypoints, eef, jump_thresh, trajectory);
7771
}
78-
79-
ROS_INFO_STREAM("Visualizing Cartesian Path plan with waypoints (" << fraction*100 << "% acheived)");
80-
81-
82-
std::vector<ros::Duration> times_from_start;
83-
int iter=0;
84-
for(auto x: trajectory.joint_trajectory.points)
85-
{
86-
// ROS_INFO_STREAM(iter++ << " point_time_from_start: " << x.time_from_start);
87-
times_from_start.push_back(x.time_from_start);
88-
}
89-
90-
// Adjust starting from point 2 i.e. index 1
91-
for(int i=1; i< times_from_start.size();i++)
92-
{
93-
94-
if(times_from_start[i]==ros::Duration(0) && i<times_from_start.size())
95-
{
96-
ros::Duration prev = times_from_start[i];
97-
times_from_start[i] = ros::Duration((times_from_start[i-1].toSec()+times_from_start[i+1].toSec())/2.0);
98-
ROS_WARN_STREAM("Recomputing point " << i << " from " << prev << " to: " << times_from_start[i-1] << " + " << times_from_start[i+1] << " = " <<times_from_start[i]);
99-
}
100-
}
101-
102-
for(int i=0; i< times_from_start.size(); i++)
103-
{
104-
trajectory.joint_trajectory.points[i].time_from_start = times_from_start[i];
105-
// ROS_INFO_STREAM("Recomputed time point " << i << " : " << trajectory.joint_trajectory.points[i].time_from_start );
106-
}
107-
108-
72+
adjustTrajectoryToFixTimeSequencing(trajectory);
10973

11074
// Visualize the plan in RViz
75+
ROS_INFO_STREAM("Visualizing Cartesian Path plan with waypoints (" << fraction*100 << "% acheived)");
11176
visual_tools->deleteAllMarkers();
11277
visual_tools->publishText(text_pose, "Cartesian path", rvt::WHITE, rvt::XLARGE);
11378
for (std::size_t i = 0; i < waypoints.size(); ++i)
@@ -131,12 +96,8 @@ void MoveitCustomApi::adjustTrajectoryToFixTimeSequencing(moveit_msgs::RobotTraj
13196
for(int i=0; i < times_from_start.size() ; i++)
13297
{
13398
times_from_start[i]= trajectory.joint_trajectory.points[i].time_from_start;
134-
// ROS_INFO_STREAM("P: " << i<< " time_from_start: " << times_from_start[i]);
13599
}
136100

137-
// ROS_INFO_STREAM("Size of time_from_start :" << times_from_start.size() << " trajectory points: " << trajectory.joint_trajectory.points.size());
138-
139-
140101
// Adjust starting from point 2 i.e. index 1
141102
bool adjusted_flag=false;
142103
for(int i=1; i< times_from_start.size()-1;i++)
@@ -162,7 +123,6 @@ void MoveitCustomApi::adjustTrajectoryToFixTimeSequencing(moveit_msgs::RobotTraj
162123
for(int i=0; i< times_from_start.size(); i++)
163124
{
164125
trajectory.joint_trajectory.points[i].time_from_start = times_from_start[i];
165-
// ROS_INFO_STREAM("Recomputed time point " << i << " : " << trajectory.joint_trajectory.points[i].time_from_start );
166126
}
167127
}
168128

@@ -182,19 +142,10 @@ moveit::planning_interface::MoveGroupInterface::Plan MoveitCustomApi::getCartesi
182142
{
183143
fraction = move_group->computeCartesianPath(waypoints, eef_step, jump_threshold, trajectory);
184144
}
185-
186-
ROS_INFO_STREAM("Visualizing Cartesian Path plan to " << display_label <<" (" << fraction*100 << "% acheived)");
187-
188-
// trajectory.joint_trajectory.points.resize(5);
189-
// trajectory.joint_trajectory.points[0].time_from_start = ros::Duration(0);
190-
// trajectory.joint_trajectory.points[1].time_from_start = ros::Duration(0.1234);
191-
// trajectory.joint_trajectory.points[2].time_from_start = ros::Duration(0);
192-
// trajectory.joint_trajectory.points[3].time_from_start = ros::Duration(0.3456);
193-
// trajectory.joint_trajectory.points[4].time_from_start = ros::Duration(0);
194-
195145
adjustTrajectoryToFixTimeSequencing(trajectory);
196146

197147
// Visualize the plan in RViz
148+
ROS_INFO_STREAM("Visualizing Cartesian Path plan to " << display_label <<" (" << fraction*100 << "% acheived)");
198149
visual_tools->deleteAllMarkers();
199150
visual_tools->publishText(text_pose, "Cartesian path", rvt::WHITE, rvt::XLARGE);
200151
for (std::size_t i = 0; i < waypoints.size(); ++i)
@@ -214,13 +165,10 @@ void MoveitCustomApi::sleepSafeFor(double duration)
214165
{
215166
ros::spinOnce();
216167
}
217-
218168
}
219169

220-
221170
bool MoveitCustomApi::moveGroupExecutePlan(moveit::planning_interface::MoveGroupInterface::Plan my_plan)
222171
{
223-
224172
if(user_prompts)
225173
{
226174
std::string message = "Planning completed, press Next to execute";
@@ -476,7 +424,6 @@ void MoveitCustomApi::initialiseMoveit(ros::NodeHandle nh)
476424
visual_tools->publishText(text_pose, boost::to_upper_copy<std::string>(robot_name_), rvt::WHITE, rvt::XLARGE);
477425
visual_tools->trigger();
478426
planning_scene_diff_publisher = nh.advertise<moveit_msgs::PlanningScene>("planning_scene", 1);
479-
480427
}
481428

482429
void MoveitCustomApi::moveToNamedTarget(std::string target)
@@ -549,8 +496,6 @@ void MoveitCustomApi::pickAtPoseFromHeight(geometry_msgs::Pose target_pose, doub
549496
}
550497
else
551498
{
552-
// moveGroupExecutePlan(getPlanToPoseTarget(target_pose, max_trials, "Pre Pick Pose"));
553-
// moveGroupExecutePlan(getCartesianPathPlanToPose(target_pose, "Pre Pick Pose"));
554499
executeCartesianTrajtoPose(target_pose,"Pre Pick Pose");
555500
}
556501
ROS_INFO("---------------------------");
@@ -559,15 +504,13 @@ void MoveitCustomApi::pickAtPoseFromHeight(geometry_msgs::Pose target_pose, doub
559504
// Go down to reach and grasp the object
560505
target_pose.position.z-=height;
561506
executeCartesianTrajtoPose(target_pose,"Pick Pose");
562-
// moveGroupExecutePlan(getCartesianPathPlanToPose(target_pose, "Pick Pose"));
563507
if (do_gripper) gripperClose(nh);
564508
sleepSafeFor(robot_settle_time_);
565509
// addOrRemoveTestPieceCollissionObjectWRTRobot(COMMAND_ADD);
566510
ROS_INFO("---------------------------");
567511

568512
// Go back up
569513
target_pose.position.z+=height;
570-
// moveGroupExecutePlan(getCartesianPathPlanToPose(target_pose, "Post Pick Pose"));
571514
executeCartesianTrajtoPose(target_pose,"Post Pick Pose");
572515
ROS_INFO("---------------------------");
573516
}
@@ -581,14 +524,11 @@ void MoveitCustomApi::placeAtPoseFromHeight(geometry_msgs::Pose target_pose, dou
581524
{
582525
// Go to a set height above given pose
583526
target_pose.position.z+=height;
584-
// moveGroupExecutePlan(getPlanToPoseTarget(target_pose, max_trials, "Pre Place Pose"));
585-
// moveGroupExecutePlan(getCartesianPathPlanToPose(target_pose, "Pre Place Pose"));
586527
executeCartesianTrajtoPose(target_pose,"Pre Place Pose");
587528
ROS_INFO("---------------------------");
588529
sleepSafeFor(robot_settle_time_);
589530
// Go down and place the object
590531
target_pose.position.z-=height;
591-
// moveGroupExecutePlan(getCartesianPathPlanToPose(target_pose, "Place Pose"));
592532
executeCartesianTrajtoPose(target_pose,"Place Pose");
593533
ROS_INFO("---------------------------");
594534
if (do_gripper) gripperOpen(nh);
@@ -597,7 +537,6 @@ void MoveitCustomApi::placeAtPoseFromHeight(geometry_msgs::Pose target_pose, dou
597537

598538
// Go back up
599539
target_pose.position.z+=height;
600-
// moveGroupExecutePlan(getCartesianPathPlanToPose(target_pose, "Post Place Pose"));
601540
executeCartesianTrajtoPose(target_pose,"Post Place Pose");
602541
ROS_INFO("---------------------------");
603542
}

0 commit comments

Comments
 (0)