update TCP request, argument

This commit is contained in:
ackimixs
2024-03-27 20:03:28 +01:00
parent ce1f0f9daa
commit 4f79d18938
4 changed files with 42 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
#include "ArucoDetector.h"
ArucoDetector::ArucoDetector(Type::RobotPose* pose, const std::string& calibrationPath, const Team team, const int cameraId, const bool headless) : robotPose(pose), headless(headless), team(team)
ArucoDetector::ArucoDetector(Type::RobotPose* pose, const std::string& calibrationPath, const Team team, const bool headless) : robotPose(pose), headless(headless), team(team)
{
// opencv 4.8
// this->detector = cv::aruco::ArucoDetector(getPredefinedDictionary(cv::aruco::DICT_4X4_50), cv::aruco::DetectorParameters());
@@ -19,19 +19,12 @@ ArucoDetector::ArucoDetector(Type::RobotPose* pose, const std::string& calibrati
);
this->readCameraParameters(calibrationPath);
// this->cap = cv::VideoCapture(cameraId);
this->cam = new lccv::PiCamera;
cam->options->video_width=1920;
cam->options->video_height=1080;
cam->options->framerate=10;
cam->options->verbose=true;
/* if (!cap.isOpened()) {
std::cerr << "Error opening camera." << std::endl;
} else
{
started = true;
}*/
started = true;
if (!headless)

View File

@@ -32,7 +32,7 @@ class ArucoDetector {
bool started = false;
public:
ArucoDetector(Type::RobotPose* pose, const std::string& calibrationPath, Team team, int cameraId = 0, bool headless = false);
ArucoDetector(Type::RobotPose* pose, const std::string& calibrationPath, Team team, bool headless = false);
~ArucoDetector();

View File

@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
{
if (std::string(argv[i]) == "--help")
{
std::cout << "Usage: " << argv[0] << " <video capture device> <path/to/calibration_results.yaml>" << std::endl;
std::cout << "Usage: " << argv[0] << "<path/to/calibration_results.yaml> <TCP port>" << std::endl;
std::cout << "video capture device: The ID of the video capture device to use. Usually 0 for the built-in camera." << std::endl;
std::cout << "path/to/calibration_results.yaml: The path to the calibration results file." << std::endl;
std::cout << "to run the program in headless mode, add the --headless flag." << std::endl;
@@ -40,19 +40,11 @@ int main(int argc, char *argv[])
}
if (argc < 3) {
std::cout << "Usage: " << argv[0] << " <video capture device> <path/to/calibration_results.yaml>" << std::endl;
std::cout << "Usage: " << argv[0] << "<path/to/calibration_results.yaml> <port>" << std::endl;
return 1;
}
const int cameraId = std::stoi(argv[1]);
if (cameraId < 0)
{
std::cerr << "Error: Camera ID must be a positive integer." << std::endl;
return -1;
}
const std::string calibrationPath = argv[2];
const std::string calibrationPath = argv[1];
// End argument parser
std::optional<std::thread> userInput;
@@ -64,7 +56,7 @@ int main(int argc, char *argv[])
auto* robotPose = new Type::RobotPose{cv::Point3f(0, 0, 0), CV_PI/2};
ArucoDetector detector(robotPose, calibrationPath, BLUE, cameraId, headless);
ArucoDetector detector(robotPose, calibrationPath, BLUE, headless);
auto whiteFlower = ArucoTag(36, "White_flower", 20, FLOWER);
//whiteFlower.setFlowerObjectRepresentation();
@@ -75,7 +67,9 @@ int main(int argc, char *argv[])
int code;
MyClient client(robotPose, "127.0.0.1", 8080);
int port = std::stoi(argv[2]);
MyClient client(robotPose, "127.0.0.1", port);
client.start();

View File

@@ -12,39 +12,44 @@ MyClient::MyClient(Type::RobotPose* robotPose, const char* ip, const int port) :
void MyClient::handleMessage(const std::string& message)
{
if (startWith(message, "request aruco"))
std::vector<std::string> messageSplited = split(message, ";");
if (messageSplited[0] == "aruco" || messageSplited[0] == "all")
{
std::string res;
res += "arucotags ";
if (arucoTags.empty())
if (messageSplited[2] == "get aruco")
{
res += "404";
} else {
for (auto& [tag, pos] : arucoTags)
std::string res;
res += "aruco;strat;get aruco;";
if (arucoTags.empty())
{
res += std::to_string(tag.id) + " ";
res += std::to_string(pos.first.at<double>(0, 0)) + " ";
res += std::to_string(pos.first.at<double>(1, 0)) + " ";
res += std::to_string(pos.first.at<double>(2, 0)) + " ";
res += "404";
} else {
for (auto& [tag, pos] : arucoTags)
{
res += std::to_string(tag.id) + ",";
res += tag.name + ",";
res += std::to_string(pos.first.at<double>(0, 0)) + ",";
res += std::to_string(pos.first.at<double>(1, 0)) + ",";
res += std::to_string(pos.first.at<double>(2, 0)) + ",";
}
}
this->sendMessage(res.c_str());
} else if (messageSplited[2] == "ping")
{
this->sendMessage("pong aruco");
} else if (messageSplited[2] == "set robot_pos")
{
// cut the string with space and take the first, second, third and fourth element
std::vector<std::string> tokens = split(message, " ");
robotPose->position.x = std::stof(tokens[1]);
robotPose->position.y = std::stof(tokens[2]);
robotPose->position.z = std::stof(tokens[3]);
robotPose->theta = std::stof(tokens[4]);
}
this->sendMessage(res.c_str());
} else if (startWith(message, "ping aruco"))
{
this->sendMessage("pong aruco");
} else if (startWith(message, "robotPose"))
{
// cut the string with space and take the first, second, third and fourth element
std::vector<std::string> tokens = split(message, " ");
robotPose->position.x = std::stof(tokens[1]);
robotPose->position.y = std::stof(tokens[2]);
robotPose->position.z = std::stof(tokens[3]);
robotPose->theta = std::stof(tokens[4]);
}
}