Modifica sensore per restituire accelerazione su z
This commit is contained in:
Binary file not shown.
@@ -15,6 +15,8 @@ class Sensore : public PieceInterface{
|
|||||||
std::vector<std::vector<float>> rotData;
|
std::vector<std::vector<float>> rotData;
|
||||||
std::vector<float> timeData;
|
std::vector<float> timeData;
|
||||||
|
|
||||||
|
float gModule;
|
||||||
|
|
||||||
//in che punto sto controllando il segnale
|
//in che punto sto controllando il segnale
|
||||||
unsigned int* dataPos;
|
unsigned int* dataPos;
|
||||||
|
|
||||||
@@ -32,8 +34,8 @@ class Sensore : public PieceInterface{
|
|||||||
|
|
||||||
//funzioni specifiche
|
//funzioni specifiche
|
||||||
void initCSV(std::vector<std::vector<float>> data);
|
void initCSV(std::vector<std::vector<float>> data);
|
||||||
void setIntervall(int min, int max);
|
|
||||||
void setPos(int &pos);
|
float getZ_Acc();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -22,7 +22,7 @@ Sensore::~Sensore(){
|
|||||||
|
|
||||||
void Sensore::initCSV(std::vector<std::vector<float>> data){
|
void Sensore::initCSV(std::vector<std::vector<float>> data){
|
||||||
//timestamp_ns, wx, wy, wz, ax, ay, az, gx, gy, gz
|
//timestamp_ns, wx, wy, wz, ax, ay, az, gx, gy, gz
|
||||||
if (data.size() < 1) throw "Sensor data empty";
|
if (data.size() < 10) throw "Sensor data empty";
|
||||||
float stTime = int64_t( data[0][0] ) ;
|
float stTime = int64_t( data[0][0] ) ;
|
||||||
|
|
||||||
for (std::vector<float> row : data){
|
for (std::vector<float> row : data){
|
||||||
@@ -37,6 +37,14 @@ void Sensore::initCSV(std::vector<std::vector<float>> data){
|
|||||||
accData.push_back(tmpA);
|
accData.push_back(tmpA);
|
||||||
gData.push_back(tmpG);
|
gData.push_back(tmpG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//trovo il modulo di g facendo la media del modulo nei primi 1000 campioni
|
||||||
|
gModule = 0;
|
||||||
|
for(int i = 0; i< data.size()>1000 ? 1000 : 10; i++){
|
||||||
|
gModule += sqrt(pow(gData[i][0],2)+pow(gData[i][1],2)+pow(gData[i][2],2));
|
||||||
|
}
|
||||||
|
gModule = gModule / 1000;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,13 +98,12 @@ sf::Shape* Sensore::draw(ReferencePlane plane){
|
|||||||
void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori della gravità
|
void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori della gravità
|
||||||
int dir = direction == Direction::R ? -1 : 1;
|
int dir = direction == Direction::R ? -1 : 1;
|
||||||
std::vector<float> grav = gData[index];
|
std::vector<float> grav = gData[index];
|
||||||
float modG = sqrt(pow(grav[0],2)+pow(grav[1],2)+pow(grav[2],2));
|
|
||||||
|
|
||||||
//x = mod * cosX -> mod = x/cosx -> cosx = x/mod
|
//x = mod * cosX -> mod = x/cosx -> cosx = x/mod
|
||||||
|
|
||||||
float tmpSinX = -grav[0] / modG;
|
float tmpSinX = -grav[0] / gModule;
|
||||||
float tmpSinY = -grav[1] / modG;
|
float tmpSinY = -grav[1] / gModule;
|
||||||
float tmpSinZ = -grav[2] / modG;
|
float tmpSinZ = -grav[2] / gModule;
|
||||||
|
|
||||||
float tmpAX = acos(dir*tmpSinX);
|
float tmpAX = acos(dir*tmpSinX);
|
||||||
float tmpAY = acos(dir*tmpSinY);
|
float tmpAY = acos(dir*tmpSinY);
|
||||||
@@ -106,5 +113,11 @@ void Sensore::calcRotWithG(unsigned int index){ // calcolo rotazione con valori
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Sensore::getZ_Acc(){
|
||||||
|
int id = *dataPos;
|
||||||
|
float tmpAcc = 0;
|
||||||
|
|
||||||
|
tmpAcc = gModule - sqrt(pow(gData[id][0],2)+pow(gData[id][1],2)+pow(gData[id][2],2));
|
||||||
|
return tmpAcc;
|
||||||
|
}
|
||||||
/////////////// cinematica inversa
|
/////////////// cinematica inversa
|
||||||
@@ -324,6 +324,13 @@ void doGUI(State &gs)
|
|||||||
gs.selectedPlane = (ReferencePlane)currentPlane;
|
gs.selectedPlane = (ReferencePlane)currentPlane;
|
||||||
gs.updateCollections();
|
gs.updateCollections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*////// DA FARE ///////*/
|
||||||
|
|
||||||
|
//Finestra gestione velocità di riproduzione
|
||||||
|
|
||||||
|
//Finestra controllo sovrapposizione
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user