31 #include <tf/tfMessage.h> 35 #include <mongo/client/dbclient.h> 36 #include <mongodb_store/util.h> 39 using namespace mongo;
65 static pthread_mutex_t
qsize_mutex = PTHREAD_MUTEX_INITIALIZER;
74 string strMsgFrame = t->header.frame_id;
75 string strMsgChild = t->child_frame_id;
81 string strEntryFrame = (*itEntry).tsTransform.header.frame_id;
82 string strEntryChild = (*itEntry).tsTransform.child_frame_id;
85 if((strEntryFrame == strMsgFrame && strEntryChild == strMsgChild) ||
86 (strEntryFrame == strMsgChild && strEntryChild == strMsgFrame)) {
90 float fVectorialDistance = sqrt(((t->transform.translation.x - (*itEntry).tsTransform.transform.translation.x) *
91 (t->transform.translation.x - (*itEntry).tsTransform.transform.translation.x)) +
92 ((t->transform.translation.y - (*itEntry).tsTransform.transform.translation.y) *
93 (t->transform.translation.y - (*itEntry).tsTransform.transform.translation.y)) +
94 ((t->transform.translation.z - (*itEntry).tsTransform.transform.translation.z) *
95 (t->transform.translation.z - (*itEntry).tsTransform.transform.translation.z)));
97 tf::Quaternion q1(t->transform.rotation.x, t->transform.rotation.y, t->transform.rotation.z, t->transform.rotation.w);
99 (*itEntry).tsTransform.transform.rotation.y,
100 (*itEntry).tsTransform.transform.rotation.z,
101 (*itEntry).tsTransform.transform.rotation.w);
103 float fAngularDistance = 2.0 * fabs(q1.
angle(q2));
105 float fTimeDistance = (fabs((t->header.stamp.sec * 1000.0 + t->header.stamp.nsec / 1000000.0) -
106 ((*itEntry).tsTransform.header.stamp.sec * 1000.0 + (*itEntry).tsTransform.header.stamp.nsec / 1000000.0)) / 1000.0);
114 (*itEntry).tsTransform = *t;
134 std::vector<BSONObj> transforms;
136 const tf::tfMessage& msg_in = *msg;
137 bool bDidLogTransforms =
false;
139 std::vector<geometry_msgs::TransformStamped>::const_iterator t;
140 for (t = msg_in.transforms.begin(); t != msg_in.transforms.end(); ++t) {
142 bDidLogTransforms =
true;
144 Date_t stamp = t->header.stamp.sec * 1000.0 + t->header.stamp.nsec / 1000000.0;
146 BSONObjBuilder transform_stamped;
147 BSONObjBuilder transform;
148 transform_stamped.append(
"header", BSON(
"seq" << t->header.seq
150 <<
"frame_id" << t->header.frame_id));
151 transform_stamped.append(
"child_frame_id", t->child_frame_id);
152 transform.append(
"translation", BSON(
"x" << t->transform.translation.x
153 <<
"y" << t->transform.translation.y
154 <<
"z" << t->transform.translation.z));
155 transform.append(
"rotation", BSON(
"x" << t->transform.rotation.x
156 <<
"y" << t->transform.rotation.y
157 <<
"z" << t->transform.rotation.z
158 <<
"w" << t->transform.rotation.w));
159 transform_stamped.append(
"transform", transform.obj());
160 transforms.push_back(transform_stamped.obj());
164 if(bDidLogTransforms) {
166 "__recorded" << Date_t(time(NULL) * 1000) <<
167 "__topic" <<
topic));
181 unsigned int l_in_counter, l_out_counter, l_drop_counter, l_qsize;
199 printf(
"%u:%u:%u:%u\n", l_in_counter, l_out_counter, l_drop_counter, l_qsize);
203 int main(
int argc,
char **argv) {
204 std::string mongodb =
"localhost", nodename =
"";
219 while ((c = getopt(argc, argv,
"t:m:n:c:ak:l:g:")) != -1) {
220 if ((c ==
'?') || (c ==
':')) {
221 printf(
"Usage: %s -t topic -m mongodb -n nodename -c collection -k vectorial-threshold -l angular-threshold -g time-threshold -a\n", argv[0]);
223 }
else if (c ==
't') {
225 }
else if (c ==
'm') {
227 }
else if (c ==
'n') {
229 }
else if (c ==
'c') {
231 }
else if (c ==
'a') {
233 }
else if (c ==
'k') {
235 }
else if (c ==
'l') {
237 }
else if (c ==
'g') {
243 printf(
"No topic given.\n");
245 }
else if (nodename ==
"") {
246 printf(
"No node name given.\n");
256 ROS_ERROR(
"Failed to connect to MongoDB: %s", errmsg.c_str());
float fVectorialDistanceThreshold
list< PoseStampedMemoryEntry > lstPoseStampedMemory
unsigned int drop_counter
void print_count(const ros::TimerEvent &te)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
float fTimeDistanceThreshold
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static pthread_mutex_t out_counter_mutex
static pthread_mutex_t qsize_mutex
ROSCPP_DECL void spin(Spinner &spinner)
int main(int argc, char **argv)
tfScalar angle(const Quaternion &q) const
void msg_callback(const tf::tfMessage::ConstPtr &msg)
DBClientConnection * mongodb_conn
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
static pthread_mutex_t drop_counter_mutex
float fAngularDistanceThreshold
bool shouldLogTransform(std::vector< geometry_msgs::TransformStamped >::const_iterator t)
geometry_msgs::TransformStamped tsTransform
static pthread_mutex_t in_counter_mutex