26 #include <mongo/client/dbclient.h> 28 #include <sensor_msgs/PointCloud.h> 32 #include <mongodb_store/util.h> 34 using namespace mongo;
47 static pthread_mutex_t
qsize_mutex = PTHREAD_MUTEX_INITIALIZER;
51 BSONObjBuilder document;
52 BSONObjBuilder transform;
55 const sensor_msgs::PointCloud& msg_in = *msg;
57 Date_t stamp = msg_in.header.stamp.sec * 1000.0 + msg_in.header.stamp.nsec / 1000000.0;
58 document.append(
"header", BSON(
"seq" << msg_in.header.seq
60 <<
"frame_id" << msg_in.header.frame_id));
62 BSONArrayBuilder pointb(document.subarrayStart(
"points"));
64 std::vector<geometry_msgs::Point32>::const_iterator p;
65 for (p = msg_in.points.begin(); p != msg_in.points.end(); ++p) {
66 pointb.append(BSON(
"x" << p->x
72 BSONArrayBuilder channelsb(document.subarrayStart(
"channels"));
75 std::vector<sensor_msgs::ChannelFloat32>::const_iterator c;
76 for (c = msg_in.channels.begin(); c != msg_in.channels.end(); ++c) {
77 cb.append(
"name", c->name);
79 BSONArrayBuilder valuesb(cb.subarrayStart(
"values"));
80 std::vector<float>::const_iterator v;
81 for (v = c->values.begin(); v != c->values.end(); ++v) {
86 channelsb.append(cb.obj());
90 mongodb_store::add_meta_for_msg<sensor_msgs::PointCloud>(msg, document);
106 unsigned int l_in_counter, l_out_counter, l_drop_counter, l_qsize;
124 printf(
"%u:%u:%u:%u\n", l_in_counter, l_out_counter, l_drop_counter, l_qsize);
132 std::string
topic =
"", mongodb =
"localhost", nodename =
"";
138 while ((c = getopt(argc, argv,
"t:m:n:c:")) != -1) {
139 if ((c ==
'?') || (c ==
':')) {
140 printf(
"Usage: %s -t topic -m mongodb -n nodename -c collection\n", argv[0]);
142 }
else if (c ==
't') {
144 }
else if (c ==
'm') {
146 }
else if (c ==
'n') {
148 }
else if (c ==
'c') {
154 printf(
"No topic given.\n");
156 }
else if (nodename ==
"") {
157 printf(
"No node name given.\n");
167 ROS_ERROR(
"Failed to connect to MongoDB: %s", errmsg.c_str());
void print_count(const ros::TimerEvent &te)
static pthread_mutex_t qsize_mutex
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
static pthread_mutex_t out_counter_mutex
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
DBClientConnection * mongodb_conn
int main(int argc, char **argv)
unsigned int drop_counter
ROSCPP_DECL void spin(Spinner &spinner)
static pthread_mutex_t in_counter_mutex
void msg_callback(const sensor_msgs::PointCloud::ConstPtr &msg)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
static pthread_mutex_t drop_counter_mutex