world.h
Go to the documentation of this file.
00001 #ifndef PBD_WORLD
00002 #define PBD_WORLD
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <boost/thread/mutex.hpp>
00007 #include <boost/thread/thread.hpp>
00008 
00009 #include "ros/ros.h"
00010 #include "sensor_msgs/PointCloud2.h"
00011 #include "geometry_msgs/Vector3.h"
00012 #include "geometry_msgs/PoseStamped.h"
00013 #include "geometry_msgs/TransformStamped.h"
00014 #include "geometry_msgs/Quaternion.h"
00015 #include "geometry_msgs/Point.h"
00016 #include "visualization_msgs/Marker.h"
00017 #include "visualization_msgs/InteractiveMarker.h"
00018 #include "visualization_msgs/InteractiveMarkerControl.h"
00019 #include "visualization_msgs/InteractiveMarkerFeedback.h"
00020 #include <interactive_markers/interactive_marker_server.h>
00021 #include "rail_manipulation_msgs/SegmentedObject.h"
00022 #include "rail_manipulation_msgs/SegmentedObjectList.h"
00023 #include <moveit/planning_interface/planning_interface.h>
00024 #include <moveit/planning_scene/planning_scene.h>
00025 #include "fetch_pbd_interaction/WorldState.h"
00026 #include "fetch_pbd_interaction/Landmark.h"
00027 #include "fetch_pbd_interaction/GetObjectList.h"
00028 #include "fetch_pbd_interaction/GetMostSimilarObject.h"
00029 #include "fetch_pbd_interaction/GetObjectFromName.h"
00030 #include "fetch_pbd_interaction/GetNearestObject.h"
00031 #include "std_msgs/ColorRGBA.h"
00032 #include "std_srvs/Empty.h"
00033 #include "moveit_msgs/CollisionObject.h"
00034 #include "moveit_msgs/PlanningScene.h"
00035 #include "shape_msgs/SolidPrimitive.h"
00036 
00037 // #include "pcl/point_cloud.h"
00038 #include "pcl_conversions/pcl_conversions.h"
00039 #include "pcl/point_types.h"
00040 #include "pcl/filters/filter.h"
00041 #include "pcl/common/centroid.h"
00042 #include "pcl/common/common.h"
00043 #include "pcl/common/distances.h"
00044 #include "pcl/common/pca.h"
00045 #include "pcl/filters/filter.h"
00046 #include "pcl/kdtree/kdtree_flann.h"
00047 #include "pcl/point_types.h"
00048 #include "pcl/search/kdtree.h"
00049 #include "pcl/segmentation/conditional_euclidean_clustering.h"
00050 #include "pcl/segmentation/extract_clusters.h"
00051 #include "pcl/segmentation/region_growing_rgb.h"
00052 #include "pcl_conversions/pcl_conversions.h"
00053 #include <pcl/filters/radius_outlier_removal.h>
00054 #include <pcl/ModelCoefficients.h>
00055 #include <pcl/point_types.h>
00056 #include <pcl/io/pcd_io.h>
00057 #include <pcl/filters/extract_indices.h>
00058 #include <pcl/filters/voxel_grid.h>
00059 #include <pcl/features/normal_3d.h>
00060 #include <pcl/kdtree/kdtree.h>
00061 #include <pcl/sample_consensus/method_types.h>
00062 #include <pcl/sample_consensus/model_types.h>
00063 #include <pcl/segmentation/sac_segmentation.h>
00064 #include <pcl/segmentation/extract_clusters.h>
00065 #include <pcl/filters/passthrough.h>
00066 #include <pcl/filters/project_inliers.h>
00067 #include <pcl/surface/concave_hull.h>
00068 #include <pcl/point_types_conversion.h>
00069 #include <pcl_ros/transforms.h>
00070 #include <pcl_ros/impl/transforms.hpp>
00071 #include <pcl/common/centroid.h>
00072 #include <pcl/common/common.h>
00073 #include <pcl/filters/filter.h>
00074 #include <pcl/filters/crop_box.h>
00075 #include <pcl/filters/conditional_removal.h>
00076 #include <pcl/console/parse.h>
00077 
00078 #include <tf/transform_listener.h>
00079 #include <tf/transform_broadcaster.h>
00080 
00081 #include <algorithm>
00082 #include <math.h>
00083 
00084 #include "fetch_pbd_interaction/world_landmark.h"
00085 
00086 namespace fetch_pbd_interaction {
00087 
00088 class World {
00089 
00090 private:
00091     boost::mutex mutex;
00092     std::vector<fetch_pbd_interaction::WorldLandmark> objects;
00093     interactive_markers::InteractiveMarkerServer im_server;
00094     ros::Publisher add_grasp_pub;
00095     ros::Publisher world_update_pub;
00096     ros::Publisher planning_scene_diff_publisher;
00097     ros::Subscriber table_subscriber;
00098     ros::Subscriber object_subscriber;
00099     ros::ServiceClient segmentation_service_client;
00100     std::string segmented_objects_topic;
00101     bool has_surface;
00102     tf::TransformListener tf_listener;
00103     tf::TransformBroadcaster tf_broadcaster;
00104     ros::ServiceServer nearest_object_service;
00105     ros::ServiceServer object_list_service;
00106     ros::ServiceServer similar_object_service;
00107     ros::ServiceServer object_from_name_service;
00108     ros::ServiceServer clear_world_objects_service;
00109     ros::ServiceServer update_world_service;
00110     interactive_markers::MenuHandler menu_handler;
00111     geometry_msgs::Vector3 scale_text;
00112     // Two objects must be closer than this to be considered 'the same'.
00113     float obj_similar_dist_threshold;
00114 
00115     // When adding objects, if they are closer than this they'll replace one
00116     // another.
00117     float obj_add_dist_threshold;
00118 
00119     // How close to 'nearest' object something must be to be counted as
00120     // 'near' it.     
00121     float obj_nearest_dist_threshold;
00122 
00123     // Landmark distances below this will be clamped to zero.
00124     float obj_dist_zero_clamp;
00125 
00126     // Scales
00127     float text_height;
00128     float surface_height;  // 0.01 == 1cm (i think)
00129     float text_offset;  // how high objects' labels are above them.
00130 
00131     // colors
00132     std_msgs::ColorRGBA color_obj; // not yet a param
00133     std_msgs::ColorRGBA color_surface; // not yet a param
00134     std_msgs::ColorRGBA color_text; // not yet a param
00135 
00136     // frames
00137     std::string base_frame;
00138     ros::Duration marker_duration;
00139 
00140     static void pc2ToMarker(sensor_msgs::PointCloud2 pc2, int index, 
00141                                   ros::Duration duration, std::string output_frame,
00142                                   visualization_msgs::Marker* pc2_marker_points, visualization_msgs::Marker* pc2_marker_sphere_list);
00143 
00144     static float objectDissimilarity(fetch_pbd_interaction::Landmark obj1, fetch_pbd_interaction::Landmark obj2);
00145 
00146     static float poseDistance(geometry_msgs::Pose pose1, geometry_msgs::Pose pose2, bool is_on_table=true);
00147     
00148     visualization_msgs::InteractiveMarker getSurfaceMarker(geometry_msgs::Pose pose, geometry_msgs::Vector3 dimensions);
00149 
00150     void worldChanged();
00151 
00152     bool getMostSimilarObjectCallback(fetch_pbd_interaction::GetMostSimilarObject::Request& req,
00153                      fetch_pbd_interaction::GetMostSimilarObject::Response& res);
00154 
00155     std::vector<fetch_pbd_interaction::Landmark> getObjectList();
00156 
00157     bool getObjectListCallback(fetch_pbd_interaction::GetObjectList::Request& req, 
00158                       fetch_pbd_interaction::GetObjectList::Response& resp);
00159 
00160     bool updateWorldCallback(fetch_pbd_interaction::GetObjectList::Request& req, 
00161                       fetch_pbd_interaction::GetObjectList::Response& resp);
00162 
00163     bool getObjectFromNameCallback(fetch_pbd_interaction::GetObjectFromName::Request& req, 
00164                       fetch_pbd_interaction::GetObjectFromName::Response& resp);
00165 
00166     bool hasObjects();
00167 
00168     void recordObjectPose();
00169 
00170     void objectsUpdateCallback(const rail_manipulation_msgs::SegmentedObjectListConstPtr& msg);
00171     
00172     void getBoundingBox(sensor_msgs::PointCloud2 pc2, geometry_msgs::Vector3* dimensions, geometry_msgs::Pose* pose);
00173 
00174 
00175     void tablePositionUpdateCallback(const rail_manipulation_msgs::SegmentedObjectPtr& msg);
00176 
00177     bool clearObjectsCallback(std_srvs::Empty::Request& req, 
00178                       std_srvs::Empty::Response& resp);
00179 
00180     void clearObjects();
00181 
00182     bool getNearestObjectCallback(fetch_pbd_interaction::GetNearestObject::Request& req, 
00183                       fetch_pbd_interaction::GetNearestObject::Response& resp);
00184 
00185     void markerFeedbackCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
00186 
00187     void resetObjects();
00188 
00189     bool addNewObject(geometry_msgs::Pose pose, geometry_msgs::Vector3 dimensions, 
00190                         sensor_msgs::PointCloud2 point_cloud);
00191 
00192 
00193     void removeSurfaceMarker();
00194 
00195     visualization_msgs::InteractiveMarker getObjectMarker(int index);
00196 
00197     void addSurfaceToPlanningScene(geometry_msgs::Pose pose, geometry_msgs::Vector3 dimensions);
00198 
00199     void removeSurfaceFromPlanningScene();
00200   
00201     void publishTfPose(geometry_msgs::Pose pose, std::string name, std::string parent);
00202 
00203     void removeObject(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
00204 
00205     void addGrasp(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback);
00206 
00207 
00208 public:
00209     World(ros::NodeHandle n, ros::NodeHandle pn, 
00210               const std::string grasp_suggestion_service, 
00211               const std::string& segmentation_service_name, const std::string& segmented_objects_topic_name,
00212               const std::string& segmented_table_topic_name, const std::string& planning_scene_topic, 
00213               const float&  obj_similar_distance_threshold, const float&  obj_add_distance_threshold,
00214               const float&  obj_nearest_distance_threshold, 
00215               const float& obj_distance_zero_clamp, const float& text_h, 
00216               const float&  surface_h, const float&  text_off, 
00217               const std::string& base_frame_name);
00218     ~World();
00219 
00220     void update();
00221 
00222 };
00223 
00224 };
00225 
00226 #endif
00227 


fetch_pbd_interaction
Author(s): Sarah Elliott
autogenerated on Thu Jun 6 2019 18:27:21