我目前正在尝试在 Visual Studio 中为扩展卡尔曼滤波器设置开发环境。我已经通过 vcpkg 安装了所有必需的头文件和库,并将它们链接到我在 Visual Studio 项目中的解决方案的属性中。我可以在 bash 中成功构建我的项目。但我无法在 Visual Studio 中构建相同的内容。我收到以下三个关于 uWebsockets 的错误:
- 错误 C2664: 'void uWS::Group::onMessage(std::function<void (uWS::WebSocket,char *,size_t,uWS::OpCode)>)': 无法从 'main::<lambda_bea007e7d222dc9b176de28a1ce05b5d 转换参数 1 >' 到 'std::function<void (uWS::WebSocket,char *,size_t,uWS::OpCode)>'
- 错误 C2664: 'void uWS::Group::onConnection(std::function<void (uWS::WebSocket,uWS::HttpRequest)>)': 无法将参数 1 从 'main::<lambda_65b17263bf2521e013c9f6d82b42f5a6>' 转换为 'std ::函数<void (uWS::WebSocket,uWS::HttpRequest)>'
- 错误 C2664: 'void uWS::Group::onDisconnection(std::function<void (uWS::WebSocket,int,char *,size_t)>)': 无法将参数 1 从 'main::<lambda_ab657350ab1a8d006c36b876f8906aac>' 转换为'std::function<void (uWS::WebSocket,int,char *,size_t)>'
我的主要功能的代码是
#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();
我正在寻找关于为什么我收到此错误的解决方案。我将参数作为指针传递,我认为这是正确的格式