00001 #include "tidyup_actions/goalCreatorTidyupObjects.h"
00002 #include "hardcoded_facts/geometryPoses.h"
00003 #include "tidyup_utils/stringutil.h"
00004 #include <pluginlib/class_list_macros.h>
00005 #include <ros/ros.h>
00006 #include <tf/transform_datatypes.h>
00007 #include <set>
00008
00009 PLUGINLIB_DECLARE_CLASS(tidyup_actions, goal_creator_tidyup_objects,
00010 tidyup_actions::GoalCreatorTidyupObjects, continual_planning_executive::GoalCreator)
00011
00012 namespace tidyup_actions
00013 {
00014
00015 GoalCreatorTidyupObjects::GoalCreatorTidyupObjects()
00016 {
00017 }
00018
00019 GoalCreatorTidyupObjects::~GoalCreatorTidyupObjects()
00020 {
00021 }
00022
00023 bool GoalCreatorTidyupObjects::fillStateAndGoal(SymbolicState & currentState, SymbolicState & goal)
00024 {
00025 ros::NodeHandle nhPriv("~");
00026
00027
00028 currentState.addSuperType("pose", "pose");
00029 currentState.addSuperType("frameid", "frameid");
00030 currentState.addSuperType("location", "pose");
00031 currentState.addSuperType("manipulation_location", "location");
00032 currentState.addSuperType("door_location", "location");
00033 currentState.addSuperType("door_in_location", "door_location");
00034 currentState.addSuperType("door_out_location", "door_location");
00035 currentState.addSuperType("room", "room");
00036 currentState.addSuperType("static_object", "static_object");
00037 currentState.addSuperType("door", "door");
00038 currentState.addSuperType("movable_object", "pose");
00039 currentState.addSuperType("arm", "arm");
00040 currentState.addSuperType("arm_state", "arm_state");
00041 goal.addSuperType("pose", "pose");
00042 goal.addSuperType("frameid", "frameid");
00043 goal.addSuperType("location", "pose");
00044 goal.addSuperType("manipulation_location", "location");
00045 goal.addSuperType("door_location", "location");
00046 goal.addSuperType("door_in_location", "door_location");
00047 goal.addSuperType("door_out_location", "door_location");
00048 goal.addSuperType("room", "room");
00049 goal.addSuperType("static_object", "static_object");
00050 goal.addSuperType("door", "door");
00051 goal.addSuperType("movable_object", "pose");
00052 goal.addSuperType("arm", "arm");
00053 goal.addSuperType("arm_state", "arm_state");
00054
00055 currentState.printSuperTypes();
00056
00057
00058 std::string locationsFile;
00059
00060 if(!nhPriv.getParam("locations", locationsFile)) {
00061 ROS_ERROR("Could not get ~locations parameter.");
00062 return false;
00063 }
00064 ROS_INFO("%s: file_name: %s", __PRETTY_FUNCTION__, locationsFile.c_str());
00065 GeometryPoses locations = GeometryPoses();
00066 if(!locations.load(locationsFile)) {
00067 ROS_ERROR("Could not load locations from \"%s\".", locationsFile.c_str());
00068 return false;
00069 }
00070
00071 std::set<string> rooms;
00072 std::set<string> doors;
00073 std::set<string> static_objects;
00074 forEach(const GeometryPoses::NamedPose & np, locations.getPoses()) {
00075 const string& location = np.first;
00076 currentState.setNumericalFluent("timestamp", location, np.second.header.stamp.toSec());
00077 currentState.addObject(np.second.header.frame_id, "frameid");
00078 currentState.setObjectFluent("frame-id", location, np.second.header.frame_id);
00079 currentState.setNumericalFluent("x", location, np.second.pose.position.x);
00080 currentState.setNumericalFluent("y", location, np.second.pose.position.y);
00081 currentState.setNumericalFluent("z", location, np.second.pose.position.z);
00082 currentState.setNumericalFluent("qx", location, np.second.pose.orientation.x);
00083 currentState.setNumericalFluent("qy", location, np.second.pose.orientation.y);
00084 currentState.setNumericalFluent("qz", location, np.second.pose.orientation.z);
00085 currentState.setNumericalFluent("qw", location, np.second.pose.orientation.w);
00086
00087
00088
00089 const vector<string>& nameParts = StringUtil::split(location, "_");
00090 const string& room = nameParts[nameParts.size()-1];
00091 const string& type = nameParts[0];
00092 string name = nameParts[0];
00093 for(size_t i = 1; i < nameParts.size()-1; i++)
00094 name += "_" + nameParts[i];
00095 rooms.insert(room);
00096 currentState.addObject(room, "room");
00097 currentState.setObjectFluent("location-in-room", location, room);
00098
00099 if (StringUtil::startsWith(type, "door"))
00100 {
00101 doors.insert(name);
00102 currentState.addObject(name, "door");
00103
00104
00105 currentState.setObjectFluent("belongs-to-door", location, name);
00106 currentState.addObject(location, "door_in_location");
00107 goal.addObject(location, "door_in_location");
00108
00109
00110 geometry_msgs::PoseStamped outPose = np.second;
00111 tf::Quaternion rot180 = tf::createQuaternionFromYaw(M_PI);
00112 tf::Quaternion locRot;
00113 tf::quaternionMsgToTF(outPose.pose.orientation, locRot);
00114 tf::quaternionTFToMsg(locRot * rot180, outPose.pose.orientation);
00115
00116 string outLocation = location + "_out";
00117 currentState.setObjectFluent("belongs-to-door", outLocation, name);
00118 currentState.addObject(outLocation, "door_out_location");
00119 goal.addObject(outLocation, "door_out_location");
00120
00121 currentState.setNumericalFluent("timestamp", outLocation, outPose.header.stamp.toSec());
00122 currentState.setObjectFluent("frame-id", outLocation, outPose.header.frame_id);
00123 currentState.setNumericalFluent("x", outLocation, outPose.pose.position.x);
00124 currentState.setNumericalFluent("y", outLocation, outPose.pose.position.y);
00125 currentState.setNumericalFluent("z", outLocation, outPose.pose.position.z);
00126 currentState.setNumericalFluent("qx", outLocation, outPose.pose.orientation.x);
00127 currentState.setNumericalFluent("qy", outLocation, outPose.pose.orientation.y);
00128 currentState.setNumericalFluent("qz", outLocation, outPose.pose.orientation.z);
00129 currentState.setNumericalFluent("qw", outLocation, outPose.pose.orientation.w);
00130 currentState.setObjectFluent("location-in-room", outLocation, room);
00131 }
00132 else
00133 {
00134 static_objects.insert(name);
00135 currentState.addObject(name, "static_object");
00136 currentState.setBooleanPredicate("static-object-at-location", name + " " + location, true);
00137 currentState.addObject(location, "manipulation_location");
00138 goal.addObject(location, "manipulation_location");
00139 }
00140 }
00141
00142 goal.setForEachGoalStatement("manipulation_location", "searched", true);
00143 goal.setForEachGoalStatement("movable_object", "tidy", true);
00144 goal.setForEachGoalStatement("arm", "hand-free", true);
00145 goal.setForEachGoalStatement("wipe_point", "wiped", true);
00146
00147 currentState.setBooleanPredicate("can-grasp", "right_arm", true);
00148 currentState.setBooleanPredicate("can-grasp", "left_arm", true);
00149
00150 currentState.setObjectFluent("arm-state", "right_arm", "arm_unknown");
00151 currentState.setObjectFluent("arm-state", "left_arm", "arm_unknown");
00152
00153 return true;
00154 }
00155
00156 };
00157