00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include "rtt_tf-component.hpp"
00049 #include <rtt/Component.hpp>
00050
00051 namespace rtt_tf
00052 {
00053
00054 using namespace RTT;
00055 using namespace tf;
00056
00057 RTT_TF::RTT_TF(const string& name) :
00058 TaskContext(name, PreOperational), prop_interpolating(true),
00059 prop_cache_time(Transformer::DEFAULT_CACHE_TIME), prop_buffer_size(
00060 DEFAULT_BUFFER_SIZE)
00061 {
00062 this->addProperty("interpolating", prop_interpolating);
00063 this->addProperty("cache_time", prop_cache_time);
00064 this->addProperty("buffer_size", prop_buffer_size);
00065 this->addEventPort("tf_in", port_tf_in);
00066
00067 this->addOperation("lookupTransform", &RTT_TF::lookupTransform, this).doc(
00068 "lookup the most recent transform from source to target").arg(
00069 "target", "target frame").arg("source", "source frame");
00070
00071 }
00072
00073 bool RTT_TF::configureHook()
00074 {
00075
00076 m_transformer.reset(new Transformer(prop_interpolating, ros::Duration(
00077 prop_cache_time)));
00078
00079 ConnPolicy cp = ConnPolicy::buffer(prop_buffer_size);
00080 cp.transport = 3;
00081 cp.name_id = "/tf";
00082
00083 return port_tf_in.createStream(cp);
00084 }
00085
00086 void RTT_TF::updateHook()
00087 {
00088 Logger::In(this->getName());
00089 #ifndef NDEBUG
00090 log(Debug) << "In update" << endlog();
00091 #endif
00092 try
00093 {
00094 tf::tfMessage msg_in;
00095 while (port_tf_in.read(msg_in) == NewData)
00096 {
00097 for (unsigned int i = 0; i < msg_in.transforms.size(); i++)
00098 {
00099 StampedTransform trans;
00100 transformStampedMsgToTF(msg_in.transforms[i], trans);
00101 try
00102 {
00103 std::map<std::string, std::string>* msg_header_map =
00104 msg_in.__connection_header.get();
00105 std::string authority;
00106 std::map<std::string, std::string>::iterator it =
00107 msg_header_map->find("callerid");
00108 if (it == msg_header_map->end())
00109 {
00110 log(Warning) << "Message received without callerid"
00111 << endlog();
00112 authority = "no callerid";
00113 }
00114 else
00115 {
00116 authority = it->second;
00117 }
00118 m_transformer->setTransform(trans, authority);
00119 } catch (TransformException& ex)
00120 {
00121
00122 log(Error) << "Failure to set received transform from "
00123 << msg_in.transforms[i].child_frame_id << " to "
00124 << msg_in.transforms[i].header.frame_id
00125 << " with error: " << ex.what() << endlog();
00126 }
00127 }
00128 }
00129
00130 } catch (std::exception& ex)
00131 {
00132 log(Error) << ex.what() << endlog();
00133 }
00134 }
00135
00136 geometry_msgs::TransformStamped RTT_TF::lookupTransform(const std::string& target,
00137 const std::string& source)
00138 {
00139 tf::StampedTransform stamped_tf;
00140 ros::Time common_time;
00141 m_transformer->getLatestCommonTime(source, target, common_time,NULL);
00142 m_transformer->lookupTransform(target, source, common_time, stamped_tf);
00143 geometry_msgs::TransformStamped msg;
00144 tf::transformStampedTFToMsg(stamped_tf,msg);
00145 return msg;
00146 }
00147
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 ORO_CREATE_COMPONENT(rtt_tf::RTT_TF)