$search
00001 /* 00002 * generate_evidence.cpp 00003 * 00004 * Created on: Nov 12, 2012 00005 * Author: jelfring 00006 */ 00007 00008 #include <ros/ros.h> 00009 00010 #include "wire_msgs/WorldEvidence.h" 00011 #include "wire_msgs/ObjectEvidence.h" 00012 00013 #include "problib/conversions.h" 00014 00015 // Publisher used to send evidence to world model 00016 ros::Publisher world_evidence_publisher_; 00017 00018 00019 void addEvidence(wire_msgs::WorldEvidence& world_evidence, double x, double y, double z, const std::string& class_label, const std::string& color) { 00020 wire_msgs::ObjectEvidence obj_evidence; 00021 00022 // Set the continuous position property 00023 wire_msgs::Property posProp; 00024 posProp.attribute = "position"; 00025 00026 // Set position (x,y,z), set the covariance matrix as 0.005*identity_matrix 00027 pbl::PDFtoMsg(pbl::Gaussian(pbl::Vector3(x, y, z), pbl::Matrix3(0.0005, 0.0005, 0.0005)), posProp.pdf); 00028 obj_evidence.properties.push_back(posProp); 00029 00030 // Set the continuous orientation property 00031 wire_msgs::Property oriProp; 00032 oriProp.attribute = "orientation"; 00033 00034 // Set the orientation (0,0,0,1), with covariance matrix 0.01*identity_matrix 00035 pbl::PDFtoMsg(pbl::Gaussian(pbl::Vector4(0, 0, 0, 1), pbl::Matrix4(0.01, 0.01, 0.01, 0.01)), oriProp.pdf); 00036 obj_evidence.properties.push_back(oriProp); 00037 00038 // Set the discrete class label property 00039 wire_msgs::Property classProp; 00040 classProp.attribute = "class_label"; 00041 pbl::PMF classPMF; 00042 00043 // Probability of the class label is 0.7 00044 classPMF.setProbability(class_label, 0.7); 00045 pbl::PDFtoMsg(classPMF, classProp.pdf); 00046 obj_evidence.properties.push_back(classProp); 00047 00048 // Set the discrete color property with a probability of 0.9 00049 wire_msgs::Property colorProp; 00050 colorProp.attribute = "color"; 00051 pbl::PMF colorPMF; 00052 00053 // The probability of the detected color is 0.9 00054 colorPMF.setProbability(color, 0.1); 00055 pbl::PDFtoMsg(colorPMF, colorProp.pdf); 00056 obj_evidence.properties.push_back(colorProp); 00057 00058 // Add all properties to the array 00059 world_evidence.object_evidence.push_back(obj_evidence); 00060 } 00061 00062 00063 void generateEvidence() { 00064 00065 // Create world evidence message 00066 wire_msgs::WorldEvidence world_evidence; 00067 00068 // Set header 00069 world_evidence.header.stamp = ros::Time::now(); 00070 world_evidence.header.frame_id = "/map"; 00071 00072 // Add evidence 00073 addEvidence(world_evidence, 2, 2.2, 3, "mug", "red"); 00074 00075 // Publish results 00076 world_evidence_publisher_.publish(world_evidence); 00077 ROS_INFO("Published world evidence with size %d", world_evidence.object_evidence.size()); 00078 00079 } 00080 00084 int main(int argc, char **argv) { 00085 00086 // Initialize ros and create node handle 00087 ros::init(argc,argv,"generate_evidence"); 00088 ros::NodeHandle nh; 00089 00090 // Publisher 00091 world_evidence_publisher_ = nh.advertise<wire_msgs::WorldEvidence>("/world_evidence", 100); 00092 00093 // Publish with 3 Hz 00094 ros::Rate r(3.0); 00095 00096 while (ros::ok()) { 00097 generateEvidence(); 00098 r.sleep(); 00099 } 00100 00101 return 0; 00102 }