===== Logging turtlesim data ===== This is a simple example to show logging of pose and velocity information from running the ''turtlesim'' node. ==== Logging the data ==== Start the turtlesim and log all the topics using the following sets of commands rosrun turtlesim turtlesim_node rosrun turtlesim turtle_teleop_key # for keyboard teleop to get changing data rosrun mongodb_log mongodb_log -a # for all topics. check help for more options # use Ctrl + C to stop ==== Accessing the data ==== The data that has been logged can be accessed via may ways, directly using terminal mongo client or via the language APIs. These are each shown below; === Via the mongo terminal client === This is installed when you get the mongodb package installed on the system. mongo # alternatively, use the ros version with rosrun mongodb mongo # you should see an interface like the following MongoDB shell version: 2.0.4 connecting to: test # change to the ros database using > use roslog switched to roslog # see a list of databases using > show dbs local (empty) roslog 0.203125GB # see the list of items stored using the following > db.getCollectionNames() [ "system.indexes", "turtle1_color_sensor", "turtle1_command_velocity", "turtle1_pose" ] # further commands are given in standard mongo cheatsheets > === Via a python API === The full documentation of the python API is available online at [[http://api.mongodb.org/python/current/|http://api.mongodb.org/python/current/]]. Below is a simple example usage: import pymongo mclient = pymongo.Connection() db = mclient['roslog'] # get the collections db.collection_names() [u'turtle1_color_sensor', u'system.indexes', u'turtle1_pose', u'turtle1_ command_velocity'] # show all the data in the database docs = db['turtle1_pose'].find() for d in docs: print d # this displays a long list with elements like these {u'__topic': u'/turtle1/pose', u'linear_velocity': 0.0, u'theta': 1.9824 440479278564, u'y': 8.26992130279541, u'x': 4.029432773590088, u'_id': O bjectId('51c98fcca6c646570b000901'), u'angular_velocity': 0.0, u'__recor ded': 1372164044.44448} {u'__topic': u'/turtle1/pose', u'linear_velocity': 0.0, u'theta': 1.9824 440479278564, u'y': 8.26992130279541, u'x': 4.029432773590088, u'_id': O bjectId('51c98fcca6c646570b000902'), u'angular_velocity': 0.0, u'__recor ded': 1372164044.460494} # querying can be done directly on these. e.g. q = db['turtle1_pose'].find({'__recorded':{'$gt' : 1372164044.44448}}) q.count() 1 # which is exactly the last recording as shown in the data snippet above