diff --git a/include/RealIntelCam.hpp b/include/RealIntelCam.hpp new file mode 100644 index 0000000..b834247 --- /dev/null +++ b/include/RealIntelCam.hpp @@ -0,0 +1,42 @@ +#ifndef INTELCAM_H +#define INTELCAM_H + +#include +#include +#include +#include + +const float TIME_INTERVAL = 0.01; // Time interval in seconds +const double RAD_TO_DEG = 180.0 / M_PI; + + +using namespace std + +class realIntelCam +{ + public: + + RealIntelCam(); + + void update_camera_position(); + + vector get_location(); + + vector get_angle(); + + private: + //Essential to initiate connection + rs2::pipeline pipeline; + rs2::config configure; + rs2::pipeline_profile profile; + // the acceleration in 3D previous: 0->x, 1->y, 2->z current 3->x, 4->y, 5->z + float acceleration[]{}; + // average velocity aka speed + float velocity[]{}; + // calculated location + float camera_location[]; + //calculated angle + float camera_angle[]; +} + +#endif \ No newline at end of file diff --git a/include/web_interface.hpp b/include/web_interface.hpp new file mode 100644 index 0000000..06af9ac --- /dev/null +++ b/include/web_interface.hpp @@ -0,0 +1,6 @@ +#ifndef WEB_INTERFACE_HPP +#define WEB_INTERFACE_HPP + +int web(Mat *frame); + +#endif // WEBCAM_INTERFACE_HPP diff --git a/make.txt b/make.txt new file mode 100644 index 0000000..86d50f9 --- /dev/null +++ b/make.txt @@ -0,0 +1,9 @@ +build_/mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/sample_submodule build_/mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/grass_killer build_/mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/imu_interface +mkdir -p /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs +mkdir -p /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build +g++ -I /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/include -c /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/sample_submodule/submodule.cpp -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/submodule.o +g++ -I /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/include -c /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/sample_submodule/arg.cpp -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/arg.o +g++ -I /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/include -c /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/grass_killer/grass_killer.cpp -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/grass_killer.o +g++ -I /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/include -c /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/src/imu_interface/measure.cpp -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/measure.o +[[[[ BUILDING NAVI ]]]] +g++ /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/main.o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/submodule.o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/arg.o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/grass_killer.o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/build/objs/measure.o -o /mnt/c/Users/adelr/Documents/Agrobot/new-intel-realsense-imu-interface-Alfredo/.git/Navi/navi diff --git a/src/web_interface/rules.mk b/src/web_interface/rules.mk new file mode 100644 index 0000000..1faa7b4 --- /dev/null +++ b/src/web_interface/rules.mk @@ -0,0 +1,10 @@ +GENERATED_OBJS := web_interface.o + +include submodule.general.mk + +build_$(DIR): + $(call build,web_interface.cpp) +clean_$(DIR): +test_$(DIR): + @echo testing the module $(DIR)! +test_webcam_interface: test_$(DIR) diff --git a/src/web_interface/web_interface.cpp b/src/web_interface/web_interface.cpp new file mode 100644 index 0000000..6f6313a --- /dev/null +++ b/src/web_interface/web_interface.cpp @@ -0,0 +1,69 @@ +#include +#include +#include + +using namespace std; +using namespace cv; + +// Alias for websocketpp server +typedef websocketpp::server server; + +/*! + * Handles the connection to the WebSocket server. + * Captures frames from the webcam, encodes them, + * and sends them via the WebSocket connection. + * + * \param hdl The connection handle. + * \param s The WebSocket server. + * \param cap The OpenCV VideoCapture object. + */ +void handle_connection(websocketpp::connection_hdl hdl, server& s, Mat *frame) { + while (true) { + try { + if (!frame->empty()) { + // Convert OpenCV frame to byte vector + vector buffer; + imencode(".jpg", *frame, buffer); + s.send(hdl, buffer.data(), buffer.size(), websocketpp::frame::opcode::binary); + } + else { + cerr << "Couldn't capture frame from webcam." << endl; + break; + } + } catch (websocketpp::exception const & e) { + cout << "Caught websocket exception: " << e.what() << endl; + } + } +} + +/*! + * Initializes and runs the WebSocket server, capturing frames + * from the webcam and sending them via open WebSocket connections. + * + * Clears all access log channels, initializes the OpenCV webcam, + * defines the WebSocket server connection handler, listens on port 6969, + * and finally starts the accept loop and the ASIO io_service event loop. + * + * \return 0 if the server ran successfully, otherwise -1. + */ +int web(Mat *frame) { + // Create a WebSocket server + server s; + // Clear all access log channels to prevent frames being logged + // If frames are logged, then it makes the WebSocket server very slow + s.clear_access_channels(websocketpp::log::alevel::all); + + s.set_open_handler([&s,frame](websocketpp::connection_hdl hdl) { + thread video_thread(handle_connection, hdl, ref(s), ref(frame)); + video_thread.detach(); + }); + + // Listen on port 6969 + s.init_asio(); + s.listen(6969); + s.start_accept(); + s.run(); + + return 0; +} +