Controllo posizione con gui completa

This commit is contained in:
2026-06-06 11:27:21 +02:00
parent 52b2a95032
commit ba5e071c6f
7 changed files with 20 additions and 44 deletions
+2 -2
View File
@@ -23,8 +23,8 @@ Pos=68,96
Size=740,472
[Window][Set data position]
Pos=18,542
Size=534,60
Pos=10,520
Size=521,73
[Window][Dear ImGui Demo/ResizableChild_478B81A3]
IsChild=1
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -32,7 +32,7 @@ class PieceInterface{
rb::rigidbody body;
sf::Color color;
virtual void update(unsigned int pos) = 0;
virtual void update(sf::Clock cl) = 0;
virtual sf::Shape* draw(ReferencePlane plane) = 0;
virtual ~PieceInterface(){}
};
+3 -6
View File
@@ -14,12 +14,9 @@ class Sensore : public PieceInterface{
std::vector<std::vector<float>> gData;
std::vector<std::vector<float>> rotData;
std::vector<float> timeData;
rb::Vector3 stPos;
//in che punto sto controllando il segnale
unsigned int dataPos;
std::vector<int> dataIntvl;
unsigned int curTime;
unsigned int* dataPos;
//funzioni ausiliarie
void calcRotWithG(unsigned int index);
@@ -27,10 +24,10 @@ class Sensore : public PieceInterface{
public:
Sensore(rb::Vector3 coords, _Float16 mass);
Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, int min, int max, std::vector<std::vector<float>> data);
Sensore(rb::Vector3 coords, _Float16 mass, unsigned int* st, std::vector<std::vector<float>> data);
~Sensore();
void update(unsigned int pos) override;
void update(sf::Clock cl) override;
sf::Shape* draw(ReferencePlane plane) override;
//funzioni specifiche
+3 -26
View File
@@ -9,11 +9,9 @@ Sensore::Sensore(rb::Vector3 coords, _Float16 mass){
initialize_shapes(sensore_Dim);
}
Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, int min, int max, std::vector<std::vector<float>> data) : Sensore(coords, mass){
Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int* st, std::vector<std::vector<float>> data) : Sensore(coords, mass){
dataPos = st;
this->dataIntvl = {min, max};
initCSV(data);
curTime = 0;
}
@@ -45,26 +43,13 @@ void Sensore::initCSV(std::vector<std::vector<float>> data){
void Sensore::update(sf::Clock cl){
// Aggiorno la posizione nei dati
curTime += cl.getElapsedTime().asMilliseconds();
/*
if (timeData[dataPos]){
}
*/
/*
if (timeData[dataPos] < currTime && dataIntvl - dataPos > 0) { //aggiorno solo se ho cambiato posizione
dataPos++;
//calcolo la posizione e velocità
calcRotWithG(dataPos);
calcRotWithG(*dataPos);
body.setAcc(rb::Vector3{accData[dataPos]});
body.setAcc(rb::Vector3{accData[*dataPos]});
body.step(cl);
}
*/
}
@@ -118,13 +103,5 @@ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori
}
void Sensore::setIntervall(int min, int max){
this->dataIntvl = {min, max};
}
void Sensore::setPos(int &pos){
this->dataPos = pos;
}
/////////////// cinematica inversa
+1 -1
View File
@@ -65,7 +65,7 @@ void State::update(){
for(PieceInterface* p : pieces){
p->update(*pos);
p->update(clock);
}
for(JointInterface* j : joints){
j->movechild();
+7 -5
View File
@@ -37,7 +37,7 @@ int main() {
//Costruisco la GUI
State gs(800, 600, "Visualizzatore passo",&maj,&min,&pos);
gs.window.setFramerateLimit(60);
gs.window.setFramerateLimit(140);
printf("Costruisco gli oggetti\n");
try{
@@ -47,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,900,3000,coscia));
gs.pieces.push_back(new Sensore (rb::Vector3{300,300,300},_Float16( 0.2 ),&pos,coscia));
gs.pieces.push_back(new Caviglia (rb::Vector3{300,300,500},1));
gs.pieces[1]->body.setRot({0,0,0});
@@ -55,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,900,3000,caviglia));
gs.pieces.push_back(new Sensore (rb::Vector3{300,300,500},_Float16( 0.2 ),&pos,caviglia));
gs.pieces.push_back(new Torso(rb::Vector3{300,400,150},2));
@@ -86,12 +86,14 @@ int main() {
//Avvio il loop della GUI
gs.clock.start();
sf::Clock mainClock;
while (gs.window.isOpen())
{
curTime += gs.clock.getElapsedTime().asMilliseconds();
curTime += mainClock.restart().asMilliseconds();
if (curTime > T){
if (gs.play && pos < maj) pos += curTime / T;
curTime = 0;
if (gs.play && pos < maj) pos += 1;
}
// Show update