Skip to content

Commit 9d9c129

Browse files
committed
Database can now report collisions
1 parent 21e47ce commit 9d9c129

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

mocha_core/mocha_core/database.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class DBwLock():
8282
8383
sample_db may be a valid dictionary that can be preloaded into
8484
the object (useful for debugging, see sample_db.py) """
85-
def __init__(self, sample_db=None):
85+
def __init__(self, sample_db=None, ros_node=None):
8686
if sample_db is not None:
8787
assert isinstance(sample_db, dict)
8888
# For ROS2, we can't deepcopy Time objects, so we'll just assign directly
@@ -92,6 +92,7 @@ def __init__(self, sample_db=None):
9292
else:
9393
self.db = {}
9494
self.lock = threading.Lock()
95+
self.ros_node = ros_node
9596

9697
def add_modify_data(self, dbm):
9798
""" Insert new stuff into the db. Use the header as message index """
@@ -106,7 +107,10 @@ def add_modify_data(self, dbm):
106107
if dbm.topic_id not in self.db[dbm.robot_id]:
107108
self.db[dbm.robot_id][dbm.topic_id] = {}
108109
if dbm.header in self.db[dbm.robot_id][dbm.topic_id]:
109-
raise Exception("database: Header Collision Detected")
110+
if self.ros_node is not None:
111+
self.ros_node.get_logger().error("Database - Header Collision Detected. " + "You may want to decrease your publish rate into MOCHA")
112+
else:
113+
raise Exception("database: Header Collision Detected")
110114
self.db[dbm.robot_id][dbm.topic_id][dbm.header] = dbm
111115
self.lock.release()
112116
return dbm.header

mocha_core/mocha_core/database_server.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, robot_configs, topic_configs, robot_name, ros_node):
5353
self.topic_list = self.topic_configs[self.robot_configs[self.robot_name]["node-type"]]
5454

5555
# Create the empty database with lock
56-
self.dbl = database.DBwLock()
56+
self.dbl = database.DBwLock(ros_node=self.ros_node)
5757

5858
# Get current robot number
5959
self.robot_number = du.get_robot_id_from_name(self.robot_configs,
@@ -137,9 +137,6 @@ def get_data_hash_db_service_cb(self, req, response):
137137
def select_db_service_cb(self, req, response):
138138
# TODO Implement filtering
139139

140-
# Note: robot_id and topic_id are uint8 in ROS2, so they can't be None
141-
# We can add range validation if needed, but for now just proceed
142-
143140
list_headers = self.dbl.get_header_list(req.robot_id)
144141

145142
response.headers = du.serialize_headers(list_headers)

0 commit comments

Comments
 (0)