Roomba Controller Dashboard 1
A GUI and TCP client application that is used to control a Roomba for Computer Engineering 2880 @ Iowa State
Loading...
Searching...
No Matches
HoleManager.cpp
Go to the documentation of this file.
1
5#include <iostream>
6#include "HoleManager.hpp"
7#include "Field.hpp"
8
10 holes = std::make_unique<std::vector<Hole>>();
11 holeMeasurements = std::make_unique<std::vector<Pose2D>>();
12}
13
14void HoleManager::addHole(const Pose2D& cornerOne, const Pose2D& cornerTwo) {
15 double size = cornerOne.distanceTo(cornerTwo) / sqrt(2);
16 this->holes->push_back(Hole(cornerOne, cornerTwo, size));
17}
18
19void HoleManager::addHole(const Hole& hole) {
20 this->holes->push_back(hole);
21}
22
23Hole HoleManager::getHole(uint8_t index) {
24 if (index > holes->size()) {
25 return {NAN, NAN, NAN, NAN, NAN};
26 }
27 else {
28 return holes->data()[index];
29 }
30}
31
32std::vector<Hole> HoleManager::getHoles() {
33 std::vector<Hole> toCpy;
34 for (uint8_t i = 0; i < holes->size(); i++) {
35 toCpy.push_back(holes->data()[i]); // Unsafe lol
36 }
37 return toCpy;
38}
39
40void HoleManager::addPoint(const Pose2D& position) {
41 bool foundMatch = false;
42 this->holeMeasurements->push_back(position);
43 for (uint16_t i = 0; i < this->holes->size(); i++) {
44 if (this->holes->data()[i].pointCouldBeMemberOfHole(position)) {
45 this->holes->data()[i].addPoint(position);
46 foundMatch = true;
47 break;
48 }
49 }
50 if (!foundMatch) {
51 this->holes->push_back(Hole(position, HOLE_SIZE));
52 }
53}
54
55// deiscretization step
57
58 // shoot out a small line from the position in the dircection of the heading
59 /*
60 for (uint16_t i = 0; i < this->holeMeasurements->size(); i++) {
61 Pose2D initial = this->holeMeasurements->at(i);
62 Pose2D pose2(this->holeMeasurements->at(i)); // should copy
63 pose2.translateByMagnitude(HOLE_SIZE * 0.5);
64 if (position.isOnLine(initial, pose2)) {
65 return true;
66 }
67 }
68 */
69
70 for (uint8_t i = 0; i < this->holes->size(); i++) {
71 //std::cout << this->holes->at(i) << std::endl;
72 if (this->holes->at(i).isInSquare(position)) {
73 // std::cout << "failed for: " << position.getX() << ", " << position.getY() << std::endl;
74 return true;
75 }
76 }
77 return false;
78}
79
81 // for every hole return a few points around the square
82
83 std::vector<Pose2D> toReturn;
84 for (uint16_t i = 0; i < this->holes->size(); i++) {
85 std::vector<Pose2D> placements = this->holes->at(i).getSuggestedNodePlacements();
86 for (uint16_t j = 0; j < placements.size(); j++) {
87 toReturn.push_back(placements.at(j));
88 }
89 }
90 return toReturn;
91}
92
93// weighting step
94bool HoleManager::lineIntersectsAnyHoleMeasurement(const Pose2D& positionOne, const Pose2D& positionTwo) {
95 // we have a pose of each measurement
96 // have to make the rectangle and the expected line
97
98 /*
99 for (uint16_t i = 0; i < this->holeMeasurements->size(); i++) {
100 // for every point make the rectangle
101 Rectangle rect = makeRectangleFromLine(positionOne, positionTwo, MEASUREMENT_WIDTH);
102 if (lineIntersectsRectangle(positionOne.getX(), positionOne.getY(), positionTwo.getX(), positionTwo.getY(), rect.r1.getX(), rect.r1.getY(), rect.r2.getX(), rect.r2.getY(), rect.r3.getX(), rect.r3.getY(), rect.r4.getX(), rect.r4.getY())) {
103 return true;
104 }
105 }
106 */
107
108 for (uint16_t i = 0; i < this->holes->size(); i++) {
109 if (this->holes->at(i).lineIntersectsHole(positionOne, positionTwo)) {
110 return true;
111 }
112 }
113
114 return false;
115}
116
117void HoleManager::offsetAll(const Pose2D& offset) const {
118 for (uint16_t i = 0; i < this->holes->size(); i++) {
119 this->holes->at(i).offset(offset);
120 }
121 for (uint16_t i = 0; i < this->holeMeasurements->size(); i++) {
122 this->holeMeasurements->at(i).plus(offset);
123 }
124}
#define HOLE_SIZE
Definition Hole.hpp:14
void offsetAll(const Pose2D &offset) const
bool lineIntersectsAnyHoleMeasurement(const Pose2D &positionOne, const Pose2D &positionTwo)
void addPoint(const Pose2D &position)
bool nodeCollides(Pose2D position)
Hole getHole(uint8_t index)
std::vector< Hole > getHoles()
std::vector< Pose2D > getSuggestedNodePlacements()
void addHole(const Hole &hole)
Definition Hole.hpp:20
double distanceTo(const Pose2D &other) const
Definition Pose2D.cpp:86