def api_set_calibration()

in deepracer_follow_the_leader_ws/webserver_pkg/webserver_pkg/calibration.py [0:0]


def api_set_calibration(cali_type):
    """API to call the service to store the calibration to file and
       set the current calibration.

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

    Returns:
        dict: Execution status if the API call was successful.
    """
    data = request.json
    webserver_node = webserver_publisher_node.get_webserver_node()
    webserver_node.get_logger().info(f"set_calibration: {data}")
    state = 0 if cali_type == "angle" else 1
    conversion = PWM_ANGLE_CONVERSION if state == 0 else PWM_THROTTLE_CONVERSION
    set_mid = int(data["mid"]) * conversion + PWM_OFFSET
    set_min = int(data["min"]) * conversion + PWM_OFFSET
    set_max = int(data["max"]) * conversion + PWM_OFFSET
    set_polarity = int(data["polarity"])
    webserver_node.get_logger().info(f"State: {state} "
                                     f"mid: {set_mid} "
                                     f"min: {set_min} "
                                     f"max: {set_max} "
                                     f"polarity: {set_polarity}")
    try:
        set_cal_req = SetCalibrationSrv.Request()
        set_cal_req.cal_type = state
        set_cal_req.min = set_min
        set_cal_req.max = set_max
        set_cal_req.mid = set_mid
        set_cal_req.polarity = set_polarity
        set_cal_res = call_service_sync(webserver_node.set_cal_cli, set_cal_req)
        if set_cal_res and set_cal_res.error == 0:
            return jsonify({"success": True})
        else:
            return jsonify({"success": False})
    except Exception as ex:
        webserver_node.get_logger().error(f"Unable to reach set vehicle calibration server: {ex}")
        return api_fail("Unable to reach set vehicle calibration")