[英]How to calculate total distance covered by a sensor from its set of locations which are 3D points?
I am using Qt GUI to track the motion of a sensor. 我正在使用Qt GUI跟踪传感器的运动。 The mainwindow.cpp file is: mainwindow.cpp文件是:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ATC3DG.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include "QTimer"
#include "qtimer.h"
#include "math.h"
double square(double x)
{
return x*x;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_start_clicked()
{
points.clear(); //points is a global std::vector<cv::Point3> declared in mainwindow.h
errorCode = InitializeBIRDSystem();
errorCode = GetBIRDSystemConfiguration(&ATC3DG.m_config);
id = 0;
errorCode = SetSystemParameter(SELECT_TRANSMITTER, &id, sizeof(id));
EM_time = new QTimer(this);
connect(EM_time, SIGNAL(timeout()), this, SLOT(showValues()));
EM_time->start();
}
void MainWindow::showValues()
{
EM_time->stop();
pRecord = &record;
{
sensorID = 0;
{
errorCode = GetAsynchronousRecord(sensorID, pRecord, sizeof(record));
unsigned int status = GetSensorStatus(sensorID);
if ( status == VALID_STATUS )
{
points.push_back(cv::Point3f(record.x, record.y, record.z));
QString str;
str.sprintf("%f, %f, %f",record.x, record.y, record.z );
this->ui->label->setText(str);
}
}
}
EM_time->start();
}
void MainWindow::on_stop_clicked()
{
EM_time->stop();
double sum = 0;
double dist;
QString str;
for (int i=0; i<points.size()-1; i++)
{
dist = sqrt(square(points[i].x - points[i+1].x) + square(points[i].y - points[i+1].y) + square(points[i].z - points[i+1].z));
sum = sum+dist;
}
str.sprintf("%d cm", sum*2.54);
this->ui->distance->setText(str);
}
ATC3DG.h is the header file of the sensor. ATC3DG.h是传感器的头文件。 record.x, record.y, record.z gives the 3D location of x, y and z location of the sensor in inches . record.x,record.y,record.z以英寸为单位给出传感器x,y和z位置的3D位置。 Basically what I am doing is, when I click the start button, the sensor is switched on and the QTimer starts with its signal emitted during timeouts and the showvalues() function will start to execute. 基本上,我要做的是,当我单击开始按钮时,传感器已打开,并且QTimer以其在超时期间发出的信号开始,并且showvalues()函数将开始执行。 This function displays the position of the sensor in label of the Qt GUI. 此功能在Qt GUI的标签中显示传感器的位置。 During this loop, points will be filled with all the position values of the sensor. 在此循环期间,将用传感器的所有位置值填充点 。
The stop button stops the timer and calculates the distance using all the points containing in the points vector. 停止按钮将停止计时器,并使用点向量中包含的所有点来计算距离。 This is done using: 使用以下命令完成此操作:
double sum=0;
double dist;
for (int i=0; i<points.size()-1; i++)
{
dist = sqrt(square(points[i].x - points[i+1].x) + square((int)points[i].y - (int)points[i+1].y) + square(points[i].z - points[i+1].z));
sum = sum+dist;
}
The sum is giving me totally weird values. 这笔钱给了我完全奇怪的价值。 For example, when the sensor has moved only about 5 or 6 inches, it is showing values in the range of 100s and like that. 例如,当传感器仅移动了大约5或6英寸时,它显示的值在100s之内,并且如此。
My mainwindow.h file is: 我的mainwindow.h文件是:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ATC3DG.h"
#include "QTimer"
#include <opencv2/core/core.hpp>
namespace Ui {
class MainWindow;
}
class CSystem
{
public:
SYSTEM_CONFIGURATION m_config;
};
class CSensor
{
public: SENSOR_CONFIGURATION m_config;
};
class CXmtr
{
public: TRANSMITTER_CONFIGURATION m_config;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void on_start_clicked();
void showValues();
void on_stop_clicked();
private:
Ui::MainWindow *ui;
private:
DOUBLE_POSITION_ANGLES_RECORD record, *pRecord;
CSystem ATC3DG;
CSensor *pSensor;
CXmtr *pXmtr;
int errorCode;
int sensorID;
int i;
short id;
QTimer *EM_time;
std::vector<cv::Point3f> points;
};
#endif // MAINWINDOW_H
issues I can see in your code: 我在您的代码中看到的问题:
GetAsynchronousRecord
suggest asynchronous action and you are using value immediately! GetAsynchronousRecord
建议异步操作,您将立即使用值! I don't known this library but this looks suspicious. 我不知道这个图书馆,但是看起来很可疑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.