forked from embeye/QEmbeddedEye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MotorMatrix.cpp
61 lines (45 loc) · 1.89 KB
/
MotorMatrix.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
//
// Created by aman on 15/03/17.
//
#include "MotorMatrix.h"
MotorMatrix::MotorMatrix() {}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MotorMatrix::~MotorMatrix()
{
motorTargets.clear();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// implementation of utility functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void MotorMatrix::readToBufferPointer(std::string fileName, float *buffer, long sizeOfBufferElements)
{
FILE *f = fopen(fileName.c_str(), "rb");
if (fread(buffer, sizeof(float), sizeOfBufferElements, f)){ std::cout << "File read sucess!\n"; }
else{ std::cout << "Failed to read File!\n"; }
fclose(f);
}
void MotorMatrix ::loadMotorTargetsLUT() {
motorTargets.clear();
float *buffer;
buffer = new float[FRAME_HEIGHT * FRAME_WIDTH * MATRIX_SIZE];
readToBufferPointer(MOTOR_LUT_FILE_PATH, buffer, FRAME_HEIGHT * FRAME_WIDTH * MATRIX_SIZE);
motorTargets.resize(MATRIX_SIZE);
for (int i = 0; i < MATRIX_SIZE; ++i) {
motorTargets[i].resize(FRAME_WIDTH);
for (int j = 0; j < FRAME_WIDTH; ++j)
motorTargets[i][j].resize(FRAME_HEIGHT);
}
//copy into vector
float*ptr = buffer;
for (int i = 0; i < MATRIX_SIZE; i++)
for (int j = 0; j < FRAME_WIDTH; j++)
for (int k = 0; k < FRAME_HEIGHT; k++)
motorTargets[i][j][k] = *ptr++;
//free(buffer);
delete buffer;
}
void MotorMatrix ::getPanTiltFromCoordinates(int xPixCoordinate, int yPixCoordinate, float *panTargetVal,
float *tiltTargetVal) {
*panTargetVal = motorTargets[0][xPixCoordinate][yPixCoordinate];
*tiltTargetVal = motorTargets[1][xPixCoordinate][yPixCoordinate];
}