John Collins

John Collins

Developer

© 2024

Introducing Clojure Rosbag

I wrote a simple ROS bag reader for Clojure/Clojurescript. This is the first post in a series about robotics tools and algorithms for clojure. ROS is a defacto standard message format for robot data that is widly used in the industry. It has many issues (which I will conver in another post), but if you want to do anything with robot data in today’s ecosystem you’ll need to be able to read what we call ROS bags.

This library is built on top of a currently forked version of the Java Bag Reader. It provides a user-friendly API that is similar to the Python rosbag API.

(import '[java.io File])
(require '[clj-rosbag.core :as rosbag])
(def bag-file (File. "resources/Float32.bag"))
;; Note, open can take a path to a bag file, or a byte array.
(def bag (rosbag/open (.getPath bag-file)))

;; Returns a lazy sequence of messages on topic "/data".
(def messages (rosbag/read-messages bag ["/data"]))
messages
;; ({:topic "/data",
;;   :message {:data 3.14159},
;;   :time #inst "2017-08-30T05:00:39.005849329-00:00"})

Currently it’s in early alpha. There’s a fair amount that could be done to improve performance (such as dyanamically compiling connection records as they are read). It also contains a pre-compiled jar of the java bag reader, which is much less than ideal. Nevertheless, it does provide a clean API for handling ROS bags from clojure.

It’s worth noting that there serveral repositories available that provide free ROS data collected in real-world environments. For example, checkout the self-driving car dataset provided by Udacity.