Cambio posizione aggoirnamento dati (da concludere)
This commit is contained in:
@@ -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(){}
|
||||
};
|
||||
|
||||
@@ -18,8 +18,8 @@ class Sensore : public PieceInterface{
|
||||
|
||||
//in che punto sto controllando il segnale
|
||||
unsigned int dataPos;
|
||||
unsigned int dataIntvl;
|
||||
|
||||
std::vector<int> 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<std::vector<float>> data);
|
||||
Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, int min, int max, std::vector<std::vector<float>> 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<std::vector<float>> data);
|
||||
void setIntervall(int min, int max);
|
||||
void setPos(int &pos);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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<std::vector<float>> data) : Sensore(coords, mass){
|
||||
Sensore::Sensore(rb::Vector3 coords, _Float16 mass, unsigned int st, int min, int max, std::vector<std::vector<float>> 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<std::vector<float>> 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<std::vector<float>> 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
|
||||
+13
-9
@@ -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();
|
||||
|
||||
|
||||
+22
-3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user