Go to the documentation of this file.00001 #include <carl_demos/sequential_tasks.h>
00002
00003 using namespace std;
00004
00005 SequentialTasks::SequentialTasks() :
00006 armClient("carl_moveit_wrapper/common_actions/arm_action"),
00007 armHomeClient("jaco_arm/home_arm"),
00008 obtainObjectClient("carl_demos/obtain_object"),
00009 moveCarlClient("move_carl")
00010 {
00011 lookAtFrameClient = n.serviceClient<carl_dynamixel::LookAtFrame>("/asus_controller/look_at_frame");
00012
00013 ROS_INFO("Waiting for action servers...");
00014 armClient.waitForServer();
00015 obtainObjectClient.waitForServer();
00016 moveCarlClient.waitForServer();
00017 armHomeClient.waitForServer();
00018 ROS_INFO("Initialized.");
00019 }
00020
00021 void SequentialTasks::makeFruitBasket()
00022 {
00023 ROS_INFO("*************************************************");
00024 ROS_INFO("Apple");
00025 ROS_INFO("*************************************************");
00026 obtainObject(-1, "apple", "kitchen_table_surface_link");
00027
00028 ROS_INFO("*************************************************");
00029 ROS_INFO("Orange");
00030 ROS_INFO("*************************************************");
00031 obtainObject(-1, "orange", "kitchen_table_surface_link");
00032
00033 ROS_INFO("*************************************************");
00034 ROS_INFO("Banana");
00035 ROS_INFO("*************************************************");
00036 obtainObject(-1, "banana", "kitchen_table_surface_link");
00037 }
00038
00039 void SequentialTasks::packSchoolBag()
00040 {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 obtainObject(carl_navigation::MoveCarlGoal::KITCHEN_TABLE, "tape", "kitchen_table_surface_link");
00066
00067
00068 checkSurface(carl_navigation::MoveCarlGoal::COFFEE_TABLE, "coffee_table_surface_link");
00069
00070
00071 carl_navigation::MoveCarlGoal moveGoal;
00072 moveGoal.location = carl_navigation::MoveCarlGoal::INTERACTION_1;
00073 moveCarlClient.sendGoal(moveGoal);
00074 moveCarlClient.waitForResult(ros::Duration(60.0));
00075
00076 carl_dynamixel::LookAtFrame lookSrv;
00077 lookSrv.request.frame = "lazy_chair_2_surface_link";
00078 if (!lookAtFrameClient.call(lookSrv))
00079 {
00080 ROS_INFO("Could not call look at frame client!");
00081 return;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 ROS_INFO("Finished.");
00125 }
00126
00127 void SequentialTasks::checkSurface(int location, std::string surfaceLink)
00128 {
00129 ROS_INFO("Navigating to new location...");
00130
00131 carl_navigation::MoveCarlGoal moveGoal;
00132 moveGoal.location = location;
00133 moveCarlClient.sendGoal(moveGoal);
00134 moveCarlClient.waitForResult(ros::Duration(60.0));
00135 ROS_INFO("Navigation complete.");
00136
00137 ROS_INFO("Looking at surface...");
00138
00139 carl_dynamixel::LookAtFrame lookSrv;
00140 lookSrv.request.frame = surfaceLink;
00141 if (!lookAtFrameClient.call(lookSrv))
00142 {
00143 ROS_INFO("Could not call look at frame client!");
00144 return;
00145 }
00146 ROS_INFO("Looking at surface complete.");
00147
00148 ROS_INFO("Retracting arm...");
00149
00150 rail_manipulation_msgs::ArmGoal retractGoal;
00151 retractGoal.action = rail_manipulation_msgs::ArmGoal::RETRACT;
00152 armClient.sendGoal(retractGoal);
00153 armClient.waitForResult(ros::Duration(20.0));
00154 bool success = armClient.getResult()->success;
00155 if (!success)
00156 {
00157 ROS_INFO("Could not ready arm after storing object.");
00158 return;
00159 }
00160 ROS_INFO("Arm ready.");
00161
00162 ros::Duration(5.0).sleep();
00163 }
00164
00165 void SequentialTasks::obtainObject(int location, string object, string surfaceLink)
00166 {
00167 if (location != -1)
00168 {
00169 ROS_INFO("Navigating to new location...");
00170
00171 carl_navigation::MoveCarlGoal moveGoal;
00172 moveGoal.location = location;
00173 moveCarlClient.sendGoal(moveGoal);
00174 moveCarlClient.waitForResult(ros::Duration(60.0));
00175 ROS_INFO("Navigation complete.");
00176
00177 ROS_INFO("Looking at surface...");
00178
00179 carl_dynamixel::LookAtFrame lookSrv;
00180 lookSrv.request.frame = surfaceLink;
00181 if (!lookAtFrameClient.call(lookSrv)) {
00182 ROS_INFO("Could not call look at frame client!");
00183 return;
00184 }
00185 ROS_INFO("Looking at surface complete.");
00186 }
00187
00188 ROS_INFO("Obtaining object...");
00189
00190 carl_demos::ObtainObjectGoal obtainGoal;
00191 obtainGoal.lift = true;
00192 obtainGoal.verify = false;
00193 obtainGoal.object_name = object;
00194 obtainObjectClient.sendGoal(obtainGoal);
00195 obtainObjectClient.waitForResult(ros::Duration(60.0));
00196 carl_demos::ObtainObjectResultConstPtr obtainResult = obtainObjectClient.getResult();
00197 if (!obtainResult->success)
00198 {
00199 ROS_INFO("Failed to obtain requested object.");
00200 return;
00201 }
00202 ROS_INFO("Object obtained.");
00203
00204 ROS_INFO("Homing arm...");
00205
00206 wpi_jaco_msgs::HomeArmGoal homeGoal;
00207 homeGoal.retract = false;
00208 armHomeClient.sendGoal(homeGoal);
00209 armHomeClient.waitForResult(ros::Duration(20.0));
00210 bool success = armHomeClient.getResult()->success;
00211 if (!success)
00212 {
00213 ROS_INFO("Could not ready arm after storing object.");
00214 return;
00215 }
00216 ROS_INFO("Arm ready.");
00217 }
00218
00219 int main(int argc, char **argv)
00220 {
00221 ros::init(argc, argv, "sequential_tasks");
00222
00223 SequentialTasks st;
00224
00225 st.makeFruitBasket();
00226
00227 ROS_INFO("Action teminated.");
00228
00229 return EXIT_SUCCESS;
00230 }