Skip to content

Instantly share code, notes, and snippets.

@ibraEssam
Created June 3, 2020 18:28
Show Gist options
  • Select an option

  • Save ibraEssam/d4c463365996ee14d07fad4bcb3ff95a to your computer and use it in GitHub Desktop.

Select an option

Save ibraEssam/d4c463365996ee14d07fad4bcb3ff95a to your computer and use it in GitHub Desktop.
def on_new_messages(self, messages):
''' [Optional] Called according to the execution mode of the block.
Parameters
----------
messages : dict
A dictionary of the port keys and the values of the incoming messages.
'''
bboxes = messages['bboxes'].bboxes #Bounding boxes
if(self.braked): # check if brake is already applied
if(time.time() - self.last_time >= self.get_property("time_limt")): # wait x minutes before releasing the brake
self.braked = False
print("realeasing the brake")
msg = Bool()
msg.data = False
self.publish("brake_sign", msg)
self.last_time = time.time()
else:
for bbox in bboxes: # cechk every boundig box
print("Width: "+str(bbox.width)+" X: "+str(bbox.x))
if(bbox.width >= self.box_w and bbox.x <= self.box_x_lim): # if the box width > the threshold and in the right location
print("Braking")
msg = Bool()
msg.data = True
self.publish("brake_sign", msg)
self.braked = True
self.last_time = time.time()
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment