move_arm_warehouse_logger_reader.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2008, Willow Garage, Inc.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the Willow Garage nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  *  \author E. Gil Jones
00036  *********************************************************************/
00037 
00038 #include <ros/console.h>
00039 #include <boost/foreach.hpp>
00040 #include <sstream>
00041 
00042 #include <move_arm_warehouse/move_arm_warehouse_logger_reader.h>
00043 
00044 using namespace move_arm_warehouse;
00045 
00046 static const std::string DATABASE_NAME="arm_navigation";
00047 static const std::string PLANNING_SCENE_TIME_NAME="planning_scene_time";
00048 static const std::string PLANNING_SCENE_ID_NAME="planning_scene_id";
00049 static const std::string MOTION_PLAN_REQUEST_ID_NAME="motion_request_id";
00050 static const std::string TRAJECTORY_ID_NAME="trajectory_id";
00051 static const std::string TRAJECTORY_MOTION_REQUEST_ID_NAME="trajectory_motion_request_id";
00052 static const std::string PAUSED_COLLISION_MAP_TIME_NAME="paused_collision_map_time";
00053 
00054 typedef mongo_ros::MessageWithMetadata<arm_navigation_msgs::PlanningScene>::ConstPtr PlanningSceneWithMetadata;
00055 typedef mongo_ros::MessageWithMetadata<arm_navigation_msgs::MotionPlanRequest>::ConstPtr MotionPlanRequestWithMetadata;
00056 typedef mongo_ros::MessageWithMetadata<trajectory_msgs::JointTrajectory>::ConstPtr JointTrajectoryWithMetadata;
00057 typedef mongo_ros::MessageWithMetadata<arm_navigation_msgs::ArmNavigationErrorCodes>::ConstPtr ErrorCodesWithMetadata;
00058 typedef mongo_ros::MessageWithMetadata<head_monitor_msgs::HeadMonitorFeedback>::ConstPtr HeadMonitorFeedbackWithMetadata;
00059   
00060 MoveArmWarehouseLoggerReader::MoveArmWarehouseLoggerReader()
00061 {
00062   char hostname[256];
00063   
00064   gethostname(hostname, 256);
00065 
00066   hostname_ = hostname;
00067 
00068   ROS_DEBUG_STREAM("Hostname is " << hostname_);
00069 
00070 
00071   planning_scene_collection_ = new mongo_ros::MessageCollection<arm_navigation_msgs::PlanningScene>(DATABASE_NAME, "planning_scene");
00072   motion_plan_request_collection_ = new mongo_ros::MessageCollection<arm_navigation_msgs::MotionPlanRequest>(DATABASE_NAME, "motion_plan_request");
00073   trajectory_collection_ = new mongo_ros::MessageCollection<trajectory_msgs::JointTrajectory>(DATABASE_NAME, "trajectory");
00074   outcome_collection_ = new mongo_ros::MessageCollection<arm_navigation_msgs::ArmNavigationErrorCodes>(DATABASE_NAME, "outcome");
00075   paused_state_collection_ = new mongo_ros::MessageCollection<head_monitor_msgs::HeadMonitorFeedback>(DATABASE_NAME, "paused_state");
00076 }
00077 
00078 MoveArmWarehouseLoggerReader::~MoveArmWarehouseLoggerReader() {
00079   delete planning_scene_collection_;
00080   delete motion_plan_request_collection_;
00081   delete trajectory_collection_;
00082   delete outcome_collection_;
00083   delete paused_state_collection_;
00084 }
00085 
00089 
00090 mongo_ros::Metadata MoveArmWarehouseLoggerReader::initializeMetadataWithHostname()
00091 {
00092   return mongo_ros::Metadata("hostname", hostname_);
00093 }
00094 
00095 void MoveArmWarehouseLoggerReader::addPlanningSceneIdToMetadata(const unsigned int& id,
00096                                                                 mongo_ros::Metadata& metadata) {
00097   metadata.append(PLANNING_SCENE_ID_NAME, id);
00098 }
00099 
00100 void MoveArmWarehouseLoggerReader::addPlanningSceneTimeToMetadata(const arm_navigation_msgs::PlanningScene& planning_scene,
00101                                                                   mongo_ros::Metadata& metadata)
00102 {
00103   metadata.append(PLANNING_SCENE_TIME_NAME, planning_scene.robot_state.joint_state.header.stamp.toSec());
00104 }
00105 
00106 unsigned int MoveArmWarehouseLoggerReader::determineNextPlanningSceneId() {
00107   mongo_ros::Query q;
00108   std::vector<PlanningSceneWithMetadata> planning_scenes = planning_scene_collection_->pullAllResults(q, true, PLANNING_SCENE_ID_NAME, false);
00109   if(planning_scenes.size() == 0) {
00110     return 0;
00111   }
00112   //should be in reverse order
00113   return planning_scenes.front()->lookupInt(PLANNING_SCENE_ID_NAME)+1;
00114 }
00115 
00116 void MoveArmWarehouseLoggerReader::pushPlanningSceneToWarehouseWithoutId(const arm_navigation_msgs::PlanningScene& planning_scene,
00117                                                                          unsigned int& id) 
00118 {
00119   id = determineNextPlanningSceneId();
00120   pushPlanningSceneToWarehouse(planning_scene, id);
00121 }
00122 
00123 
00124 void MoveArmWarehouseLoggerReader::pushPlanningSceneToWarehouse(const arm_navigation_msgs::PlanningScene& planning_scene,
00125                                                                 const unsigned int id)
00126 {
00127   mongo_ros::Metadata metadata = initializeMetadataWithHostname();
00128   addPlanningSceneTimeToMetadata(planning_scene, metadata);
00129   //TODO - check for duplicates?
00130   addPlanningSceneIdToMetadata(id, metadata);
00131   planning_scene_collection_->insert(planning_scene, metadata);
00132 }
00133 
00134 void MoveArmWarehouseLoggerReader::pushMotionPlanRequestToWarehouse(const unsigned int planning_scene_id,
00135                                                                     const unsigned int mpr_id,
00136                                                                     const std::string& stage_name,
00137                                                                     const arm_navigation_msgs::MotionPlanRequest& motion_plan_request)
00138 {
00139   mongo_ros::Metadata metadata = initializeMetadataWithHostname();
00140   addPlanningSceneIdToMetadata(planning_scene_id, metadata);
00141   
00142   metadata.append("stage_name", stage_name);
00143   
00144   metadata.append(MOTION_PLAN_REQUEST_ID_NAME, mpr_id);
00145   //adding the presence of goal pose constraints to metadata
00146   metadata.append("has_goal_position_constraints", !motion_plan_request.goal_constraints.position_constraints.empty());
00147 
00148  
00149   metadata.append("has_path_constraints", 
00150                   (!motion_plan_request.path_constraints.orientation_constraints.empty() || motion_plan_request.path_constraints.position_constraints.empty()));
00151   
00152   motion_plan_request_collection_->insert(motion_plan_request, metadata);
00153 }
00154 
00155 void MoveArmWarehouseLoggerReader::pushJointTrajectoryToWarehouse(const unsigned int planning_scene_id,
00156                                                                   const std::string& trajectory_source,
00157                                                                   const ros::Duration& production_time,
00158                                                                   const trajectory_msgs::JointTrajectory& trajectory,
00159                                                                   const trajectory_msgs::JointTrajectory& trajectory_control_error,
00160                                                                   const unsigned int trajectory_id,
00161                                                                   const unsigned int motion_request_id,
00162                                                                   const arm_navigation_msgs::ArmNavigationErrorCodes& error_code)
00163 {
00164   mongo_ros::Metadata metadata = initializeMetadataWithHostname();
00165   addPlanningSceneIdToMetadata(planning_scene_id, metadata);
00166 
00167   metadata.append("trajectory_source", trajectory_source);
00168   metadata.append("production_time", production_time.toSec());
00169   metadata.append(TRAJECTORY_ID_NAME, trajectory_id);
00170   metadata.append(TRAJECTORY_MOTION_REQUEST_ID_NAME, motion_request_id);
00171   metadata.append("trajectory_error_code", error_code.val);
00172   metadata.append("controller_error", jointTrajectoryToString(trajectory_control_error));
00173   trajectory_collection_->insert(trajectory, metadata);
00174 }
00175 
00176 void MoveArmWarehouseLoggerReader::pushOutcomeToWarehouse(const unsigned int id, 
00177                                                           const std::string& pipeline_stage,
00178                                                           const arm_navigation_msgs::ArmNavigationErrorCodes& error_codes)
00179 {
00180   mongo_ros::Metadata metadata = initializeMetadataWithHostname();
00181   addPlanningSceneIdToMetadata(id, metadata);
00182 
00183   metadata.append("pipeline_stage", pipeline_stage);
00184   outcome_collection_->insert(error_codes, metadata);
00185 }
00186 
00187 void MoveArmWarehouseLoggerReader::pushPausedStateToWarehouse(const unsigned int id, 
00188                                                               const head_monitor_msgs::HeadMonitorFeedback& feedback)
00189 {
00190   mongo_ros::Metadata metadata = initializeMetadataWithHostname();
00191   addPlanningSceneIdToMetadata(id, metadata);
00192   metadata.append(PAUSED_COLLISION_MAP_TIME_NAME, feedback.paused_collision_map.header.stamp.toSec());
00193   paused_state_collection_->insert(feedback, metadata);
00194 }
00195 
00199 
00200 void MoveArmWarehouseLoggerReader::getAvailablePlanningSceneList(const std::string& hostname, 
00201                                                                  std::vector<unsigned int>& planning_scene_ids,
00202                                                                  std::vector<ros::Time>& creation_times)
00203 {
00204   creation_times.clear();
00205   planning_scene_ids.clear();
00206 
00207   // std::stringstream fin(planning_scenes[i]->metadata);
00208   // YAML::Parser parser(fin);
00209   // YAML::Node doc;
00210   // while(parser.GetNextDocument(doc)) {    }
00211 
00212   mongo_ros::Query q;
00213   std::vector<PlanningSceneWithMetadata> planning_scenes = planning_scene_collection_->pullAllResults(q, true, PLANNING_SCENE_TIME_NAME, true);
00214 
00215   planning_scene_ids.resize(planning_scenes.size());
00216   creation_times.resize(planning_scenes.size());
00217 
00218   bool no_ids = false;
00219   for(unsigned int i = 0; i < planning_scenes.size(); i++) {    
00220     if(!planning_scenes[i]->metadata.hasField(PLANNING_SCENE_ID_NAME.c_str())) {
00221       no_ids = true;
00222       break;
00223     }
00224     planning_scene_ids[i] = planning_scenes[i]->lookupInt(PLANNING_SCENE_ID_NAME);
00225     ROS_DEBUG_STREAM("Got planning scene id " << planning_scene_ids[i]);
00226     creation_times[i] = ros::Time(planning_scenes[i]->lookupDouble(PLANNING_SCENE_TIME_NAME));
00227   }
00228   if(no_ids) {
00229     ROS_WARN_STREAM("No planning scene ids, can't load");
00230   }
00231 }
00232 
00233 mongo_ros::Query MoveArmWarehouseLoggerReader::makeQueryForPlanningSceneTime(const ros::Time& time)
00234 {
00235   mongo_ros::Query retq;
00236   retq.append(PLANNING_SCENE_TIME_NAME, time.toSec()); 
00237   return retq;
00238 }
00239 
00240 mongo_ros::Query MoveArmWarehouseLoggerReader::makeQueryForPlanningSceneId(const unsigned int id)
00241 {
00242   mongo_ros::Query retq;
00243   retq.append(PLANNING_SCENE_ID_NAME, id); 
00244   return retq;
00245 }
00246 
00247 bool MoveArmWarehouseLoggerReader::getPlanningScene(const std::string& hostname, 
00248                                                     const unsigned int& id,
00249                                                     arm_navigation_msgs::PlanningScene& planning_scene, 
00250                                                     std::string& hostname_out)
00251 {
00252   mongo_ros::Query q = makeQueryForPlanningSceneId(id);  
00253   std::vector<PlanningSceneWithMetadata> planning_scenes = planning_scene_collection_->pullAllResults(q, false);
00254 
00255   if(planning_scenes.size() == 0) {
00256     ROS_WARN_STREAM("No scenes with id " << id);
00257     return false;
00258   } else if(planning_scenes.size() > 1) {
00259     ROS_WARN_STREAM("More than one scene with id " << id << " num " << planning_scenes.size());
00260   }
00261 
00262   PlanningSceneWithMetadata& scene = planning_scenes[0];
00263   planning_scene = *scene;
00264   hostname_out = scene->lookupString("hostname");
00265   return true;
00266 }
00267 
00268 bool MoveArmWarehouseLoggerReader::getAssociatedOutcomes(const std::string& hostname,
00269                                                          const unsigned int id, 
00270                                                          std::vector<std::string>& pipeline_names,
00271                                                          std::vector<arm_navigation_msgs::ArmNavigationErrorCodes>& error_codes)
00272 {
00273   mongo_ros::Query q = makeQueryForPlanningSceneId(id);  
00274   std::vector<ErrorCodesWithMetadata> meta_error_codes = outcome_collection_->pullAllResults(q, false);
00275   
00276   if(meta_error_codes.size() == 0) {
00277     ROS_DEBUG_STREAM("No outcomes associated with id " << id);
00278     return false;
00279   } 
00280   error_codes.resize(meta_error_codes.size());
00281   pipeline_names.resize(meta_error_codes.size());
00282   for(unsigned int i = 0; i < meta_error_codes.size(); i++) {
00283     pipeline_names[i] = meta_error_codes[i]->lookupString("pipeline_stage");
00284     error_codes[i] = *meta_error_codes[i];
00285   }
00286   return true;
00287 }
00288                                                  
00289 bool MoveArmWarehouseLoggerReader::getAssociatedMotionPlanRequestsStageNames(const std::string& hostname, 
00290                                                                              const unsigned int planning_scene_id,
00291                                                                              std::vector<std::string>& stage_names)
00292 {
00293   mongo_ros::Query q = makeQueryForPlanningSceneId(planning_scene_id);  
00294   std::vector<MotionPlanRequestWithMetadata> motion_plan_requests = motion_plan_request_collection_->pullAllResults(q, true, PLANNING_SCENE_ID_NAME, true);
00295 
00296   if(motion_plan_requests.size() == 0) {
00297     ROS_DEBUG_STREAM("No motion plan requests with id" << planning_scene_id);
00298     return false;
00299   } 
00300 
00301   stage_names.resize(motion_plan_requests.size());
00302   for(unsigned int i = 0; i < motion_plan_requests.size(); i++) {
00303     stage_names[i] = motion_plan_requests[i]->lookupString("stage_name");
00304   }
00305   return true; 
00306 }
00307 
00308 bool MoveArmWarehouseLoggerReader::getAssociatedMotionPlanRequest(const std::string& hostname, 
00309                                                                   const unsigned int planning_scene_id, 
00310                                                                   const unsigned int motion_request_id,
00311                                                                   arm_navigation_msgs::MotionPlanRequest& request)
00312 {  
00313   mongo_ros::Query q = makeQueryForPlanningSceneId(planning_scene_id);  
00314   q.append(MOTION_PLAN_REQUEST_ID_NAME, motion_request_id);
00315   std::vector<MotionPlanRequestWithMetadata> motion_plan_requests = motion_plan_request_collection_->pullAllResults(q, false);
00316 
00317   if(motion_plan_requests.size() == 0) {
00318     ROS_WARN_STREAM("No motion plan requests with planning scene id " << planning_scene_id
00319                     << " and motion plan id " << motion_request_id);
00320     return false;
00321   } else if(motion_plan_requests.size() > 1) {
00322     ROS_WARN_STREAM("More than one motion plan requests with planning scene id " << planning_scene_id
00323                     << " and motion plan id " << motion_request_id);
00324     return false;
00325   }
00326   request = *motion_plan_requests[0];
00327   return true;
00328 }
00329 
00330 bool MoveArmWarehouseLoggerReader::getAssociatedMotionPlanRequests(const std::string& hostname,
00331                                                                    const unsigned int planning_scene_id, 
00332                                                                    std::vector<unsigned int>& ids,
00333                                                                    std::vector<std::string>& stage_names,
00334                                                                    std::vector<arm_navigation_msgs::MotionPlanRequest>& requests)
00335 {
00336   stage_names.clear();
00337   ids.clear();
00338   requests.clear();
00339   mongo_ros::Query q = makeQueryForPlanningSceneId(planning_scene_id);
00340   std::vector<MotionPlanRequestWithMetadata> motion_plan_requests = motion_plan_request_collection_->pullAllResults(q, false);
00341 
00342   for(size_t i = 0; i < motion_plan_requests.size(); i++)
00343   {
00344     stage_names.push_back(motion_plan_requests[i]->lookupString("stage_name"));
00345     ids.push_back(motion_plan_requests[i]->lookupInt(MOTION_PLAN_REQUEST_ID_NAME));
00346     requests.push_back(*motion_plan_requests[i]);
00347     ROS_DEBUG_STREAM("Loading planning scene " << planning_scene_id << " motion plan request " << ids[i] << " from warehouse...");
00348   }
00349 
00350   return true;
00351 }
00352 
00353 bool MoveArmWarehouseLoggerReader::getAssociatedJointTrajectorySources(const std::string& hostname, 
00354                                                                        const unsigned int planning_scene_id,
00355                                                                        const unsigned int motion_request_id,
00356                                                                        std::vector<unsigned int>& ids, 
00357                                                                        std::vector<std::string>& trajectory_sources)
00358 {
00359   ids.clear();
00360   trajectory_sources.clear();
00361   mongo_ros::Query q = makeQueryForPlanningSceneId(planning_scene_id);
00362   q.append(TRAJECTORY_MOTION_REQUEST_ID_NAME, motion_request_id);
00363   
00364   std::vector<JointTrajectoryWithMetadata> joint_trajectories = trajectory_collection_->pullAllResults(q, true, TRAJECTORY_ID_NAME);
00365 
00366   if(joint_trajectories.size() == 0) {
00367     ROS_WARN_STREAM("No joint trajectories with planning scene id " << planning_scene_id
00368                     << " and motion plan id " << motion_request_id);
00369     return false;
00370   } 
00371   ids.resize(joint_trajectories.size());
00372   trajectory_sources.resize(joint_trajectories.size());
00373   for(unsigned int i = 0; i < joint_trajectories.size(); i++) {
00374     trajectory_sources[i] = joint_trajectories[i]->lookupString("trajectory_source");
00375   }
00376   return true; 
00377 }
00378 
00379 bool MoveArmWarehouseLoggerReader::getAssociatedJointTrajectory(const std::string& hostname, 
00380                                                                 const unsigned int planning_scene_id,
00381                                                                 const unsigned int motion_request_id,
00382                                                                 const unsigned int trajectory_id,
00383                                                                 ros::Duration& duration, 
00384                                                                 trajectory_msgs::JointTrajectory& joint_trajectory,
00385                                                                 trajectory_msgs::JointTrajectory& trajectory_control_error)
00386 {
00387   mongo_ros::Query q = makeQueryForPlanningSceneId(planning_scene_id);  
00388   q.append(TRAJECTORY_MOTION_REQUEST_ID_NAME, motion_request_id);
00389   q.append(TRAJECTORY_ID_NAME, trajectory_id);
00390   std::vector<JointTrajectoryWithMetadata> joint_trajectories = trajectory_collection_->pullAllResults(q, false);
00391 
00392   if(joint_trajectories.size() == 0) {
00393     ROS_WARN_STREAM("No joint trajectories with with planning scene id " << planning_scene_id
00394                     << " and motion plan id " << motion_request_id
00395                     << " and trajectory id " << trajectory_id);
00396     return false;
00397   } else if(joint_trajectories.size() > 1) {
00398     ROS_WARN_STREAM("Multiple trajectories in db with same ids");
00399     return false;
00400   }
00401   
00402   duration = ros::Duration(joint_trajectories[0]->lookupDouble("production_time"));
00403   joint_trajectory = *joint_trajectories[0];
00404   stringToJointTrajectory(joint_trajectories[0]->lookupString("controller_error"),trajectory_control_error);
00405   return true;
00406 }
00407 
00408 bool MoveArmWarehouseLoggerReader::getAssociatedJointTrajectories(const std::string& hostname,
00409                                                                   const unsigned int planning_scene_id,
00410                                                                   const unsigned int motion_request_id,
00411                                                                   std::vector<trajectory_msgs::JointTrajectory>& trajectories,
00412                                                                   std::vector<trajectory_msgs::JointTrajectory>& trajectory_control_errors,
00413                                                                   std::vector<std::string>& sources,
00414                                                                   std::vector<unsigned int>& ids,
00415                                                                   std::vector<ros::Duration>& durations,
00416                                                                   std::vector<int32_t>& error_codes)
00417 {
00418   trajectories.clear();
00419   trajectory_control_errors.clear();
00420   sources.clear();
00421   ids.clear();
00422   durations.clear();
00423   error_codes.clear();
00424   mongo_ros::Query q = makeQueryForPlanningSceneId(planning_scene_id);
00425   q.append(TRAJECTORY_MOTION_REQUEST_ID_NAME, motion_request_id);
00426   std::vector<JointTrajectoryWithMetadata> joint_trajectories = trajectory_collection_->pullAllResults(q, false);
00427  trajectory_msgs::JointTrajectory trajectory_control_error;
00428 
00429   for(size_t i = 0; i < joint_trajectories.size(); i++)
00430   {
00431     trajectories.push_back(*joint_trajectories[i]);
00432     stringToJointTrajectory(joint_trajectories[i]->lookupString("controller_error"),trajectory_control_error);
00433     trajectory_control_errors.push_back(trajectory_control_error);
00434     sources.push_back(joint_trajectories[i]->lookupString("trajectory_source"));
00435     ids.push_back(joint_trajectories[i]->lookupInt(TRAJECTORY_ID_NAME));
00436     ROS_DEBUG_STREAM("Loading mpr id " << motion_request_id << " trajectory " << ids[i] << " from warehouse...");
00437     durations.push_back(ros::Duration(joint_trajectories[i]->lookupDouble("production_time")));
00438     error_codes.push_back(joint_trajectories[i]->lookupInt("trajectory_error_code"));
00439   }
00440 
00441   return true;
00442 }
00443 
00444 bool MoveArmWarehouseLoggerReader::getAssociatedPausedStates(const std::string& hostname, 
00445                                                              const unsigned int id, 
00446                                                              std::vector<ros::Time>& paused_times)
00447 {
00448   paused_times.clear();
00449   mongo_ros::Query q = makeQueryForPlanningSceneId(id);  
00450   std::vector<HeadMonitorFeedbackWithMetadata> paused_states = paused_state_collection_->pullAllResults(q, true, PLANNING_SCENE_ID_NAME);
00451 
00452   if(paused_states.size() == 0) {
00453     return false;
00454   } 
00455   paused_times.resize(paused_states.size());
00456   for(unsigned int i = 0; i < paused_states.size(); i++) {
00457     paused_times[i] = ros::Time(paused_states[i]->lookupDouble("paused_collision_map_stamp"));
00458   }
00459   return true;   
00460 }
00461 
00462 bool MoveArmWarehouseLoggerReader::getAssociatedPausedState(const std::string& hostname, 
00463                                                             const unsigned int id, 
00464                                                             const ros::Time& paused_time,
00465                                                             head_monitor_msgs::HeadMonitorFeedback& paused_state)
00466 {
00467   mongo_ros::Query q = makeQueryForPlanningSceneId(id);  
00468   q.append(PAUSED_COLLISION_MAP_TIME_NAME, paused_time.toSec());
00469 
00470   std::vector<HeadMonitorFeedbackWithMetadata> paused_states = paused_state_collection_->pullAllResults(q, false);
00471 
00472   if(paused_states.size() == 0) {
00473     ROS_WARN_STREAM("No paused states with that time");
00474     return false;
00475   } else if(paused_states.size() > 1) {
00476     ROS_WARN_STREAM("Multiple paused states with time");
00477     return false;
00478   }
00479   paused_state = *paused_states[0];
00480   return true;
00481 }
00482 
00483 bool MoveArmWarehouseLoggerReader::hasPlanningScene(const std::string& hostname,
00484                                                     const unsigned int id) {
00485   mongo_ros::Query q = makeQueryForPlanningSceneId(id);  
00486   q.append("hostname", hostname);
00487   
00488   std::vector<PlanningSceneWithMetadata> planning_scenes = planning_scene_collection_->pullAllResults(q, true);
00489   if(planning_scenes.size() > 0) return true;
00490   return false;
00491 }
00492 
00493 bool MoveArmWarehouseLoggerReader::removePlanningSceneAndAssociatedDataFromWarehouse(const std::string& hostname,
00494                                                                                      const unsigned int id) {
00495   mongo_ros::Query q = makeQueryForPlanningSceneId(id);  
00496   q.append("hostname", hostname);
00497 
00498   unsigned int rem = planning_scene_collection_->removeMessages(q);
00499   ROS_DEBUG_STREAM("Removed " << rem << " planning scenes");
00500 
00501   bool has_planning_scene = (rem > 0);
00502   
00503   rem = motion_plan_request_collection_->removeMessages(q);
00504   ROS_DEBUG_STREAM("Removed " << rem << " motion plan requests");
00505 
00506   rem = trajectory_collection_->removeMessages(q);
00507   ROS_DEBUG_STREAM("Removed " << rem << " trajectories");
00508 
00509   rem = outcome_collection_->removeMessages(q);
00510   ROS_DEBUG_STREAM("Removed " << rem << " outcomes");
00511 
00512   rem = paused_state_collection_->removeMessages(q);
00513   ROS_DEBUG_STREAM("Removed " << rem << " paused states");
00514 
00515   return has_planning_scene;
00516 }
00517 
00518 std::string MoveArmWarehouseLoggerReader::jointTrajectoryToString(const trajectory_msgs::JointTrajectory& trajectory)
00519 {
00520   std::stringstream returnval;
00521   returnval << trajectory.points.size() << ",";
00522   for( unsigned int i=0; i<trajectory.points.size(); i++)
00523   {
00524     const trajectory_msgs::JointTrajectoryPoint& point = trajectory.points[i];
00525     returnval << point.positions.size() << ",";
00526     for( unsigned int j=0; j<point.positions.size(); j++ )
00527     {
00528       returnval << point.positions[j] << ",";
00529       returnval << point.velocities[j] << ",";
00530     }
00531   }
00532 
00533   return returnval.str();
00534 }
00535 
00536 void MoveArmWarehouseLoggerReader::stringToJointTrajectory(const std::string& trajectory, trajectory_msgs::JointTrajectory& joint_trajectory_error)
00537 {
00538   std::stringstream stream(trajectory);
00539   double position;
00540   double velocity;
00541   char c;
00542   int tsize;
00543   int psize;
00544   joint_trajectory_error.points.clear();
00545 
00546 
00547   stream >> tsize;
00548   stream >> c;
00549   for( int i=0; i<tsize; i++)
00550   {
00551     trajectory_msgs::JointTrajectoryPoint point;
00552     stream >> psize;
00553     stream >> c;
00554     for( int j=0; j<psize; j++)
00555     {
00556       stream >> position;
00557       stream >> c;
00558       stream >> velocity;
00559       stream >> c;
00560       point.positions.push_back(position);
00561       point.velocities.push_back(position);
00562     }
00563     joint_trajectory_error.points.push_back(point);
00564   }
00565 }
00566 
00567 // void MoveArmWarehouseLoggerReader::deleteMotionPlanRequestFromWarehouse(const arm_navigation_msgs::PlanningScene& planning_scene,
00568 //                                                                         const std::string& stage_name,
00569 //                                                                         const std::string& ID)
00570 // {
00571 //   mongo_ros::Query q = makeQueryForPlanningSceneTime(time);  
00572 //   q.append("stage_name", stage_name);
00573 //   q.append("motion_request_id", ID);
00574 //   std::vector<MotionPlanRequestWithMetadata> motion_plan_requests = motion_plan_request_collection_->pullAllResults(q, false);
00575 //   coll.removeMessages(q);
00576 //   std::vector<MotionPlanRequestWithMetadata> motion_plan_requests_after = motion_plan_request_collection_->pullAllResults(q, false);
00577 //   ROS_DEBUG_STREAM("Removing " << motion_plan_requests.size()-motion_plan_requests_after.size() << " motion plan requests");
00578 // }


move_arm_warehouse
Author(s): Ioan Sucan, Sachin Chitta(sachinc@willowgarage.com)
autogenerated on Thu Dec 12 2013 11:09:11