void CalibrationCtrl::setCalibration()

in deepracer_offroad_ws/ctrl_pkg/src/ctrl_state.cpp [521:548]


    void CalibrationCtrl::setCalibration(int type, const std::vector<int> &cal) {
        if (cal.size() != ServoCalType::total) {
            RCLCPP_ERROR(ctrlNode->get_logger(), "Invalid calibration vector");
            return;
        }
        if (cal[ServoCalType::max] == cal[ServoCalType::min]
            || cal[ServoCalType::max] == cal[ServoCalType::mid]
            || cal[ServoCalType::min] == cal[ServoCalType::mid]
            || std::max(cal[ServoCalType::max], cal[ServoCalType::min]) != cal[ServoCalType::max]
            || std::max(cal[ServoCalType::max], cal[ServoCalType::mid]) != cal[ServoCalType::max]
            || std::max(cal[ServoCalType::min], cal[ServoCalType::mid]) != cal[ServoCalType::mid]) {
            RCLCPP_ERROR(ctrlNode->get_logger(), "Invalid calibration values");
            return;
        }
        auto srvRequest = std::make_shared<deepracer_interfaces_pkg::srv::SetCalibrationSrv::Request>();
        srvRequest->cal_type = type;
        srvRequest->max = cal[ServoCalType::max];
        srvRequest->mid = cal[ServoCalType::mid];
        srvRequest->min = cal[ServoCalType::min];
        srvRequest->polarity = cal[ServoCalType::polarity];
        auto future_result = servoSetCalClient_->async_send_request(srvRequest);
        future_result.wait();

        auto srvResponse = future_result.get();
        if(srvResponse->error != 0){
            RCLCPP_ERROR(ctrlNode->get_logger(), "Setting calibration failed.");
        }
    }