Esempio n. 1
0
def api_manual_drive():
    """API that publishes control messages to control the angle and throttle in
       manual drive mode.

    Returns:
        dict: Execution status if the API call was successful.
    """
    webserver_node = webserver_publisher_node.get_webserver_node()
    angle = request.json.get("angle")
    throttle = request.json.get("throttle")
    max_speed = request.json.get("max_speed")

    if angle is None:
        return api_fail("angle is required")
    if throttle is None:
        return api_fail("throttle is required")
    if max_speed is None:
        return api_fail("max_speed is required")

    if angle < -1.0 or angle > 1.0:
        return api_fail("angle out of range")
    if throttle < -1.0 or throttle > 1.0:
        return api_fail("throttle out of range")

    webserver_node.get_logger().info(f"Angle: {angle}  Throttle: {throttle}")

    # Create the servo message.
    msg = ServoCtrlMsg()
    # bound the throttle value based on the categories defined
    msg.angle = -1.0 * get_categorized_manual_angle(angle)
    categorized_throttle = get_categorized_manual_throttle(throttle)
    msg.throttle = -1.0 * get_rescaled_manual_speed(categorized_throttle,
                                                    max_speed)
    webserver_node.pub_manual_drive.publish(msg)
    return jsonify({"success": True})
def api_adjust_calibrating_wheels(cali_type):
    """API to call the service to publishes a message withPWM measurement to adjust
       wheels while calibrating.

    Args:
        cali_type (int): Calibration type identifying steering/throttle calibration.

    Returns:
        dict: Execution status if the API call was successful.
    """
    webserver_node = webserver_publisher_node.get_webserver_node()
    form_data = request.json
    if cali_type == "angle":
        angle = float(
            int(form_data["pwm"]) * PWM_ANGLE_CONVERSION + PWM_OFFSET)
        throttle = -1.0
    else:
        angle = -1.0
        throttle = float(
            int(form_data["pwm"]) * PWM_THROTTLE_CONVERSION + PWM_OFFSET)
    webserver_node.get_logger().info(f"Angle: {angle}  Throttle: {throttle}")
    msg = ServoCtrlMsg()
    msg.angle = angle
    msg.throttle = throttle
    webserver_node.pub_calibration_drive.publish(msg)
    return jsonify({"success": True})
    def inference_cb(self, inference_msg):
        """Call back for whenever inference data is received.

        Args:
            inference_msg (InferResultsArray): Message containing all relevant inference data.
        """
        servo = ServoCtrlMsg()
        self.process_inference_data(inference_msg, servo)
        self.auto_drive_publisher.publish(servo)
    def __init__(self, qos_profile):
        """Create a DeepracerOffroadNavigationNode.
        """
        super().__init__('deepracer_offroad_navigation_node')
        self.get_logger().info("deepracer_offroad_navigation_node started.")
        self.current_waypoint = 0

        # Double buffer to hold the input deltas in x and y from qr_detection_node.
        self.delta_buffer = utils.DoubleBuffer(clear_data_on_get=True)

        # Create subscription to detection deltas from qr_detection_node.
        self.detection_delta_subscriber = \
            self.create_subscription(DetectionDeltaMsg,
                                     constants.QR_DETECTION_DELTA_TOPIC,
                                     self.detection_delta_cb,
                                     qos_profile)

        # Creating publisher to publish action (angle and throttle).
        self.action_publisher = self.create_publisher(ServoCtrlMsg,
                                                      constants.ACTION_PUBLISH_TOPIC,
                                                      qos_profile)

        # Service to dynamically set MAX_SPEED_PCT.
        self.set_max_speed_service = self.create_service(SetMaxSpeedSrv,
                                                         constants.SET_MAX_SPEED_SERVICE_NAME,
                                                         self.set_max_speed_cb)

        # Initializing the msg to be published.
        msg = ServoCtrlMsg()
        msg.angle, msg.throttle = constants.ActionValues.DEFAULT, constants.ActionValues.DEFAULT

        self.lock = threading.Lock()
        # Default maximum speed percentage (updated as per request using service call).
        self.max_speed_pct = constants.MAX_SPEED_PCT

        # Create a background servo publish thread.
        self.stop_thread = False
        self.thread_initialized = False
        self.thread = threading.Thread(target=self.action_publish, args=(msg,))
        self.thread.start()
        self.thread_initialized = True
        self.get_logger().info(f"Waiting for input delta: {constants.QR_DETECTION_DELTA_TOPIC}")
    def __init__(self, qos_profile):
        """Create a RCNavigationNode.
        """
        super().__init__('rc_navigation_node')
        self.get_logger().info("rc_navigation_node started.")

        # Double buffer to hold the mouse flag from Mouse Detection.
        self.mouse_buffer = utils.DoubleBuffer(clear_data_on_get=True)

        # Create subscription to detection mouse from mouse_detection_node.
        self.mouse_detection_subscriber = \
            self.create_subscription(MouseDetectionMsg,
                                     constants.MOUSE_DETECTION_TOPIC,
                                     self.mouse_detection_cb,
                                     qos_profile)

        # Creating publisher to publish action (angle and throttle).
        self.action_publisher = self.create_publisher(
            ServoCtrlMsg, constants.ACTION_PUBLISH_TOPIC, qos_profile)

        # Initializing the msg to be published.
        msg = ServoCtrlMsg()
        msg.angle, msg.throttle = constants.ActionValues.DEFAULT, constants.ActionValues.DEFAULT

        self.lock = threading.Lock()
        # Default maximum speed percentage (updated as per request using service call).
        self.max_speed_pct = constants.MAX_SPEED_PCT

        # Create a background servo publish thread.
        self.stop_thread = False
        self.thread_initialized = False
        self.thread = threading.Thread(target=self.action_publish,
                                       args=(msg, ))
        self.thread.start()
        self.thread_initialized = True
        self.get_logger().info(
            f"Waiting for input mouse flag: {constants.MOUSE_DETECTION_TOPIC}")