Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <ros/ros.h>
00009
00010 #include "articulation_models/models/factory.h"
00011
00012 #include "articulation_msgs/ModelMsg.h"
00013 #include "articulation_msgs/TrackMsg.h"
00014 #include "articulation_msgs/ParamMsg.h"
00015
00016 using namespace std;
00017 using namespace articulation_models;
00018 using namespace articulation_msgs;
00019
00020 #include <boost/random.hpp>
00021 #include <boost/random/normal_distribution.hpp>
00022
00023 int main(int argc, char** argv) {
00024 ros::init(argc, argv, "model_fitting");
00025 ros::NodeHandle n;
00026 ros::Publisher model_pub = n.advertise<ModelMsg> ("model", 5);
00027 ros::Rate loop_rate(5);
00028 int count = 0;
00029
00030 boost::normal_distribution<> nd(0.0, 0.01);
00031 boost::mt19937 rng;
00032 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> >
00033 var_nor(rng, nd);
00034
00035 MultiModelFactory factory;
00036
00037 ModelMsg model_msg;
00038 model_msg.name = "rotational";
00039 ParamMsg sigma_param;
00040 sigma_param.name = "sigma_position";
00041 sigma_param.value = 0.02;
00042 sigma_param.type = ParamMsg::PRIOR;
00043 sigma_param.name = "sigma_orientation";
00044 sigma_param.value = M_PI*10;
00045 sigma_param.type = ParamMsg::PRIOR;
00046 model_msg.params.push_back(sigma_param);
00047
00048 model_msg.track.header.stamp = ros::Time();
00049 model_msg.track.header.frame_id = "/";
00050
00051 while (ros::ok()) {
00052
00053 geometry_msgs::Pose pose;
00054 pose.position.x = cos(count / 30.0)+var_nor();
00055 pose.position.y = sin(count / 30.0)+var_nor();
00056 pose.position.z = var_nor();
00057 pose.orientation.x = 0;
00058 pose.orientation.y = 0;
00059 pose.orientation.z = 0;
00060 pose.orientation.w = 1;
00061 model_msg.track.pose.push_back(pose);
00062
00063 if(model_msg.track.pose.size()<3) continue;
00064
00065 cout <<"creating object"<<endl;
00066 GenericModelPtr model_instance = factory.restoreModel(model_msg);
00067 cout <<"fitting"<<endl;
00068 model_instance->fitModel();
00069 cout <<"evaluating"<<endl;
00070 model_instance->evaluateModel();
00071 cout <<"done"<<endl;
00072
00073 cout << "model class = "<< model_instance->getModelName() << endl;
00074 cout << " radius = "<<model_instance->getParam("rot_radius")<< endl;
00075 cout << " center.x = "<<model_instance->getParam("rot_center.x")<< endl;
00076 cout << " center.y = "<<model_instance->getParam("rot_center.y")<< endl;
00077 cout << " center.z = "<<model_instance->getParam("rot_center.z")<< endl;
00078 cout << " log LH = " << model_instance->getParam("loglikelihood")<< endl;
00079
00080 ModelMsg fitted_model_msg = model_instance->getModel();
00081 model_pub.publish(fitted_model_msg);
00082
00083 ros::spinOnce();
00084 loop_rate.sleep();
00085 ++count;
00086 }
00087 }