Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/ros/Utils/RosbagSubscriber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ mutable struct RosbagSubscriber
syncBuffer::Dict{Symbol,Tuple{DateTime, Int}} # t,ns,msgdata
nextMsgChl::Symbol
nextMsgTimestamp::Tuple{DateTime, Int}
compression::Any
# constructors
end
RosbagSubscriber(bagfile::AbstractString;
compression=nothing,
channels::Vector{Symbol}=Symbol[],
callbacks::Dict{Symbol,Function}=Dict{Symbol,Function}(),
readers::Dict{Symbol,PyObject}=Dict{Symbol,PyObject}(),
syncBuffer::Dict{Symbol,Tuple{DateTime, Int}}=Dict{Symbol,Tuple{DateTime, Int}}() ) = RosbagSubscriber(bagfile,channels,callbacks,readers,syncBuffer, :null, (unix2datetime(0),0))
syncBuffer::Dict{Symbol,Tuple{DateTime, Int}}=Dict{Symbol,Tuple{DateTime, Int}}() ) = RosbagSubscriber(bagfile,channels,callbacks,readers,syncBuffer, :null, (unix2datetime(0),0),compression)
#

# loss of accuracy (Julia only Millisecond)
Expand Down Expand Up @@ -97,8 +99,8 @@ function loop!(rbs::RosbagSubscriber, args...)
rbs.callbacks[rbs.nextMsgChl](msg, args...)
true
else
println("false, dont know how to handle message time as typeof(msgT)=$(typeof(msgT))")
@show msg
@warn "Unsure about decoding this topic:msg type pair, make sure the subscribed topic names are spelled exactly right." rbs.nextMsgChl msgT maxlog=10
# @show msg
false
end
end
Expand All @@ -114,5 +116,5 @@ function (rbs::RosbagSubscriber)( chl::AbstractString,
# include the type converter, see ref: https://github.com/jdlangs/RobotOS.jl/blob/21a7088461a21bc9b24cd2763254d5043d5b1800/src/callbacks.jl#L23
rbs.callbacks[cn] = (m)->callback(convert(MT,m[2]),args...)
rbs.syncBuffer[cn] = (unix2datetime(0), 0)
rbs.readers[cn] = RosbagParser(rbs.bagfile, chl)
rbs.readers[cn] = RosbagParser(rbs.bagfile, chl) #; rbs.compression)
end
4 changes: 2 additions & 2 deletions src/ros/Utils/rosbagReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import sys

class RosbagParser:
def __init__(self, bag_file_name, topic_name):
def __init__(self, bag_file_name, topic_name): #, compression=None):
#bag_file_name = sys.argv[1]
#topic_name = sys.argv[2]

self.bag = rosbag.Bag(bag_file_name)
self.bag = rosbag.Bag(bag_file_name, 'r') #, compression=compression)
self.bag_contents = self.bag.read_messages(topics=[topic_name])

self.idx = 0
Expand Down