Go to the documentation of this file.00001
00018 #include "CameraUtils/marker_manager.h"
00019 #include <QMetaType>
00020
00021 Marker_Manager::Marker_Manager(double timeout, double earlyabort_timeout, QObject *parent) :
00022 QThread(parent)
00023 {
00024 qRegisterMetaType<Eigen::Matrix4d>("Eigen::Matrix4d");
00025 qRegisterMetaType<std::string>("std::string");
00026 nh = ros::NodeHandle(ros::this_node::getName());
00027
00028 client_GetRecognizer = nh.serviceClient<asr_aruco_marker_recognition::GetRecognizer>("/asr_aruco_marker_recognition/get_recognizer");
00029 client_ReleaseRecognizer = nh.serviceClient<asr_aruco_marker_recognition::ReleaseRecognizer>("/asr_aruco_marker_recognition/release_recognizer");
00030
00031 this->timeout = timeout;
00032 this->earlyabort_timeout = earlyabort_timeout;
00033 ROS_INFO_STREAM("Marker Recognition: Timeout = " << timeout);
00034 ROS_INFO_STREAM("Marker Recognition: Early Abort = " << earlyabort_timeout);
00035 if (timeout-earlyabort_timeout <= 0.0)
00036 {
00037 ROS_ERROR("Marker Recognition: Early Abort was invalid");
00038 earlyabort_timeout = 0.0;
00039 }
00040 }
00041
00042 void Marker_Manager::run()
00043 {
00044 if (getRecognizer())
00045 {
00046
00047 recognizedMarker = false;
00048
00049 ros::Duration d = ros::Duration(earlyabort_timeout, 0);
00050 d.sleep();
00051
00052
00053 if (!recognizedMarker)
00054 {
00055 ROS_INFO("No Marker found -> Early abort.");
00056 markerFound("", Eigen::Matrix4d::Identity());
00057 releaseRecognizer();
00058
00059 }
00060 else
00061 {
00062 d = ros::Duration(timeout-earlyabort_timeout, 0);
00063 d.sleep();
00064
00065 markerFound("", Eigen::Matrix4d::Identity());
00066 releaseRecognizer();
00067 }
00068 }
00069 else
00070 {
00071 ROS_ERROR("Could not start recognition.");
00072 }
00073 }
00074
00075 void Marker_Manager::markerRecognitionCallback(const asr_msgs::AsrObject::ConstPtr object)
00076 {
00077 asr_msgs::AsrObject o = *object;
00078 recognizedMarker = true;
00079 std::string ID = o.type;
00080 Eigen::Affine3d transform;
00081 if(o.sampledPoses.size() > 0)
00082 {
00083 tf::poseMsgToEigen(o.sampledPoses.at(0).pose, transform);
00084 markerFound(ID, transform.matrix());
00085 }
00086 }
00087
00088 bool Marker_Manager::releaseRecognizer()
00089 {
00090 a.shutdown();
00091 asr_aruco_marker_recognition::ReleaseRecognizer release;
00092 return client_ReleaseRecognizer.call(release);
00093 }
00094
00095 bool Marker_Manager::getRecognizer()
00096 {
00097 a = nh.subscribe("/stereo/objects", 1000, &Marker_Manager::markerRecognitionCallback, this);
00098 asr_aruco_marker_recognition::GetRecognizer get;
00099 return client_GetRecognizer.call(get);
00100 }
00101
00102