Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected INDEX_DATA record #2347

Open
Hypothesis-Z opened this issue Sep 11, 2023 · 0 comments
Open

Expected INDEX_DATA record #2347

Hypothesis-Z opened this issue Sep 11, 2023 · 0 comments

Comments

@Hypothesis-Z
Copy link

Given a segment number, I tried to split a ros bag into segments by running the following code:

class CommandSplit:
    def __init__(self, args):
        self.filename = args.filename
        self.output = args.output
        if self.output == None:
            self.output = self.get_defalut_output()
        self.number = args.number

    def get_defalut_output(self):
        t_str = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())
        return os.path.splitext(self.filename)[0] + '_bagtools_' + t_str + '.bag'

    def run(self):
        self.bag = rosbag.Bag(self.filename)
        linspace = np.linspace(self.bag.get_start_time(), self.bag.get_end_time(), self.number+1)
        i = 0
        digit = len(str(self.number))
        outbag_filename = f'{os.path.splitext(self.output)[0]}_{i+1:0{digit}d}.bag'
        self.outbag = rosbag.Bag(outbag_filename, "w")
        print(f"writing file [{i+1}/{self.number}]: {outbag_filename}")

        for topic, raw_msg, t, conn_header in self.bag.read_messages(raw=True, return_connection_header=True):
            if i + 1 < len(linspace)-1 and t >= rospy.Time.from_sec(linspace[i+1]):
                i += 1
                self.outbag.close()
                outbag_filename = f'{os.path.splitext(self.output)[0]}_{i+1:0{digit}d}.bag'
                self.outbag = rosbag.Bag(outbag_filename, "w")
                print(f"writing file [{i+1}/{self.number}]: {outbag_filename}")
            msg_type, serialized_bytes, md5sum, pos, pytype = raw_msg
            msg = pytype()
            msg.deserialize(serialized_bytes)
            self.outbag.write(topic, msg, t, connection_header=conn_header)
            self.outbag.flush()
        
        self.outbag.close()

I got error when playing these segments:

zzq@DESKTOP:~/data/zhejianglab_evaluation$ rosbag play zjlab_EC_14_rgbdliou_bagtools_2023-09-11-15-04-37_00*.bag --clock
[ INFO] [1694420036.314181310]: Opening zjlab_EC_14_rgbdliou_bagtools_2023-09-11-15-04-37_001.bag
[ INFO] [1694420036.548806657]: Opening zjlab_EC_14_rgbdliou_bagtools_2023-09-11-15-04-37_002.bag
[ INFO] [1694420036.760476766]: Opening zjlab_EC_14_rgbdliou_bagtools_2023-09-11-15-04-37_003.bag
[FATAL] [1694420036.801129445]: Expected INDEX_DATA record

Some of them are corrupted but rosbag reindex dosn't work.
need help...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant