5 import os, bson, datetime
6 from tf.transformations
import euler_from_quaternion
16 def compare_dict(dict1, dict2)->bool:
18 if len(dict1) != len(dict2):
21 for key, value
in dict1.items():
25 if isinstance(value, dict)
and isinstance(dict2[key], dict):
26 if not compare_dict(value, dict2[key]):
28 elif dict2[key] != value:
32 def writeBfile(data, path):
33 file = open(file=path, mode=
'bw+')
34 file.write(bson.encode(document=data))
41 filePath = PATH + str(topic[
'topic'].replace(
'/',
'') +
'.tjson')
43 if not os.path.exists(path=PATH):
45 os.makedirs(name=PATH)
47 if not os.path.exists(path=filePath):
48 file = open(file=filePath, mode=
'bw+')
50 file = open(file=filePath, mode=
'br+')
58 _file = bson.BSON.decode(_file)
59 except bson.errors.InvalidBSON:
60 writeBfile(data=_data, path=filePath)
63 if compare_dict(_data, _file):
66 writeBfile(data=_data, path=filePath)
69 writeBfile(data=_data, path=filePath)
74 def q2e(data, topic) -> None:
76 orientation = data[
'pose'][
'pose'][
'orientation']
78 (raw, pitch, yaw) = euler_from_quaternion([orientation[
'x'], orientation[
'y'], orientation[
'z'], orientation[
'w']])
86 data.update({
'pose': {
'pose': {
'position': data[
'pose'][
'pose'][
'position'],
'orientation': orientation}}})