Go to the documentation of this file.00001
00018 #include <ros/ros.h>
00019 #include <asr_msgs/AsrObject.h>
00020 #include <sensor_msgs/JointState.h>
00021 #include <geometry_msgs/PoseStamped.h>
00022 #include <posedetection_msgs/Object6DPose.h>
00023 #include <string>
00024 #include <iostream>
00025 #include <fstream>
00026 #include <boost/thread.hpp>
00027
00028
00029 class DataTracker {
00030 public:
00031 ros::NodeHandle nh;
00032
00033
00034 ros::Subscriber ptu_sub;
00035 ros::Subscriber fob_sub;
00036 ros::Subscriber cbd_sub;
00037
00038 std::string ptu_topic, fob_topic, cbd_topic, output_file_path;
00039
00040 double pan, tilt;
00041 geometry_msgs::Pose fob_pose;
00042 geometry_msgs::Pose cbd_pose;
00043
00044 int data_counter;
00045
00046 void ptuCB(const sensor_msgs::JointState& ptu_msg) {
00047 ROS_DEBUG("ptu Message recieved");
00048 pan = ptu_msg.position[0];
00049 tilt = ptu_msg.position[1];
00050 }
00051
00052 void fobCB(const asr_msgs::AsrObject& fob_msg) {
00053 if (!fob_msg.identifier.empty() && strcmp(fob_msg.identifier.c_str(), "tracker_left_raw") == 0) {
00054 ROS_DEBUG("fob message recieved");
00055 geometry_msgs::PoseWithCovariance current_pose_with_c = fob_msg.sampledPoses.back();
00056 fob_pose = current_pose_with_c.pose;
00057 }
00058 }
00059 void cbdCB(const geometry_msgs::PoseStamped& cbd_msg) {
00060 ROS_DEBUG("cbd message recieved");
00061 ROS_INFO("cbd message recieved");
00062 cbd_pose = cbd_msg.pose;
00063 }
00064
00065 DataTracker(ros::NodeHandle nh){
00066 this->nh = nh;
00067 nh.getParam("ptu_topic", ptu_topic);
00068 nh.getParam("fob_topic", fob_topic);
00069 nh.getParam("cbd_topic", cbd_topic);
00070 nh.getParam("output_file_path", output_file_path);
00071
00072 ptu_sub = nh.subscribe(ptu_topic, 1, &DataTracker::ptuCB, this);
00073 fob_sub = nh.subscribe(fob_topic, 1, &DataTracker::fobCB, this);
00074 cbd_sub = nh.subscribe(cbd_topic, 1, &DataTracker::cbdCB, this);
00075 data_counter = 0;
00076 boost::thread trackerThread(spin, this);
00077 ros::spin();
00078 }
00079 static void spin(DataTracker* obj){
00080 ROS_INFO("Capturing started.");
00081 ROS_INFO("Enter 'e' to stop capturing.");
00082 while (std::cin.get() != 'e'){
00083 obj->write();
00084 }
00085 ROS_INFO("Capturing stopped.");
00086 }
00087
00088
00089 void write(){
00090 std::stringstream ss;
00091 ss << pan << "; " << tilt << "; ";
00092 ss << fob_pose.position.x << "; " << fob_pose.position.y << "; " << fob_pose.position.z << "; ";
00093 ss << fob_pose.orientation.w << "; " << fob_pose.orientation.x << "; " << fob_pose.orientation.y << "; " << fob_pose.orientation.z << "; ";
00094 ss << cbd_pose.position.x << "; " << cbd_pose.position.y << "; " << cbd_pose.position.z << std::endl;
00095 ROS_INFO("%s", ss.str().c_str());
00096 std::ofstream dataFile;
00097 dataFile.open (output_file_path.c_str(),std::ios::app);
00098 dataFile << ss.str();
00099 dataFile.close();
00100 ROS_INFO("data captured %d", data_counter);
00101 data_counter++;
00102 }
00103
00104 };
00105
00106 int main(int argc, char** argv)
00107 {
00108 ros::init(argc, argv, "calibration_tracker");
00109
00110 ros::NodeHandle nh("~");
00111 new ::DataTracker(nh);
00112
00113
00114 return 0;
00115 }