|
48 | 48 | namespace task_constructor { |
49 | 49 | namespace stages { |
50 | 50 |
|
51 | | - DeepGraspPose::DeepGraspPose(ros::NodeHandle& nh, const std::string& name) |
| 51 | + DeepGraspPose::DeepGraspPose(const std::string& name) |
52 | 52 | : GeneratePose(name), |
53 | | - client_(nh, "sample_grasps", true) { |
| 53 | + client_("sample_grasps", true) { |
54 | 54 | auto& p = properties(); |
55 | 55 | p.declare<std::string>("eef", "name of end-effector"); |
56 | 56 | p.declare<std::string>("object"); |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 |
|
122 | | - geometry_msgs::PoseStamped target_pose_msg; |
| 122 | + // sampled grasps |
| 123 | + std::vector<geometry_msgs::PoseStamped> grasp_candidates; |
| 124 | + // the cost of each grasp |
| 125 | + std::vector<double> scores; |
| 126 | + |
| 127 | + // TODO(bostoncleek): add timeout to connection ? |
| 128 | + ROS_INFO("Waiting for grasp detection action server to start..."); |
| 129 | + client_.waitForServer(); |
| 130 | + |
| 131 | + // test server connection |
| 132 | + if(!client_.isServerConnected()) |
| 133 | + { |
| 134 | + ROS_ERROR("Grasp detection action server not connected!"); |
| 135 | + } |
123 | 136 |
|
124 | 137 | moveit_task_constructor_msgs::GenerateDeepGraspPoseGoal goal; |
125 | 138 | goal.action_name = "generate_grasps"; |
126 | 139 | client_.sendGoal(goal); |
127 | 140 |
|
128 | | - ROS_WARN("!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); |
129 | | - std::cout << client_.isServerConnected() << std::endl; |
130 | | - |
131 | | - client_.waitForResult(ros::Duration(5.0)); |
| 141 | + // get result within timeout |
| 142 | + // TODO(bostoncleek): select timeout |
| 143 | + client_.waitForResult(); |
132 | 144 | if (client_.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) |
133 | 145 | { |
134 | | - printf("Done!"); |
135 | | - |
136 | | - moveit_task_constructor_msgs::GenerateDeepGraspPoseResultConstPtr grasp_result_ptr; |
137 | | - grasp_result_ptr = client_.getResult(); |
138 | | - |
139 | | - target_pose_msg = grasp_result_ptr->grasp_candidate; |
140 | | - |
| 146 | + grasp_candidates = client_.getResult()->grasp_candidates; |
| 147 | + scores = client_.getResult()->scores; |
141 | 148 | } |
142 | | - printf("Current State: %s\n", client_.getState().toString().c_str()); |
143 | 149 |
|
144 | | - ROS_WARN("!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); |
145 | | - std::cout << target_pose_msg << std::endl; |
146 | | - |
147 | | - // target_pose_msg.header.frame_id = "panda_link0"; |
148 | | - // target_pose_msg.pose.position.x = 0.5; |
149 | | - // target_pose_msg.pose.position.y = -0.25; |
150 | | - // target_pose_msg.pose.position.z = 0.20; |
| 150 | + ROS_INFO("Grasp Generator State: %s", client_.getState().toString().c_str()); |
| 151 | + ROS_WARN("Number of grasp candidates: %lu", grasp_candidates.size()); |
151 | 152 |
|
152 | 153 |
|
153 | 154 | planning_scene::PlanningScenePtr scene = upstream_solutions_.pop()->end()->scene()->diff(); |
|
160 | 161 | robot_state::RobotState& robot_state = scene->getCurrentStateNonConst(); |
161 | 162 | robot_state.setToDefaultValues(jmg, props.get<std::string>("pregrasp")); |
162 | 163 |
|
163 | | - |
164 | | - InterfaceState state(scene); |
165 | | - state.properties().set("target_pose", target_pose_msg); |
166 | | - props.exposeTo(state.properties(), { "pregrasp", "grasp" }); |
167 | | - |
168 | | - SubTrajectory trajectory; |
169 | | - trajectory.setCost(0.0); |
170 | | - trajectory.setComment(std::to_string(0.0)); |
171 | | - |
172 | | - // add frame at target pose |
173 | | - rviz_marker_tools::appendFrame(trajectory.markers(), target_pose_msg, 0.1, "grasp frame"); |
174 | | - |
175 | | - spawn(std::move(state), std::move(trajectory)); |
| 164 | + for(unsigned int i = 0; i < grasp_candidates.size(); i++) |
| 165 | + { |
| 166 | + // Do not use grasps with score < 0 |
| 167 | + // Grasp is selected based on cost not score |
| 168 | + // Invert score to represent grasp with lowest cost |
| 169 | + if (scores.at(i) > 0.0) |
| 170 | + { |
| 171 | + InterfaceState state(scene); |
| 172 | + state.properties().set("target_pose", grasp_candidates.at(i)); |
| 173 | + props.exposeTo(state.properties(), { "pregrasp", "grasp" }); |
| 174 | + |
| 175 | + SubTrajectory trajectory; |
| 176 | + trajectory.setCost(static_cast<double>(1.0 / scores.at(i))); |
| 177 | + trajectory.setComment(std::to_string(i)); |
| 178 | + |
| 179 | + // add frame at target pose |
| 180 | + rviz_marker_tools::appendFrame(trajectory.markers(), grasp_candidates.at(i), 0.1, "grasp frame"); |
| 181 | + |
| 182 | + spawn(std::move(state), std::move(trajectory)); |
| 183 | + } |
| 184 | + } |
176 | 185 | } |
177 | 186 | } // namespace stages |
178 | 187 | } // namespace task_constructor |
|
0 commit comments