Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <ros/ros.h>
00031
00032 #include <actionlib/client/simple_action_client.h>
00033 #include <turtlebot_arm_block_manipulation/BlockDetectionAction.h>
00034 #include <turtlebot_arm_block_manipulation/PickAndPlaceAction.h>
00035 #include <turtlebot_arm_block_manipulation/InteractiveBlockManipulationAction.h>
00036
00037 #include <string>
00038 #include <sstream>
00039
00040
00041 const std::string pick_and_place_topic = "/pick_and_place";
00042
00043 namespace turtlebot_arm_block_manipulation
00044 {
00045
00046 class BlockManipulationAction
00047 {
00048 private:
00049 ros::NodeHandle nh_;
00050
00051
00052 actionlib::SimpleActionClient<BlockDetectionAction> block_detection_action_;
00053 actionlib::SimpleActionClient<InteractiveBlockManipulationAction> interactive_manipulation_action_;
00054 actionlib::SimpleActionClient<PickAndPlaceAction> pick_and_place_action_;
00055
00056 BlockDetectionGoal block_detection_goal_;
00057 InteractiveBlockManipulationGoal interactive_manipulation_goal_;
00058 PickAndPlaceGoal pick_and_place_goal_;
00059
00060
00061 std::string arm_link;
00062 double gripper_open;
00063 double gripper_closed;
00064 double z_up;
00065 double z_down;
00066 double block_size;
00067 bool once;
00068
00069 public:
00070
00071 BlockManipulationAction() : nh_("~"),
00072 block_detection_action_("block_detection", true),
00073 interactive_manipulation_action_("interactive_manipulation", true),
00074 pick_and_place_action_("pick_and_place", true)
00075 {
00076
00077 nh_.param<std::string>("arm_link", arm_link, "/arm_link");
00078 nh_.param<double>("gripper_open", gripper_open, 0.042);
00079 nh_.param<double>("gripper_closed", gripper_closed, 0.024);
00080 nh_.param<double>("z_up", z_up, 0.12);
00081 nh_.param<double>("table_height", z_down, 0.01);
00082 nh_.param<double>("block_size", block_size, 0.03);
00083
00084 nh_.param<bool>("once", once, false);
00085
00086
00087 block_detection_goal_.frame = arm_link;
00088 block_detection_goal_.table_height = z_down;
00089 block_detection_goal_.block_size = block_size;
00090
00091 pick_and_place_goal_.frame = arm_link;
00092 pick_and_place_goal_.z_up = z_up;
00093 pick_and_place_goal_.gripper_open = gripper_open;
00094 pick_and_place_goal_.gripper_closed = gripper_closed;
00095 pick_and_place_goal_.topic = pick_and_place_topic;
00096
00097 interactive_manipulation_goal_.block_size = block_size;
00098 interactive_manipulation_goal_.frame = arm_link;
00099
00100 ROS_INFO("Finished initializing, waiting for servers...");
00101
00102 block_detection_action_.waitForServer();
00103 ROS_INFO("Found block detection server.");
00104
00105 interactive_manipulation_action_.waitForServer();
00106 ROS_INFO("Found interactive manipulation.");
00107
00108 pick_and_place_action_.waitForServer();
00109 ROS_INFO("Found pick and place server.");
00110
00111 ROS_INFO("Found servers.");
00112 }
00113
00114 void detectBlocks()
00115 {
00116 block_detection_action_.sendGoal(block_detection_goal_, boost::bind( &BlockManipulationAction::addBlocks, this, _1, _2));
00117 }
00118
00119 void addBlocks(const actionlib::SimpleClientGoalState& state, const BlockDetectionResultConstPtr& result)
00120 {
00121 ROS_INFO("Got block detection callback. Adding blocks.");
00122 geometry_msgs::Pose block;
00123
00124 if (state == actionlib::SimpleClientGoalState::SUCCEEDED)
00125 ROS_INFO("Succeeded!");
00126 else
00127 {
00128 ROS_INFO("Did not succeed! %s", state.toString().c_str());
00129 ros::shutdown();
00130 }
00131 interactive_manipulation_action_.sendGoal(interactive_manipulation_goal_, boost::bind( &BlockManipulationAction::pickAndPlace, this, _1, _2));
00132 }
00133
00134 void pickAndPlace(const actionlib::SimpleClientGoalState& state, const InteractiveBlockManipulationResultConstPtr& result)
00135 {
00136 ROS_INFO("Got interactive marker callback. Picking and placing.");
00137
00138 if (state == actionlib::SimpleClientGoalState::SUCCEEDED)
00139 ROS_INFO("Succeeded!");
00140 else
00141 {
00142 ROS_INFO("Did not succeed! %s", state.toString().c_str());
00143 ros::shutdown();
00144 }
00145 pick_and_place_action_.sendGoal(pick_and_place_goal_, boost::bind( &BlockManipulationAction::finish, this, _1, _2));
00146 }
00147
00148 void finish(const actionlib::SimpleClientGoalState& state, const PickAndPlaceResultConstPtr& result)
00149 {
00150 ROS_INFO("Got pick and place callback. Finished!");
00151 if (state == actionlib::SimpleClientGoalState::SUCCEEDED)
00152 ROS_INFO("Succeeded!");
00153 else
00154 ROS_INFO("Did not succeed! %s", state.toString().c_str());
00155
00156 if (once)
00157 ros::shutdown();
00158 else
00159 detectBlocks();
00160 }
00161 };
00162
00163 };
00164
00165 int main(int argc, char** argv)
00166 {
00167
00168 ros::init(argc, argv, "block_manipulation");
00169
00170 turtlebot_arm_block_manipulation::BlockManipulationAction manip;
00171
00172
00173 ros::AsyncSpinner spinner(2);
00174 spinner.start();
00175
00176 while (ros::ok())
00177 {
00178 manip.detectBlocks();
00179
00180
00181 std::cout << "Press Enter for restarting block detection" << std::endl;
00182 std::cin.ignore();
00183 }
00184
00185 spinner.stop();
00186 }