Go to the documentation of this file.00001 #include "tidyup_actions/stateCreatorRobotLocationInRoom.h"
00002 #include <pluginlib/class_list_macros.h>
00003
00004 PLUGINLIB_DECLARE_CLASS(tidyup_actions, state_creator_robot_location_in_room,
00005 tidyup_actions::StateCreatorRobotLocationInRoom, continual_planning_executive::StateCreator)
00006
00007 namespace tidyup_actions
00008 {
00009
00010 StateCreatorRobotLocationInRoom::StateCreatorRobotLocationInRoom()
00011 {
00012 }
00013
00014 StateCreatorRobotLocationInRoom::~StateCreatorRobotLocationInRoom()
00015 {
00016 }
00017
00018 void StateCreatorRobotLocationInRoom::initialize(const std::deque<std::string> & arguments)
00019 {
00020 ROS_ASSERT(arguments.size() == 2);
00021
00022 _robotPoseObject = arguments[0];
00023 _locationType = arguments[1];
00024 }
00025
00026 bool StateCreatorRobotLocationInRoom::fillState(SymbolicState & state)
00027 {
00028
00029
00030 string robotRoom;
00031 Predicate p;
00032 p.name = "location-in-room";
00033 p.parameters.push_back(_robotPoseObject);
00034 if(!state.hasObjectFluent(p, &robotRoom)) {
00035
00036 tf::StampedTransform transform;
00037 try{
00038 _tf.lookupTransform("/map", "/base_link", ros::Time(0), transform);
00039 }
00040 catch (tf::TransformException& ex){
00041 ROS_ERROR("%s",ex.what());
00042 return false;
00043 }
00044
00045
00046 pair<SymbolicState::TypedObjectConstIterator, SymbolicState::TypedObjectConstIterator> locations =
00047 state.getTypedObjects().equal_range(_locationType);
00048
00049 double minDist = HUGE_VAL;
00050 robotRoom = "";
00051 for(SymbolicState::TypedObjectConstIterator it = locations.first; it != locations.second; it++) {
00052 string location = it->second;
00053 p.parameters[0] = location;
00054
00055
00056 p.name = "location-in-room";
00057 string room;
00058 if(!state.hasObjectFluent(p, &room)) {
00059 continue;
00060 }
00061
00062 p.name = "x";
00063 double valueX;
00064 if(!state.hasNumericalFluent(p, &valueX)) {
00065 ROS_ERROR("%s: location: %s - no x-location.", __func__, location.c_str());
00066 continue;
00067 }
00068 double valueY;
00069 p.name = "y";
00070 if(!state.hasNumericalFluent(p, &valueY)) {
00071 ROS_ERROR("%s: location: %s - no y-location.", __func__, location.c_str());
00072 continue;
00073 }
00074
00075 double dist = hypot(valueX - transform.getOrigin().x(), valueY - transform.getOrigin().y());
00076 if(dist < minDist) {
00077 minDist = dist;
00078 robotRoom = room;
00079 }
00080 }
00081
00082
00083 if(robotRoom.empty()) {
00084 ROS_WARN("Could not infer location-in-room for robot_location as no nearest location with location-in-room set was found.");
00085 return false;
00086 } else {
00087 ROS_INFO("Determined (location-in-room %s) = %s", _robotPoseObject.c_str(), robotRoom.c_str());
00088 state.setObjectFluent("location-in-room", _robotPoseObject, robotRoom);
00089 }
00090 }
00091
00092 return true;
00093 }
00094
00095 };
00096