Created
June 3, 2020 18:28
-
-
Save ibraEssam/d4c463365996ee14d07fad4bcb3ff95a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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