sequential_tasks.cpp
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   //notebook
00043   obtainObject(carl_navigation::MoveCarlGoal::COFFEE_TABLE, "notebook", "coffee_table_surface_link");
00044 
00045   //look for glue
00046   checkSurface(carl_navigation::MoveCarlGoal::KITCHEN_TABLE, "kitchen_table_surface_link");
00047 
00048   //get feedback
00049   carl_navigation::MoveCarlGoal moveGoal;
00050   moveGoal.location = carl_navigation::MoveCarlGoal::INTERACTION_2;
00051   moveCarlClient.sendGoal(moveGoal);
00052   moveCarlClient.waitForResult(ros::Duration(60.0));
00053   //look at chair
00054   carl_dynamixel::LookAtFrame lookSrv;
00055   lookSrv.request.frame = "lazy_chair_2_surface_link";
00056   if (!lookAtFrameClient.call(lookSrv))
00057   {
00058     ROS_INFO("Could not call look at frame client!");
00059     return;
00060   }
00061   */
00062 
00063 
00064   //tape
00065   obtainObject(carl_navigation::MoveCarlGoal::KITCHEN_TABLE, "tape", "kitchen_table_surface_link");
00066 
00067   //look for pencil
00068   checkSurface(carl_navigation::MoveCarlGoal::COFFEE_TABLE, "coffee_table_surface_link");
00069 
00070   //get feedback
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   //look at chair
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   //pens
00087   obtainObject(carl_navigation::MoveCarlGoal::COFFEE_TABLE, "pens", "coffee_table_surface_link");
00088 
00089   //ruler
00090   obtainObject(carl_navigation::MoveCarlGoal::KITCHEN_TABLE, "ruler", "kitchen_table_surface_link");
00091 
00092   //scissors
00093   obtainObject(carl_navigation::MoveCarlGoal::KITCHEN_TABLE, "scissors", "kitchen_table_surface_link");
00094 
00095   //look for apple
00096   checkSurface(carl_navigation::MoveCarlGoal::FRIDGE, "kitchen_counter_right_surface_link");
00097 
00098   //get feedback
00099   carl_navigation::MoveCarlGoal moveGoal;
00100   moveGoal.location = carl_navigation::MoveCarlGoal::INTERACTION_2;
00101   moveCarlClient.sendGoal(moveGoal);
00102   moveCarlClient.waitForResult(ros::Duration(60.0));
00103   //look at chair
00104   carl_dynamixel::LookAtFrame lookSrv;
00105   lookSrv.request.frame = "lazy_chair_2_surface_link";
00106   if (!lookAtFrameClient.call(lookSrv))
00107   {
00108     ROS_INFO("Could not call look at frame client!");
00109     return;
00110   }
00111   */
00112 
00113   /*
00114   //orange
00115   obtainObject(carl_navigation::MoveCarlGoal::FRIDGE, "kitchen_counter_right_surface_link");
00116 
00117   //return bag
00118   carl_navigation::MoveCarlGoal moveGoal;
00119   moveGoal.location = carl_navigation::MoveCarlGoal::INTERACTION_2;
00120   moveCarlClient.sendGoal(moveGoal);
00121   moveCarlClient.waitForResult(ros::Duration(60.0));
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   //navigate to given location
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   //look at surface
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   //retract arm
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     //navigate to given location
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     //look at surface
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   //obtain given object
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   //ready arm
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 }


carl_demos
Author(s): David Kent , Russell Toris
autogenerated on Thu Jun 6 2019 21:59:32