-
Notifications
You must be signed in to change notification settings - Fork 40
/
trajectoryinterpolator.cpp
51 lines (44 loc) · 1.1 KB
/
trajectoryinterpolator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "trajectoryinterpolator.h"
#include <qdebug.h>
#define MINIMUM_POINTS_COUNT 1
TrajectoryInterpolator::TrajectoryInterpolator(QObject *parent) : QObject(parent)
{
pointsCount = MINIMUM_POINTS_COUNT;
}
void TrajectoryInterpolator::setPointsCount(int pointsCount_)
{
pointsCount = pointsCount_;
if(pointsCount < MINIMUM_POINTS_COUNT) {
pointsCount = MINIMUM_POINTS_COUNT;
}
}
void TrajectoryInterpolator::setStartPoint(Point p)
{
currentTCP = p;
}
void TrajectoryInterpolator::setFinishPoint(Point p)
{
desiredTCP = p;
}
void TrajectoryInterpolator::calculate()
{
trajectoryPoints.clear();
double dx = desiredTCP.x - currentTCP.x;
double dy = desiredTCP.y - currentTCP.y;
double dz = desiredTCP.z - currentTCP.z;
double stepX = dx / pointsCount;
double stepY = dy / pointsCount;
double stepZ = dz / pointsCount;
Point point = currentTCP;
trajectoryPoints.append(point);
for(int i = 0; i < pointsCount; i++) {
point.x += stepX;
point.y += stepY;
point.z += stepZ;
trajectoryPoints.append(point);
}
}
QVector<Point> TrajectoryInterpolator::getTrajectory()
{
return trajectoryPoints;
}