1

I currently trying to setup the development environment in Visual studio for an extended kalman filter. I have installed all the required header files and libraries through vcpkg and also linked them in the properties in my solution in Visual studio project. I can successfully build my project in bash. But I am unable to build the same in Visual studio. I get the following three errors regarding uWebsockets:

  1. error C2664: 'void uWS::Group::onMessage(std::function<void (uWS::WebSocket,char *,size_t,uWS::OpCode)>)': cannot convert argument 1 from 'main::<lambda_bea007e7d222dc9b176de28a1ce05b5d>' to 'std::function<void (uWS::WebSocket,char *,size_t,uWS::OpCode)>'
  2. error C2664: 'void uWS::Group::onConnection(std::function<void (uWS::WebSocket,uWS::HttpRequest)>)': cannot convert argument 1 from 'main::<lambda_65b17263bf2521e013c9f6d82b42f5a6>' to 'std::function<void (uWS::WebSocket,uWS::HttpRequest)>'
  3. error C2664: 'void uWS::Group::onDisconnection(std::function<void (uWS::WebSocket,int,char *,size_t)>)': cannot convert argument 1 from 'main::<lambda_ab657350ab1a8d006c36b876f8906aac>' to 'std::function<void (uWS::WebSocket,int,char *,size_t)>'

The code for my main function is

#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, &tools, &estimations, &ground_truth]
              (uWS::WebSocket<uWS::SERVER> ws, char* data, size_t length,
               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(), msg.length(), uWS::OpCode::TEXT);
 #endif
        }  // end "telemetry" if

      } else {
        string msg = "42[\"manual\",{}]";
 #ifdef UWS_VCPKG
        ws->send(msg.data(), msg.length(), uWS::OpCode::TEXT);
 #else
        ws.send(msg.data(), msg.length(), 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, int code,
      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();

I am looking for a solution on why i am getting this error. I am passing the argument as a pointer which I believe is the correct format

Adarsh Raj
  • 11
  • 1
  • At first, I thought this was obvious - your lambda has a different signature than the parameter shown in the error message. So I cloned uWebSockets and did an exhaustive text search. Nowhere in source does onConnection have a parameter of the type Visual Studio seems to think it has. Your project might be picking up an incorrect version of the headers. Is it possible you have more than one installation? Have you checked your header search path in your project properties? I agree with you - the current library interfaces on GitHub should not be generating this error. – cycollins Mar 12 '21 at 05:49

0 Answers0