-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLinkTrjPVTFile.cpp
69 lines (56 loc) · 1.35 KB
/
LinkTrjPVTFile.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "StdAfx.h"
#include "LinkTrjPVTFile.h"
LinkTrjPVTFile::LinkTrjPVTFile(void)
{
}
LinkTrjPVTFile::~LinkTrjPVTFile(void)
{
for(int i=0; i<m_axNum; i++)
{
delete[] m_P[i]; delete[] m_V[i];
}
delete[] m_P; delete[] m_V; delete[] m_T;
}
void LinkTrjPVTFile::InitAxes(int axNum, int ptNum)
{
m_axNum = axNum; m_ptNum = ptNum;
m_P = new double* [m_axNum];
m_V = new double* [m_axNum];
m_T = new double[m_ptNum];
for(int i=0; i<m_axNum; i++)
{
m_P[i] = new double[m_ptNum]; m_V[i] = new double[m_ptNum];
for(int j=0; j<m_ptNum; j++)
{
m_P[i][j] = m_V[i][j] = m_T[j] = 0.0;
}
}
m_cnt = 0;
};
// CKim - Set one pvt point
void LinkTrjPVTFile::AddPVT(int idx, uunit p[], uunit v[], uunit t)
{
for(int i=0; i<m_axNum; i++)
{
m_P[i][idx] = p[i]; m_V[i][idx] = v[i];
}
m_T[idx] = t;
}
const Error* LinkTrjPVTFile::NextSegment( uunit pos[], uunit vel[], uint8 &time )
{
// CKim - this is the function called by CAN service to send trajectory
// pos/vel is the array of position and velocity, time is duration of the segment
// return 0 for the time to end.
if(m_cnt >= m_ptNum) { time = 0; }
else
{
for(int i=0; i<m_axNum; i++)
{
pos[i] = m_P[i][m_cnt]; vel[i] = m_V[i][m_cnt];
if(m_cnt == 0) { time = m_T[m_cnt]; }
else { time = m_T[m_cnt] -m_T[m_cnt-1]; }
}
m_cnt++;
}
return 0;//&CML::Error::OK;
}