diff --git a/braindump.md b/braindump.md new file mode 100644 index 0000000..83545ae --- /dev/null +++ b/braindump.md @@ -0,0 +1,53 @@ +# Math library render implementation + +- [ ] mat4 + - [ ] functions mat4 + - [ ] constructor (identity?) + - [ ] multiply + - [ ] data acces glm::value_prt equivalent + - [ ] translate + - [ ] rotate + - [ ] perspective + - [ ] scale + - [ ] vlookat (?) + - [ ] quaternion to matrix +- [ ] vec3 + - [ ] functions vec3 + - [x] constructor + - [x] add + - [x] substract + - [x] multiply scalar + - [x] dot product + - [X] cross product + - [x] length + - [x] normalize +- [ ] mat3 +- [ ] vec4 +- [ ] quaternions to matrix +- [ ] glm::radians + + +- Connector und Connected-status indicator +- implement calibration ??? +- load .obj as model +- make it run on linux/unix +- implement 2nd sensor +- rigid body them together, somehow??? +- have a look at rtos, start the move over +- actually print a fucking model +- and most importantly LETS FUCKING GOOOOOOOOOO +- have a look at CAN and wireless and battery. how to implement those actually? PCBs??? +- Custom designed PCBs for sensors, connectors and stuff? what will be the eventual brain later on, store bought stm32? +- ziel für diese woche ist endlich eine funktionierende prototypen version zu haben, die genau das macht was sie später soll + +Today: +- **stop relying on claude/ai code. the code is shit and you dont know what youre doing half the time. use it to explain shit** +- ~~Laptops bei Ebay reinstellen (Bilder machen, Beschreibung)~~ +- ~~Laptops verpacken +- ~~Unraidserver saubermachen; neue Parity Disk einbauen~~ +- ~~Tisch saugen, Müll wegwerfen~~ +- RTOS projekt anlegen und code migrieren. Läuft alles noch? (turns out dieser approach ist vielleicht von grundauf scheiße, wenn ich eh eigene mcus and die imus bringe und alles wireless mit nem brain verbinde. mal sehen, gut zum testen i guess wie rtos funktioniert) +- 2nd sensor implementation embedded/pc +- design cad model for testrig (2 sensors, hinge) +- print cad model +- use cad model as obj in visualizer \ No newline at end of file diff --git a/build/.cmake/api/v1/reply/index-2025-06-10T07-52-59-0352.json b/build/.cmake/api/v1/reply/index-2025-08-07T12-15-05-0760.json similarity index 100% rename from build/.cmake/api/v1/reply/index-2025-06-10T07-52-59-0352.json rename to build/.cmake/api/v1/reply/index-2025-08-07T12-15-05-0760.json diff --git a/build/Debug/visualizer.exe b/build/Debug/visualizer.exe index fad465c..702a49e 100644 Binary files a/build/Debug/visualizer.exe and b/build/Debug/visualizer.exe differ diff --git a/build/Debug/visualizer.pdb b/build/Debug/visualizer.pdb index 5828d46..3a74098 100644 Binary files a/build/Debug/visualizer.pdb and b/build/Debug/visualizer.pdb differ diff --git a/build/visualizer.dir/Debug/main.obj b/build/visualizer.dir/Debug/main.obj index 7a584ce..c9c18de 100644 Binary files a/build/visualizer.dir/Debug/main.obj and b/build/visualizer.dir/Debug/main.obj differ diff --git a/build/visualizer.dir/Debug/serialcomm.obj b/build/visualizer.dir/Debug/serialcomm.obj index 79f0dff..120faae 100644 Binary files a/build/visualizer.dir/Debug/serialcomm.obj and b/build/visualizer.dir/Debug/serialcomm.obj differ diff --git a/build/visualizer.dir/Debug/vc143.pdb b/build/visualizer.dir/Debug/vc143.pdb index f9ed80d..383130b 100644 Binary files a/build/visualizer.dir/Debug/vc143.pdb and b/build/visualizer.dir/Debug/vc143.pdb differ diff --git a/build/visualizer.dir/Debug/visualizer.ilk b/build/visualizer.dir/Debug/visualizer.ilk index 208f245..b4f4a8b 100644 Binary files a/build/visualizer.dir/Debug/visualizer.ilk and b/build/visualizer.dir/Debug/visualizer.ilk differ diff --git a/build/visualizer.dir/Debug/visualizer.tlog/CL.command.1.tlog b/build/visualizer.dir/Debug/visualizer.tlog/CL.command.1.tlog index 2d8e070..b5b89f0 100644 Binary files a/build/visualizer.dir/Debug/visualizer.tlog/CL.command.1.tlog and b/build/visualizer.dir/Debug/visualizer.tlog/CL.command.1.tlog differ diff --git a/build/visualizer.dir/Debug/visualizer.tlog/CL.read.1.tlog b/build/visualizer.dir/Debug/visualizer.tlog/CL.read.1.tlog index 1c49f27..dd76668 100644 Binary files a/build/visualizer.dir/Debug/visualizer.tlog/CL.read.1.tlog and b/build/visualizer.dir/Debug/visualizer.tlog/CL.read.1.tlog differ diff --git a/build/visualizer.dir/Debug/visualizer.tlog/CL.write.1.tlog b/build/visualizer.dir/Debug/visualizer.tlog/CL.write.1.tlog index 7a3990c..1a0ebdb 100644 Binary files a/build/visualizer.dir/Debug/visualizer.tlog/CL.write.1.tlog and b/build/visualizer.dir/Debug/visualizer.tlog/CL.write.1.tlog differ diff --git a/build/visualizer.dir/Debug/visualizer.tlog/link.read.1.tlog b/build/visualizer.dir/Debug/visualizer.tlog/link.read.1.tlog index e56ad10..a36524d 100644 Binary files a/build/visualizer.dir/Debug/visualizer.tlog/link.read.1.tlog and b/build/visualizer.dir/Debug/visualizer.tlog/link.read.1.tlog differ diff --git a/imgui.ini b/imgui.ini index 6308ead..da82531 100644 --- a/imgui.ini +++ b/imgui.ini @@ -1,5 +1,5 @@ [Window][Debug##Default] -Pos=37,29 +Pos=22,29 Size=326,393 [Window][Hello, ImGui!] diff --git a/main.cpp b/main.cpp index b8ff933..711d2a6 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -26,7 +27,7 @@ std::mutex g_mutex; Quaternion g_currQuat = {1.0f, 0.0f, 0.0f, 0.0f}; std::vector g_quadHistory; -bool g_running = true; +bool g_running = false; HANDLE g_serialHandle = INVALID_HANDLE_VALUE; @@ -113,7 +114,7 @@ void serialParserThread() { // close and exit the thread CloseHandle(g_serialHandle); - std::cout << "Serial communicatin thread exiting" << std::endl; + std::cout << "Serial communication thread exiting" << std::endl; } @@ -293,7 +294,8 @@ int main() { // Start serial parsing thread // pass the address of the code in memory so that thread can start its instance of the function - std::thread parserThread(serialParserThread); + //std::thread parserThread(serialParserThread); + std::thread* parserThread = nullptr; // set rendering state of window glClearColor(0.2f, 0.3f, 0.3f, 1.0f); @@ -302,7 +304,7 @@ int main() { // main rendering loop for the ui - while (g_running && !glfwWindowShouldClose(window)) { + while (!glfwWindowShouldClose(window)) { // process new events from window evevnt queue glfwPollEvents(); // clear the color buffer == clear the screen / / GL_DEPTH_BUFFER_BIT would be for 3D rendering @@ -329,7 +331,7 @@ int main() { // apply MVP //model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f)); - // this need to be deleted and redone + // this needs to be deleted and redone glm::quat kekus_q(g_currQuat.w, g_currQuat.x, g_currQuat.y, g_currQuat.z); @@ -379,6 +381,26 @@ int main() { ImGui::Text("Hello Daddy, I'm here to serve"); ImGui::Text("w: %.4f x: %.4f y: %.4f z: %.4f", lQuad.w, lQuad.x, lQuad.y, lQuad.z); + ImGui::Text("Connection to MCU: "); + + ImGui::BeginDisabled(parserThread != nullptr); + if (ImGui::Button("Connect")) { + g_running = true; + parserThread = new std::thread(serialParserThread); + } + ImGui::EndDisabled(); + + ImGui::SameLine(); + + ImGui::BeginDisabled(parserThread == nullptr); + if (ImGui::Button("Disconnect")) { + g_running = false; + parserThread -> join(); + delete parserThread; + parserThread = nullptr; + } + ImGui::EndDisabled(); + // create scrolling section for last 200 measurements ImGui::BeginChild("History", ImVec2(0, 300), true, ImGuiWindowFlags_HorizontalScrollbar); @@ -405,10 +427,10 @@ int main() { } // set the parsing thread to exit and wait for it - g_running = false; - if (parserThread.joinable()) { - parserThread.join(); - } + // g_running = false; + //if (parserThread.joinable()) { + // parserThread.join(); + //} // clean up ImGui ImGui_ImplOpenGL3_Shutdown(); diff --git a/math3d.cpp b/math3d.cpp new file mode 100644 index 0000000..b372d76 --- /dev/null +++ b/math3d.cpp @@ -0,0 +1,96 @@ +#include + +struct Vec3 { + float x, y, z; +}; + +Vec3 create_Vec3 (float x, float y, float z) { + Vec3 result = {x, y, z}; + return result; +} + +Vec3 Vec3_add (const Vec3& a, const Vec3& b) { + Vec3 result = {a.x + b.x, a.y + b.y, a.z + b.z}; + return result; +} + +Vec3 Vec3_subtract (const Vec3& a, const Vec3& b) { + Vec3 result = {a.x - b.x, a.y - b.y, a.z - b.z}; + return result; +} + +Vec3 Vec3_scalar (const Vec3& a, const float scalar) { + Vec3 result = {a.x*scalar, a.y*scalar, a.z*scalar}; + return result; +} + +float Vec3_dot (const Vec3& a, const Vec3& b) { + float result = a.x*b.x + a.y*b.y + a.z*b.z; + return result; +} + +Vec3 Vec3_cross (const Vec3& a, const Vec3& b) { + Vec3 result = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; + return result; +} + +float Vec3_length (const Vec3& a) { + float result = sqrt(a.x*a.x + a.y*a.y + a.z*a.z); + return result; +} + +Vec3 Vec3_normalize (const Vec3& a) { + Vec3 result; + float len = sqrt(a.x*a.x + a.y*a.y + a.z*a.z); + if (len > 0.0f) { + return result = {a.x/len, a.y/len, a.z/len}; + } else { + return a; + } + +} + +struct Mat4{ + float m4[16]; +}; + +Mat4 Mat4_createMatrix (float InitialValue) { + Mat4 result; + for (int i = 0; i < 16; i++) { + result.m4[i] = {InitialValue}; + } + return result; +} + +Mat4 Mat4_createZeroes () { + Mat4 result = {0}; + return result; +} + +Mat4 Mat4_createIdentity () { + Mat4 result = {0}; + result.m4[0] = 1; + result.m4[5] = 1; + result.m4[10] = 1; + result.m4[15] = 1; + return result; +} + +Mat4 Mat4_createTranslation (float x, float y, float z) { + Mat4 result = {0}; + result.m4[0] = 1; + result.m4[5] = 1; + result.m4[10] = 1; + result.m4[15] = 1; + result.m4[12] = x; + result.m4[13] = y; + result.m4[14] = z; + return result; +} + +//translate +//rotate +//scale +//perspective + + diff --git a/math3d.hpp b/math3d.hpp new file mode 100644 index 0000000..e69de29 diff --git a/serialcomm.cpp b/serialcomm.cpp index 4b0066d..c6bdf28 100644 --- a/serialcomm.cpp +++ b/serialcomm.cpp @@ -1,4 +1,13 @@ -#include +#ifdef _WIN32 + #include +#elif defined(__APPLE__) +#elif defined(__linux__) + #include + #include + #include + #include +#endif + #include #include #include @@ -6,7 +15,8 @@ #include #include "serialcomm.hpp" -HANDLE initSerialPort (const char* portName, DWORD baudRate) { +#ifdef _WIN32 + HANDLE initSerialPort (const char* portName, DWORD baudRate) { // open serial port HANDLE hSerial = CreateFile(portName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); @@ -62,6 +72,54 @@ bool readSerialData (HANDLE hSerial, char* buffer, DWORD bufferSize, DWORD& byte return true; } +#elif defined(__APPLE__) +#elif defined(__linux__) + int initSerialPort(){ + struct termios tty; + + int linux_serialPort = open("/dev/ttyUSB0", 0_RDWR); + + // read in existing struct settings and handle errors + if (tcgetattr(linux_serialPort, &tty) !0 0) { + std::cout << "Error %i opening serial port: %s\n", errno, strerror(errno) << std::endl; + return 1; + } + + // set the serial settings + tty.c_flag &= ~PARENB; + tty.c_flag &= ~CSTOPB; + tty.c_flag &= ~CSIZE; + tty.c_flag |= CS8; + tty.c_flag &= ~CRTSCTS; + tty.c_flag |= CREAD | CLOCAL; + + tty.c_cc[VTIME] = 10; // Wait for up to 1s (10 deciseconds), returning as soon as any data is received. + tty.c_cc[VMIN] = 0; + + // Set in/out baud rate to be 9600 + cfsetispeed(&tty, B115200); + cfsetospeed(&tty, B115200); + + // save the settings and check for errors + if (tcsetattr(linux_serialPort, TCSANOW, &tty) != 0 ) { + std::cout << "Error %i saving serial port settings: %s\n", errno, strerror(errno) << std::endl; + return 1; + } + + return linux_serialPort; + } + + bool linux_readSerialData (int serialPort, char* buffer) { + if (read(serialPort, &buffer, sizeof(buffer)) < 0 ) { + std::cout << "Error reading serial port data: %s", strerror(errno)) << std::endl; + return 1; + } + } + + +#endif + + bool parseQuaternion(const std::string& data, Quaternion& quat) { // regex pattern to match the floats in the uart data stream from stm32 std::regex pattern("qw: ([+-]?\\d*\\.?\\d+) qx: ([+-]?\\d*\\.?\\d+) qy: ([+-]?\\d*\\.?\\d+) qz: ([+-]?\\d*\\.?\\d+)"); diff --git a/serialcomm.hpp b/serialcomm.hpp index a69c50f..6fdfd28 100644 --- a/serialcomm.hpp +++ b/serialcomm.hpp @@ -7,4 +7,7 @@ struct Quaternion { HANDLE initSerialPort (const char* portName, DWORD baudRate); bool readSerialData (HANDLE hSerial, char* buffer, DWORD bufferSize, DWORD& bytesRead); -bool parseQuaternion(const std::string& data, Quaternion& quat); \ No newline at end of file +bool parseQuaternion(const std::string& data, Quaternion& quat); + +int linux_initSerialPort(); +bool linux_readSerialData(int serialPort, char* buffer); \ No newline at end of file diff --git a/uff.cpp b/uff.cpp new file mode 100644 index 0000000..19acea9 --- /dev/null +++ b/uff.cpp @@ -0,0 +1,46 @@ +class Vec3 { + public: + float x, y, z; + + Vec3(float x, float y, float z) { + this->x = x; + this->y = y; + this->z = z; + } + + Vec3 add (Vec3 other) { + Vec3 result (x + other.x, y + other.y, z + other.z); + return result; + } + + Vec3 subtract (Vec3 other) { + Vec3 result (x - other.x, y - other.y, z - other.z); + return result; + } + + Vec3 scalar (float scalar) { + Vec3 result (x * scalar, y * scalar, z * scalar); + return result; + } + + float dot (Vec3 other) { + float result (x * other.x + y * other.y + z * other.z); + return result; + } + + Vec3 cross (Vec3 other) { + Vec3 result (y*other.z - z*other.y, z*other.x - x*other.z, x*other.y - y*other.x); + return result; + } + + float length () { + float result = sqrt(x*x + y*y + z*z); + return result; + } + + Vec3 normalize () { + float len = sqrt(x*x + y*y + z*z); + Vec3 result (x / len, y / len, z / len); + return result; + } +}; \ No newline at end of file