Go to the documentation of this file.00001 #ifndef OBJECT_TRACKER_OBJECT_TRACKER_H
00002 #define OBJECT_TRACKER_OBJECT_TRACKER_H
00003
00004 #include <ros/ros.h>
00005 #include <std_msgs/String.h>
00006 #include <std_msgs/Float32.h>
00007 #include <worldmodel_msgs/ImagePercept.h>
00008 #include <worldmodel_msgs/PosePercept.h>
00009 #include <worldmodel_msgs/SetObjectState.h>
00010 #include <worldmodel_msgs/SetObjectName.h>
00011 #include <worldmodel_msgs/AddObject.h>
00012 #include <worldmodel_msgs/GetObjectModel.h>
00013 #include <sensor_msgs/CameraInfo.h>
00014
00015 #include <tf/transform_listener.h>
00016 #include <image_geometry/pinhole_camera_model.h>
00017
00018 #include <hector_marker_drawing/HectorDrawings.h>
00019
00020 #include "ObjectModel.h"
00021
00022 namespace hector_object_tracker {
00023
00024 class ObjectTracker {
00025 public:
00026 ObjectTracker();
00027 virtual ~ObjectTracker();
00028
00029 protected:
00030 void sysCommandCb(const std_msgs::StringConstPtr &);
00031 void imagePerceptCb(const worldmodel_msgs::ImagePerceptConstPtr &);
00032 void posePerceptCb(const worldmodel_msgs::PosePerceptConstPtr &);
00033 void objectAgeingCb(const std_msgs::Float32ConstPtr &);
00034
00035 void modelUpdateCb(const worldmodel_msgs::ObjectModelConstPtr &);
00036
00037 bool setObjectStateCb(worldmodel_msgs::SetObjectState::Request& request, worldmodel_msgs::SetObjectState::Response& response);
00038 bool setObjectNameCb(worldmodel_msgs::SetObjectName::Request& request, worldmodel_msgs::SetObjectName::Response& response);
00039 bool addObjectCb(worldmodel_msgs::AddObject::Request& request, worldmodel_msgs::AddObject::Response& response);
00040 bool getObjectModelCb(worldmodel_msgs::GetObjectModel::Request& request, worldmodel_msgs::GetObjectModel::Response& response);
00041
00042 ObjectModel& getModel() { return model; }
00043 const ObjectModel& getModel() const { return model; }
00044
00045 ObjectModel getMergedModel();
00046
00047 void publishModelEvent(const ros::TimerEvent&);
00048 void publishModel();
00049
00050 protected:
00051 bool transformPose(const geometry_msgs::Pose& from, geometry_msgs::Pose &to, std_msgs::Header &header, tf::StampedTransform *transform = 0);
00052 bool transformPose(const geometry_msgs::PoseWithCovariance& from, geometry_msgs::PoseWithCovariance &to, std_msgs::Header &header);
00053 bool mapToNextObstacle(const geometry_msgs::Pose& source, const std_msgs::Header &header, const worldmodel_msgs::ObjectInfo &info, geometry_msgs::Pose &mapped);
00054
00055 private:
00056 ros::NodeHandle nh;
00057 ros::NodeHandle priv_nh;
00058 ros::Subscriber imagePerceptSubscriber;
00059 ros::Subscriber posePerceptSubscriber;
00060 ros::Subscriber sysCommandSubscriber;
00061 ros::Subscriber objectAgeingSubscriber;
00062
00063 struct NegativeUpdateInfo {
00064 std::string class_id;
00065 worldmodel_msgs::ObjectInfo::_support_type negative_support;
00066 worldmodel_msgs::ObjectInfo::_support_type min_support;
00067 float min_distance;
00068 float max_distance;
00069 float ignore_border_pixels;
00070 ros::Duration not_seen_duration;
00071 ros::Subscriber subscriber;
00072 };
00073 typedef boost::shared_ptr<NegativeUpdateInfo> NegativeUpdatePtr;
00074 std::vector<NegativeUpdatePtr> negativeUpdate;
00075 void negativeUpdateCallback(const sensor_msgs::CameraInfoConstPtr &, const NegativeUpdatePtr& info);
00076
00077 ros::Publisher modelPublisher;
00078 ros::Publisher modelUpdatePublisher;
00079 ros::Publisher poseDebugPublisher;
00080 ros::Publisher pointDebugPublisher;
00081 ros::Subscriber modelUpdateSubscriber;
00082
00083 ros::ServiceServer setObjectState;
00084 ros::ServiceServer addObject;
00085 ros::ServiceServer getObjectModel;
00086 ros::ServiceServer setObjectName;
00087
00088 ros::Timer publishTimer;
00089
00090 typedef std::pair<ros::ServiceClient,XmlRpc::XmlRpcValue> VerificationService;
00091 std::map<std::string,std::map<std::string,std::vector<VerificationService> > > verificationServices;
00092
00093 tf::TransformListener tf;
00094
00095 HectorDrawings drawings;
00096
00097 ObjectModel model;
00098 typedef boost::shared_ptr<image_geometry::PinholeCameraModel> CameraModelPtr;
00099 std::map<std::string,CameraModelPtr> cameraModels;
00100 ObjectTracker::CameraModelPtr getCameraModel(const std::string& frame_id, const sensor_msgs::CameraInfo& camera_info);
00101
00102 struct MergedModelInfo {
00103 std::string prefix;
00104 ObjectModel model;
00105 ros::Subscriber subscriber;
00106 };
00107 typedef boost::shared_ptr<MergedModelInfo> MergedModelPtr;
00108 std::vector<MergedModelPtr> merged_models;
00109 void mergeModelCallback(const worldmodel_msgs::ObjectModelConstPtr &new_model, const MergedModelPtr& info);
00110
00111 std::string _frame_id;
00112 std::string _worldmodel_ns;
00113
00114 double _ageing_threshold;
00115 double _publish_interval;
00116 };
00117
00118 }
00119
00120 #endif // OBJECT_TRACKER_OBJECT_TRACKER_H