微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

uwebsockets编译错误Visual Studio 2019

如何解决uwebsockets编译错误Visual Studio 2019

我目前正在尝试在Visual Studio中为扩展的卡尔曼滤波器设置开发环境。我已经通过vcpkg安装了所有必需的头文件和库,并将它们链接到Visual Studio项目中我的解决方案的属性中。我可以在bash中成功构建项目。但是我无法在Visual Studio中构建相同的对象。关于uWebsockets,我收到以下三个错误

  1. 错误C2664:'void uWS :: Group :: onMessage(std :: function )':无法将参数1从'main: :'到'std :: function '
  2. 错误C2664:'void uWS :: Group :: onConnection(std :: function )':无法从'main :: '转换参数1到'std :: function '
  3. 错误C2664:'void uWS :: Group :: ondisconnection(std :: function )':无法将参数1从'main :: '到'std :: function '

我主要功能代码

#include <math.h>
#include <uWS/uWS.h>
#include <iostream>
#include "json.hpp"
#include "FusionEKF.h"
#include "tools.h"

using Eigen::MatrixXd;
using Eigen::VectorXd;
using std::string;
using std::vector;

// for convenience
using json = nlohmann::json;

// Checks if the SocketIO event has JSON data.
// If there is data the JSON object in string format will be returned,// else the empty string "" will be returned.
string hasData(string s) {
  auto found_null = s.find("null");
  auto b1 = s.find_first_of("[");
  auto b2 = s.find_first_of("]");
  if (found_null != string::npos) {
    return "";
  }
  else if (b1 != string::npos && b2 != string::npos) {
    return s.substr(b1,b2 - b1 + 1);
  }
  return "";
}

int main() {
  uWS::Hub h;

  // Create a Kalman Filter instance
  FusionEKF fusionEKF;

  // used to compute the RMSE later
  Tools tools;
  vector<VectorXd> estimations;
  vector<VectorXd> ground_truth;
  
  #ifdef UWS_VCPKG
    h.onMessage([&fusionEKF,&tools,&estimations,&ground_truth]
              (uWS::WebSocket<uWS::SERVER> *ws,char *data,size_t length,uWS::OpCode opCode) {
  #else
    h.onMessage([&fusionEKF,&ground_truth]
              (uWS::WebSocket<uWS::SERVER> ws,char* data,uWS::OpCode opCode) {
  #endif
    // "42" at the start of the message means there's a websocket message event.
    // The 4 signifies a websocket message
    // The 2 signifies a websocket event
    if (length && length > 2 && data[0] == '4' && data[1] == '2') {
      auto s = hasData(string(data));

      if (s != "") {
        auto j = json::parse(s);

        string event = j[0].get<string>();
        
        if (event == "telemetry") {
          // j[1] is the data JSON object
          string sensor_measurement = j[1]["sensor_measurement"];
          
          MeasurementPackage meas_package;
          std::istringstream iss(sensor_measurement);
          
          long long timestamp;

          // reads first element from the current line
          string sensor_type;
          iss >> sensor_type;

          if (sensor_type.compare("L") == 0) {
            meas_package.sensor_type_ = MeasurementPackage::LASER;
            meas_package.raw_measurements_ = VectorXd(2);
            float px;
            float py;
            iss >> px;
            iss >> py;
            meas_package.raw_measurements_ << px,py;
            iss >> timestamp;
            meas_package.timestamp_ = timestamp;
          } else if (sensor_type.compare("R") == 0) {
            meas_package.sensor_type_ = MeasurementPackage::RADAR;
            meas_package.raw_measurements_ = VectorXd(3);
            float ro;
            float theta;
            float ro_dot;
            iss >> ro;
            iss >> theta;
            iss >> ro_dot;
            meas_package.raw_measurements_ << ro,theta,ro_dot;
            iss >> timestamp;
            meas_package.timestamp_ = timestamp;
          }

          float x_gt;
          float y_gt;
          float vx_gt;
          float vy_gt;
          iss >> x_gt;
          iss >> y_gt;
          iss >> vx_gt;
          iss >> vy_gt;

          VectorXd gt_values(4);
          gt_values(0) = x_gt;
          gt_values(1) = y_gt; 
          gt_values(2) = vx_gt;
          gt_values(3) = vy_gt;
          ground_truth.push_back(gt_values);
          
          // Call ProcessMeasurement(meas_package) for Kalman filter
          fusionEKF.ProcessMeasurement(meas_package);       

          // Push the current estimated x,y positon from the Kalman filter's 
          //   state vector

          VectorXd estimate(4);

          double p_x = fusionEKF.ekf_.x_(0);
          double p_y = fusionEKF.ekf_.x_(1);
          double v1  = fusionEKF.ekf_.x_(2);
          double v2 = fusionEKF.ekf_.x_(3);

          estimate(0) = p_x;
          estimate(1) = p_y;
          estimate(2) = v1;
          estimate(3) = v2;
        
          estimations.push_back(estimate);

          VectorXd RMSE = tools.CalculateRMSE(estimations,ground_truth);

          json msgJson;
          msgJson["estimate_x"] = p_x;
          msgJson["estimate_y"] = p_y;
          msgJson["rmse_x"] =  RMSE(0);
          msgJson["rmse_y"] =  RMSE(1);
          msgJson["rmse_vx"] = RMSE(2);
          msgJson["rmse_vy"] = RMSE(3);
          auto msg = "42[\"estimate_marker\"," + msgJson.dump() + "]";
          // std::cout << msg << std::endl;
 #ifdef UWS_VCPKG
          ws->send(msg.data(),msg.length(),uWS::OpCode::TEXT);
 #else
          ws.send(msg.data(),uWS::OpCode::TEXT);
 #endif
        }  // end "telemetry" if

      } else {
        string msg = "42[\"manual\",{}]";
 #ifdef UWS_VCPKG
        ws->send(msg.data(),uWS::OpCode::TEXT);
 #else
        ws.send(msg.data(),uWS::OpCode::TEXT);
 #endif
      }
    }  // end websocket message if

  }); // end h.onMessage
 
 #ifdef UWS_VCPKG
  h.onConnection([&h](uWS::WebSocket<uWS::SERVER> *ws,uWS::HttpRequest req) {
    std::cout << "Connected!!!" << std::endl;
  });
 #else
  h.onConnection([&h](uWS::WebSocket<uWS::SERVER> ws,uWS::HttpRequest req) {
      std::cout << "Connected!!!" << std::endl;
      });
 #endif

 #ifdef UWS_VCPKG
  h.ondisconnection([&h](uWS::WebSocket<uWS::SERVER> *ws,int code,char *message,size_t length) {
    ws->close();
    std::cout << "disconnected" << std::endl;
  });
 #else
  h.ondisconnection([&h](uWS::WebSocket<uWS::SERVER> ws,char* message,size_t length) {
          ws.close();
          std::cout << "disconnected" << std::endl;
      });
 #endif

  int port = 4567;
  if (h.listen("127.0.0.1",port)) {
    std::cout << "Listening to port " << port << std::endl;
  } else {
    std::cerr << "Failed to listen to port" << std::endl;
    return -1;
  }
  
  h.run();

我正在寻找有关解决错误的原因的解决方案。我将参数作为指针传递,我认为这是正确的格式

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。