def plan_action()

in deepracer_offroad_ws/deepracer_offroad_navigation_pkg/deepracer_offroad_navigation_pkg/deepracer_offroad_navigation_node.py [0:0]


    def plan_action(self, delta):
        """Helper method to calculate action to be undertaken from the detection delta
           received from qr_detection_node. This has been modified from the
           Follow the Leader Navigation Node in Follow the Leader sample project to provide
           more action brackets for Left/Right movement based on the detection deltas.
           Follow the Leader sample project:
           https://github.com/aws-deepracer/aws-deepracer-follow-the-leader-sample-project
           Also the action space for reverse has been removed since its no longer required
           for the DeepRacer Off-road sample project.

        Args:
        delta (list of floats): detection deltas in x and y axes respectively.

        Returns:
        (tuple of floats): Action Space Configuration defined in constants.py
        """
        delta_x = delta[0]
        delta_y = delta[1]

        if delta_y < constants.DeltaValueMap.FORWARD_DELTA_Y:
            # Forward Bracket
            if delta_x < constants.DeltaValueMap.FORWARD_LEFT_DELTA_X \
                    and delta_x > constants.DeltaValueMap.FORWARD_MID_LEFT_DELTA_X:
                # Min Left
                self.get_logger().info("MIN_LEFT_FORWARD")
                return constants.ActionSpaceConfig.MIN_LEFT_FORWARD
            elif delta_x <= constants.DeltaValueMap.FORWARD_MID_LEFT_DELTA_X \
                    and delta_x > constants.DeltaValueMap.FORWARD_MAX_LEFT_DELTA_X:
                # Mid Left
                self.get_logger().info("MID_LEFT_FORWARD")
                return constants.ActionSpaceConfig.MID_LEFT_FORWARD
            elif delta_x <= constants.DeltaValueMap.FORWARD_MAX_LEFT_DELTA_X:
                # Max Left
                self.get_logger().info("MAX_LEFT_FORWARD")
                return constants.ActionSpaceConfig.MAX_LEFT_FORWARD
            elif delta_x > constants.DeltaValueMap.FORWARD_RIGHT_DELTA_X \
                    and delta_x < constants.DeltaValueMap.FORWARD_MID_RIGHT_DELTA_X:
                # Min Right
                self.get_logger().info("MIN_RIGHT_FORWARD")
                return constants.ActionSpaceConfig.MIN_RIGHT_FORWARD
            elif delta_x >= constants.DeltaValueMap.FORWARD_MID_RIGHT_DELTA_X \
                    and delta_x < constants.DeltaValueMap.FORWARD_MAX_RIGHT_DELTA_X:
                # Mid Right
                self.get_logger().info("MID_RIGHT_FORWARD")
                return constants.ActionSpaceConfig.MID_RIGHT_FORWARD
            elif delta_x >= constants.DeltaValueMap.FORWARD_MAX_RIGHT_DELTA_X:
                # Max Right
                self.get_logger().info("MAX_RIGHT_FORWARD")
                return constants.ActionSpaceConfig.MAX_RIGHT_FORWARD
            else:
                # No steering
                self.get_logger().info("FORWARD")
                return constants.ActionSpaceConfig.FORWARD

        else:
            # No Action
            self.get_logger().info("NO_ACTION")
            return constants.ActionSpaceConfig.NO_ACTION