def parse_qr_json()

in deepracer_offroad_ws/qr_detection_pkg/qr_detection_pkg/qr_detection_node.py [0:0]


    def parse_qr_json(self, qrcode_info):
        """Method that parses the QR info and returns the
        JSON dictionary.

        Args:
            qrcode_info (String): Decoded String for QR Code.

        Returns:
            qr_json_detected (Dictionary): JSON Dictionary with encoded data in QR Code

        """
        qr_json_detected = json.loads(qrcode_info.split(constants.QRKeys.DEEPRACER)[1].strip())
        self.get_logger().debug(f"JSON Detected {qr_json_detected}")
        # Check if the QR Code has specific action encoded in "type"
        # and add it to waypoint_type.
        if constants.QRKeys.TYPE in qr_json_detected:
            waypoint_type = qr_json_detected[constants.QRKeys.TYPE]
            # Check if detected QR has a new action delta encoded
            # which will set the ongoing_action.
            if waypoint_type == constants.QRValues.ACTION_START:
                # Get the encoded delta values for the specific action start
                valid_detection_delta = DetectionDeltaMsg()
                valid_detection_delta.delta = qr_json_detected[constants.QRKeys.DELTA]
                # Set the ongoing action delta to detected action delta
                self.ongoing_action = valid_detection_delta
                # Check if a limit is encoded in QR code along with the action delta
                # which decides the number of frames the action delta to be published.
                if constants.QRKeys.LIMIT in qr_json_detected:
                    # Set the limit value to encoded limit value
                    self.limit = qr_json_detected[constants.QRKeys.LIMIT]
                else:
                    # Set the limit value to infinite if no limit value is encoded
                    # ie; keep running the action until we see an action_stop QR
                    self.limit = float('inf')
            elif waypoint_type == constants.QRValues.ACTION_STOP:
                # Clear the ongoing_action and set it to valid_detection_delta (None)
                valid_detection_delta = None
                self.ongoing_action = valid_detection_delta

        return qr_json_detected