diff --git a/build/.cmake/api/v1/reply/index-2026-06-04T16-14-38-0131.json b/build/.cmake/api/v1/reply/index-2026-06-04T16-14-38-0131.json deleted file mode 100644 index 7dc5a6b..0000000 --- a/build/.cmake/api/v1/reply/index-2026-06-04T16-14-38-0131.json +++ /dev/null @@ -1,132 +0,0 @@ -{ - "cmake" : - { - "generator" : - { - "multiConfig" : false, - "name" : "Unix Makefiles" - }, - "paths" : - { - "cmake" : "/usr/bin/cmake", - "cpack" : "/usr/bin/cpack", - "ctest" : "/usr/bin/ctest", - "root" : "/usr/share/cmake-4.2" - }, - "version" : - { - "isDirty" : false, - "major" : 4, - "minor" : 2, - "patch" : 3, - "string" : "4.2.3", - "suffix" : "" - } - }, - "objects" : - [ - { - "jsonFile" : "codemodel-v2-1d54dc62b65d9b1e65df.json", - "kind" : "codemodel", - "version" : - { - "major" : 2, - "minor" : 9 - } - }, - { - "jsonFile" : "cache-v2-374534acf1e5fd169877.json", - "kind" : "cache", - "version" : - { - "major" : 2, - "minor" : 0 - } - }, - { - "jsonFile" : "cmakeFiles-v1-e320a106f03fb9214dd8.json", - "kind" : "cmakeFiles", - "version" : - { - "major" : 1, - "minor" : 1 - } - }, - { - "jsonFile" : "toolchains-v1-f6f24f4dd93f5f594387.json", - "kind" : "toolchains", - "version" : - { - "major" : 1, - "minor" : 0 - } - } - ], - "reply" : - { - "client-vscode" : - { - "query.json" : - { - "requests" : - [ - { - "kind" : "cache", - "version" : 2 - }, - { - "kind" : "codemodel", - "version" : 2 - }, - { - "kind" : "toolchains", - "version" : 1 - }, - { - "kind" : "cmakeFiles", - "version" : 1 - } - ], - "responses" : - [ - { - "jsonFile" : "cache-v2-374534acf1e5fd169877.json", - "kind" : "cache", - "version" : - { - "major" : 2, - "minor" : 0 - } - }, - { - "jsonFile" : "codemodel-v2-1d54dc62b65d9b1e65df.json", - "kind" : "codemodel", - "version" : - { - "major" : 2, - "minor" : 9 - } - }, - { - "jsonFile" : "toolchains-v1-f6f24f4dd93f5f594387.json", - "kind" : "toolchains", - "version" : - { - "major" : 1, - "minor" : 0 - } - }, - { - "jsonFile" : "cmakeFiles-v1-e320a106f03fb9214dd8.json", - "kind" : "cmakeFiles", - "version" : - { - "major" : 1, - "minor" : 1 - } - } - ] - } - } - } -} diff --git a/build/bin/mainV5 b/build/bin/mainV5 index 09e96fe..c731567 100755 Binary files a/build/bin/mainV5 and b/build/bin/mainV5 differ diff --git a/src/pieces/headers/piece_interface.hpp b/src/pieces/headers/piece_interface.hpp index 7b261e3..81922ea 100644 --- a/src/pieces/headers/piece_interface.hpp +++ b/src/pieces/headers/piece_interface.hpp @@ -32,7 +32,7 @@ class PieceInterface{ rb::rigidbody body; sf::Color color; - virtual void update(sf::Clock cl) = 0; + virtual void update(unsigned int pos) = 0; virtual sf::Shape* draw(ReferencePlane plane) = 0; virtual ~PieceInterface(){} }; diff --git a/src/pieces/headers/sensore.hpp b/src/pieces/headers/sensore.hpp index dc3f518..e368c13 100644 --- a/src/pieces/headers/sensore.hpp +++ b/src/pieces/headers/sensore.hpp @@ -18,8 +18,8 @@ class Sensore : public PieceInterface{ //in che punto sto controllando il segnale unsigned int dataPos; - unsigned int dataIntvl; - + std::vector dataIntvl; + unsigned int curTime; //funzioni ausiliarie void calcRotWithG(unsigned int index); @@ -27,14 +27,16 @@ class Sensore : public PieceInterface{ public: Sensore(rb::Vector3 coords, _Float16 mass); - Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, unsigned int dataIntvl, std::vector> data); + Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, int min, int max, std::vector> data); ~Sensore(); - void update(sf::Clock cl) override; + void update(unsigned int pos) override; sf::Shape* draw(ReferencePlane plane) override; //funzioni specifiche void initCSV(std::vector> data); + void setIntervall(int min, int max); + void setPos(int &pos); }; diff --git a/src/pieces/methods/sensore_class.cpp b/src/pieces/methods/sensore_class.cpp index c223161..36641cb 100644 --- a/src/pieces/methods/sensore_class.cpp +++ b/src/pieces/methods/sensore_class.cpp @@ -9,10 +9,11 @@ Sensore::Sensore(rb::Vector3 coords, _Float16 mass){ initialize_shapes(sensore_Dim); } -Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, unsigned int dataIntvl, std::vector> data) : Sensore(coords, mass){ +Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, int min, int max, std::vector> data) : Sensore(coords, mass){ dataPos = st; - this->dataIntvl = dataIntvl; + this->dataIntvl = {min, max}; initCSV(data); + curTime = 0; } @@ -35,7 +36,7 @@ void Sensore::initCSV(std::vector> data){ /////// DA CAMBIARE QUI /////////// - + rotData.push_back(tmpR); accData.push_back(tmpA); gData.push_back(tmpG); @@ -45,7 +46,14 @@ void Sensore::initCSV(std::vector> data){ void Sensore::update(sf::Clock cl){ // Aggiorno la posizione nei dati - int64_t currTime = cl.getElapsedTime().asMicroseconds() *100000; + curTime += cl.getElapsedTime().asMilliseconds(); + /* + if (timeData[dataPos]){ + + } + */ + + /* if (timeData[dataPos] < currTime && dataIntvl - dataPos > 0) { //aggiorno solo se ho cambiato posizione dataPos++; @@ -56,6 +64,7 @@ void Sensore::update(sf::Clock cl){ body.setAcc(rb::Vector3{accData[dataPos]}); body.step(cl); } + */ } @@ -108,9 +117,14 @@ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori body.setRot(rb::Vector3{tmpAY, tmpAX, tmpAZ }); } -/* -void Sensore::calcRotWithConstraint(){ -};*/ +void Sensore::setIntervall(int min, int max){ + this->dataIntvl = {min, max}; +} + +void Sensore::setPos(int &pos){ + this->dataPos = pos; +} + /////////////// cinematica inversa \ No newline at end of file diff --git a/src/sfml_util.cpp b/src/sfml_util.cpp index 34a0b2c..f00d737 100644 --- a/src/sfml_util.cpp +++ b/src/sfml_util.cpp @@ -34,16 +34,20 @@ struct State sf::Vector2i mouse_pos; /// per settare l'ntervallo di visualizzazione - unsigned int pos = 0; - unsigned int intervalMajLimit = 1000; - unsigned int intervalMinLimit = 0; - unsigned int maxEntries = 10000; + unsigned int* pos ; + unsigned int* intervalMajLimit ; + unsigned int* intervalMinLimit ; + unsigned int maxEntries = 1000; + bool play = true; - State(unsigned w, unsigned h, std::string title) + State(unsigned w, unsigned h, std::string title, unsigned int* maj, unsigned int* min, unsigned int* pos) { window = sf::RenderWindow(sf::VideoMode({w, h}), title); ImGui::SFML::Init(window); clock.restart(); + intervalMajLimit = maj; + intervalMinLimit = min; + this->pos = pos; } void update(); void setIntervall(int n){ @@ -61,7 +65,7 @@ void State::update(){ for(PieceInterface* p : pieces){ - p->update(clock); + p->update(*pos); } for(JointInterface* j : joints){ j->movechild(); @@ -207,13 +211,13 @@ void doGUI(State &gs) ImGui::ShowDemoWindow(); ImGui::Begin("Set data position"); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.3); - ImGui::SliderScalar("Min", ImGuiDataType_U32 ,&gs.intervalMinLimit,&zero,&gs.intervalMajLimit); + ImGui::SliderScalar("Min", ImGuiDataType_U32 ,gs.intervalMinLimit,&zero,gs.intervalMajLimit); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.5); - ImGui::SliderScalar("Pos", ImGuiDataType_U32 ,&gs.pos,&gs.intervalMinLimit,&gs.intervalMajLimit); + ImGui::SliderScalar("Pos", ImGuiDataType_U32 ,gs.pos,gs.intervalMinLimit,gs.intervalMajLimit); ImGui::SameLine(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.8); - ImGui::SliderScalar("Max", ImGuiDataType_U32 ,&gs.intervalMajLimit,&gs.intervalMinLimit,&gs.maxEntries); + ImGui::SliderScalar("Max", ImGuiDataType_U32 ,gs.intervalMajLimit,gs.intervalMinLimit,&gs.maxEntries); ImGui::End(); diff --git a/src/testMain.cpp b/src/testMain.cpp index bdc8c9a..d503e8e 100755 --- a/src/testMain.cpp +++ b/src/testMain.cpp @@ -28,8 +28,15 @@ int main() { std::cerr << "Error: " << e.what() << std::endl; } + // inizializzo variabili per gestire l'intervallo di visualizzazione + + unsigned int max = 1000; + unsigned int min = 0; + unsigned int pos = 0; + unsigned int maj = 100; + //Costruisco la GUI - State gs(800, 600, "Visualizzatore passo"); + State gs(800, 600, "Visualizzatore passo",&maj,&min,&pos); gs.window.setFramerateLimit(60); printf("Costruisco gli oggetti\n"); @@ -40,7 +47,7 @@ int main() { gs.pieces.push_back(new Coscia (rb::Vector3{300,300,300},2)); - gs.pieces.push_back(new Sensore (rb::Vector3{300,300,300},_Float16( 0.2 ),900,3000,coscia)); + gs.pieces.push_back(new Sensore (rb::Vector3{300,300,300},_Float16( 0.2 ),900,900,3000,coscia)); gs.pieces.push_back(new Caviglia (rb::Vector3{300,300,500},1)); gs.pieces[1]->body.setRot({0,0,0}); @@ -48,7 +55,7 @@ int main() { processor.readCSVFile(DATA_PATH + "caviglia_filt.csv"); const auto& caviglia = processor.getData(); - gs.pieces.push_back(new Sensore (rb::Vector3{300,300,500},_Float16( 0.2 ),900,3000,caviglia)); + gs.pieces.push_back(new Sensore (rb::Vector3{300,300,500},_Float16( 0.2 ),900,900,3000,caviglia)); gs.pieces.push_back(new Torso(rb::Vector3{300,400,150},2)); @@ -71,10 +78,22 @@ int main() { printf("%s\n",e); } printf("Avvio l'interfaccia grafica\n"); + + + unsigned int curTime; + unsigned int freq = 50; + const unsigned int T = 1000/freq; //i sensori hanno una freq di campionamento di 50hz + //Avvio il loop della GUI gs.clock.start(); while (gs.window.isOpen()) { + curTime += gs.clock.getElapsedTime().asMilliseconds(); + if (curTime > T){ + curTime = 0; + if (gs.play && pos < maj) pos += 1; + } + // Show update gs.update(); doGraphics(gs);