2 #include <std_msgs/String.h> 3 #include <std_srvs/Trigger.h> 4 #include <geometry_msgs/PointStamped.h> 5 #include <trajectory_msgs/JointTrajectory.h> 6 #include <std_msgs/Empty.h> 9 #include <control_msgs/GripperCommandAction.h> 13 #include <std_srvs/SetBool.h> 14 #include <moveit_msgs/PickupAction.h> 15 #include <moveit_msgs/PlaceAction.h> 16 #include <std_msgs/Float64MultiArray.h> 18 #define MAX_BOARD_PLACE 0.05 36 moveit_msgs::PickupGoal
BuildPickGoal(
const std::string &objectName);
38 moveit_msgs::PlaceGoal
buildPlaceGoal(
const std::string &objectName);
53 int main(
int argc,
char **argv) {
55 ros::init(argc, argv,
"pick_and_plce_node");
58 srand((
unsigned int) time(NULL));
61 std::string object_name,table_name;
67 pn.
param<std::string>(
"object_name", object_name,
"can");
68 pn.
param<std::string>(
"table_name", table_name,
"table");
85 if(group.
plan(startPosPlan)) {
87 pub_controller_command = n.
advertise<trajectory_msgs::JointTrajectory>(
"/pan_tilt_trajectory_controller/command", 2);
89 ROS_INFO(
"Waiting for the moveit action server to come up");
91 ROS_INFO(
"Waiting for update_collision service...");
93 uc_client_ptr = &uc_client;
97 ROS_INFO(
"Looking down...");
108 moveit_msgs::PlaceGoal placeGoal;
109 placeGoal.group_name =
"arm";
110 placeGoal.attached_object_name = objectName;
111 placeGoal.place_eef =
false;
112 placeGoal.support_surface_name =
"table";
113 placeGoal.planner_id =
"RRTConnectkConfigDefault";
114 placeGoal.allowed_planning_time = 15.0;
115 placeGoal.planning_options.replan =
true;
116 placeGoal.planning_options.replan_attempts = 5;
117 placeGoal.planning_options.replan_delay = 2.0;
118 placeGoal.planning_options.planning_scene_diff.is_diff =
true;
119 placeGoal.planning_options.planning_scene_diff.robot_state.is_diff =
true;
120 std::vector<moveit_msgs::PlaceLocation> locations;
121 moveit_msgs::PlaceLocation location;
122 location.pre_place_approach.direction.header.frame_id =
"/base_footprint";
123 location.pre_place_approach.direction.vector.z = -1.0;
124 location.pre_place_approach.min_distance = 0.1;
125 location.pre_place_approach.desired_distance = 0.2;
127 location.post_place_retreat.direction.header.frame_id =
"/gripper_link";
128 location.post_place_retreat.direction.vector.x = -1.0;
129 location.post_place_retreat.min_distance = 0.0;
130 location.post_place_retreat.desired_distance = 0.2;
132 location.place_pose.header.frame_id = placeGoal.support_surface_name;
137 if(fabs(point.
x + location.place_pose.pose.position.x) >=
MAX_BOARD_PLACE) {
140 }
while (!inTheBoard);
145 if(fabs(point.
y + location.place_pose.pose.position.y) >=
MAX_BOARD_PLACE) {
148 }
while (!inTheBoard);
150 location.place_pose.pose.position.z = 0.13;
151 location.place_pose.pose.orientation.w = 1.0;
153 locations.push_back(location);
154 placeGoal.place_locations = locations;
159 moveit_msgs::PickupGoal goal;
160 goal.target_name = objectName;
161 goal.group_name =
"arm";
162 goal.end_effector =
"eef";
163 goal.allowed_planning_time = 15.0;
164 goal.planning_options.replan_delay = 2.0;
165 goal.planning_options.planning_scene_diff.is_diff =
true;
166 goal.planning_options.planning_scene_diff.robot_state.is_diff =
true;
167 goal.planning_options.replan=
true;
168 goal.planning_options.replan_attempts=5;
169 goal.planner_id =
"RRTConnectkConfigDefault";
171 goal.minimize_object_distance =
true;
172 moveit_msgs::Grasp g;
173 g.max_contact_force = 1.0;
174 g.grasp_pose.header.frame_id = goal.target_name;
175 g.grasp_pose.pose.position.x = -0.02;
176 g.grasp_pose.pose.position.y = 0.0;
177 g.grasp_pose.pose.position.z = 0.0;
178 g.grasp_pose.pose.orientation.x = 0.0;
179 g.grasp_pose.pose.orientation.y = 0.0;
180 g.grasp_pose.pose.orientation.z = 0.0;
181 g.grasp_pose.pose.orientation.w = 1.0;
183 g.pre_grasp_approach.direction.header.frame_id =
"/base_footprint";
184 g.pre_grasp_approach.direction.vector.x = 1.0;
185 g.pre_grasp_approach.min_distance = 0.01;
186 g.pre_grasp_approach.desired_distance = 0.2;
188 g.post_grasp_retreat.direction.header.frame_id =
"/base_footprint";
189 g.post_grasp_retreat.direction.vector.z = 1.0;
190 g.post_grasp_retreat.min_distance = 0.1;
191 g.post_grasp_retreat.desired_distance = 0.2;
193 g.pre_grasp_posture.joint_names.push_back(
"left_finger_joint");
194 g.pre_grasp_posture.joint_names.push_back(
"right_finger_joint");
195 g.pre_grasp_posture.points.resize(1);
196 g.pre_grasp_posture.points[0].positions.resize(g.pre_grasp_posture.joint_names.size());
197 g.pre_grasp_posture.points[0].positions[0] = 0.14;
199 g.grasp_posture.joint_names = g.pre_grasp_posture.joint_names;
200 g.grasp_posture.points.resize(1);
201 g.grasp_posture.points[0].positions.resize(g.grasp_posture.joint_names.size());
202 g.grasp_posture.points[0].positions[0] = 0.01;
203 g.grasp_posture.points[0].effort.resize(g.grasp_posture.joint_names.size());
204 g.grasp_posture.points[0].effort[0] = 0.6;
205 goal.possible_grasps.push_back(g);
211 trajectory_msgs::JointTrajectory traj;
213 traj.joint_names.push_back(
"head_pan_joint");
214 traj.joint_names.push_back(
"head_tilt_joint");
215 traj.points.resize(1);
217 std::vector<double> q_goal(2);
220 traj.points[0].positions=q_goal;
221 traj.points[0].velocities.push_back(0);
222 traj.points[0].velocities.push_back(0);
223 pub_controller_command.
publish(traj);
233 std_srvs::SetBool srv;
234 srv.request.data=state;
235 if (uc_client_ptr->
call(srv))
237 ROS_INFO(
"update_colision response: %s", srv.response.message.c_str());
242 ROS_ERROR(
"Failed to call service /find_objects_node/update_colision");
251 std::string object_name;
253 pn.
param<std::string>(
"object_name", object_name,
"can");
256 std_srvs::SetBool disableColl;
257 disableColl.request.data =
false;
259 if(uc_client.call(disableColl)) {
260 ROS_INFO(
"update_colision response: OFF ");
266 moveit_msgs::PickupGoal pickGoal =
BuildPickGoal(object_name);
269 res.success = (
unsigned char)
false;
270 res.message = pickStatus.
getText();
271 point.
x = point.
y = 0;
282 res.success = (
unsigned char) (found);
283 res.message = placeStatus.
getText();
284 point.
x += placeGoal.place_locations[0].place_pose.pose.position.x;
285 point.
y += placeGoal.place_locations[0].place_pose.pose.position.y;
293 if(group_ptr->
plan(startPosPlan)) {
294 group_ptr->
execute(startPosPlan);
297 std_srvs::SetBool enableColl;
298 enableColl.request.data =
true;
299 if(uc_client.call(enableColl)) {
300 ROS_INFO(
"update_colision response: ON ");
308 int randomNum = rand()%(max-min + 1) + min;
309 return randomNum / 100.0;
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
moveit_msgs::PickupGoal BuildPickGoal(const std::string &objectName)
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
ros::Publisher pub_controller_command
void publish(const boost::shared_ptr< M > &message) const
actionlib::SimpleActionClient< moveit_msgs::PickupAction > PickClient
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
void setPoseReferenceFrame(const std::string &pose_reference_frame)
double randBetweenTwoNum(int max, int min)
void setPlannerId(const std::string &planner_id)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
int main(int argc, char **argv)
void setPlanningTime(double seconds)
bool pickAndPlaceCallBack(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)
ros::ServiceClient * uc_client_ptr
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
SimpleClientGoalState sendGoalAndWait(const Goal &goal, const ros::Duration &execute_timeout=ros::Duration(0, 0), const ros::Duration &preempt_timeout=ros::Duration(0, 0))
bool set_collision_update(bool state)
std::string getText() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
MoveItErrorCode execute(const Plan &plan)
MoveItErrorCode plan(Plan &plan)
std::string startPositionName
void setNumPlanningAttempts(unsigned int num_planning_attempts)
moveit::planning_interface::MoveGroupInterface * group_ptr
moveit_msgs::PlaceGoal buildPlaceGoal(const std::string &objectName)
ros::Publisher grp_pos_pub
actionlib::SimpleActionClient< moveit_msgs::PlaceAction > PlaceClient
bool setNamedTarget(const std::string &name)
void setStartStateToCurrentState()
ROSCPP_DECL void waitForShutdown()