-
Notifications
You must be signed in to change notification settings - Fork 5
Update supervision with better file handling #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
91e8d2c
Replaced IP as identifier for trajectory class
LukasWikander eff39ca
Made new objectData class
LukasWikander 90d56af
Updated CMakeLists
LukasWikander 331a045
Renamed .h files to .hpp
LukasWikander bbe3016
Updated header file references
LukasWikander 0406381
InitializeFromFile method for object data
LukasWikander ba8cfb1
Removed IP from trajectory class
LukasWikander 3b8fbc2
Added a sanity check before parsing file
LukasWikander 05f7680
Updated init of supervisor to handle object files
LukasWikander 15562e7
Added object data based geofence and trajectory check
LukasWikander fb2ddb2
Added permits and forbids methods for geofence
LukasWikander 69797c1
Updated geofence check to something less wordy
LukasWikander a5b8f1f
Added const to non-modifying function in util
LukasWikander ce0e0d8
Ran code formatter
LukasWikander c73d6d1
Merge branch 'dev' into fix_updateSupervisionWithCoolStuff
LukasWikander 49fbfda
Moved geofence initialization to geofence class
LukasWikander 770d5c7
Updated main to reflect new geofence initialization
LukasWikander c564826
Niced up trajectory class a bit
LukasWikander 1cbf347
Updated name of file
LukasWikander 0c3d537
Minor fix
LukasWikander 3224114
Removed unnecessary newline from debug print
LukasWikander e04b6bb
Added a copy constructor and fixed a bad buffer size
LukasWikander 06112b6
Angle conversion fixed in ISO.py
LukasWikander bdb8a8d
Catch TypeError to handle tuples in ISO.py
LukasWikander dd0ec6d
Library fix include for test script
LukasWikander d645e7b
Added poll functionality to ISO.py tool
LukasWikander 5aece44
CC status -> RUNNING when in running state
LukasWikander bdea3c7
Added error printouts when failing assertions
LukasWikander 64b7593
Added a sleep after awaiting OBCState transition to running, to allow…
LukasWikander 5a054c9
Enabled the test to be run by jenkins
LukasWikander 991d96a
Set the sleep time in test to be exactly 0.01 s after breaking the ge…
LukasWikander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #ifndef GEOFENCE_H | ||
| #define GEOFENCE_H | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
| #include <regex> | ||
|
|
||
| #include "util.h" | ||
| #include "positioning.h" | ||
|
|
||
| class Geofence | ||
| { | ||
| public: | ||
|
|
||
| Geofence() = default; | ||
| ~Geofence() { polygonPoints.clear(); } | ||
| Geofence(const Geofence& other); | ||
|
|
||
| std::vector<CartesianPosition> polygonPoints; | ||
| std::string name = ""; | ||
| bool isPermitted = false; | ||
| double minHeight = 0; | ||
|
LukasWikander marked this conversation as resolved.
|
||
| double maxHeight = 0; | ||
|
|
||
| bool permits(const CartesianPosition &position) const; | ||
| bool forbids(const CartesianPosition &position) const; | ||
|
|
||
| void initializeFromFile(const std::string& fileName); | ||
|
|
||
| private: | ||
| static const std::regex fileHeaderPattern; | ||
| static const std::regex fileLinePattern; | ||
| static const std::regex fileFooterPattern; | ||
| }; | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #ifndef OBJECTDATA_HPP | ||
| #define OBJECTDATA_HPP | ||
| #include "trajectory.hpp" | ||
|
|
||
| class ObjectConfiguration | ||
| { | ||
| public: | ||
| ObjectConfiguration(); | ||
| ObjectConfiguration(const std::string &fromFile); | ||
| Trajectory trajectory; | ||
| in_addr_t ip = 0; | ||
| uint32_t id = 0; | ||
|
|
||
| void initializeFromFile(const std::string &fileName); | ||
| }; | ||
|
|
||
| #endif // OBJECTDATA_HPP |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,130 @@ | ||
| #include "geofence.h" | ||
| #include <fstream> | ||
|
|
||
| #include "geofence.hpp" | ||
| #include "util.h" | ||
| #include "regexpatterns.hpp" | ||
|
|
||
| const std::regex Geofence::fileHeaderPattern("GEOFENCE;([a-zA-Z0-9]+);(" + RegexPatterns::intPattern | ||
| + ");(permitted|forbidden);(" + RegexPatterns::floatPattern + ");(" | ||
| + RegexPatterns::floatPattern + ");"); | ||
| const std::regex Geofence::fileLinePattern("LINE;(" + RegexPatterns::floatPattern + ");(" | ||
| + RegexPatterns::floatPattern + ");ENDLINE;"); | ||
| const std::regex Geofence::fileFooterPattern("ENDGEOFENCE;"); | ||
|
|
||
| Geofence::Geofence(const Geofence& other) { | ||
| this->name = other.name; | ||
| this->maxHeight = other.maxHeight; | ||
| this->minHeight = other.minHeight; | ||
| this->isPermitted = other.isPermitted; | ||
| this->polygonPoints = std::vector<CartesianPosition>(other.polygonPoints); | ||
| } | ||
|
|
||
| /*! | ||
| * \brief parseGeofenceFile Parse the given file into a Geofence object | ||
| * \param geofenceFile A string representing the filename relative to the geofence directory. | ||
| */ | ||
| void Geofence::initializeFromFile(const std::string &fileName) { | ||
|
|
||
| using namespace std; | ||
| char geofenceDirPath[PATH_MAX]; | ||
| ifstream file; | ||
| smatch match; | ||
| string line; | ||
| string errMsg; | ||
|
|
||
| bool isHeaderParsedSuccessfully = false; | ||
| unsigned long nPoints = 0; | ||
|
|
||
| UtilGetGeofenceDirectoryPath(geofenceDirPath, sizeof (geofenceDirPath)); | ||
| string geofenceFilePath(geofenceDirPath); | ||
| geofenceFilePath += fileName; | ||
|
|
||
| file.open(geofenceFilePath); | ||
| if (!file.is_open()) { | ||
| throw ifstream::failure("Unable to open file <" + geofenceFilePath + ">"); | ||
| } | ||
|
|
||
| errMsg = "Encountered unexpected end of file while reading file <" + geofenceFilePath + ">"; | ||
|
|
||
| for (unsigned long lineCount = 0; getline(file, line); lineCount++) { | ||
| if (lineCount == 0) { | ||
| if (regex_search(line, match, fileHeaderPattern)) { | ||
| name = match[1]; | ||
| nPoints = stoul(match[2]); | ||
| polygonPoints.reserve(nPoints); | ||
| isPermitted = match[3].compare("permitted") == 0; | ||
| minHeight = stod(match[4]); | ||
| minHeight = stod(match[5]); | ||
| isHeaderParsedSuccessfully = true; | ||
| } | ||
| else { | ||
| errMsg = "The header of geofence file <" + geofenceFilePath + "> is badly formatted"; | ||
| break; | ||
| } | ||
| } | ||
| else if (lineCount > 0 && !isHeaderParsedSuccessfully) { | ||
| errMsg = "Attempt to parse geofence file <" + geofenceFilePath + "> before encountering header"; | ||
| break; | ||
| } | ||
| else if (lineCount > nPoints + 1) { | ||
| errMsg = "Geofence line count of file <" + geofenceFilePath | ||
| + "> does not match specified line count"; | ||
| break; | ||
| } | ||
| else if (lineCount == nPoints + 1) { | ||
| if (regex_search(line, match, fileFooterPattern)) { | ||
| file.close(); | ||
| LogMessage(LOG_LEVEL_DEBUG, "Closed <%s>", geofenceFilePath.c_str()); | ||
| return; | ||
| } | ||
| else { | ||
| errMsg = "Final line of geofence file <" + geofenceFilePath + "> badly formatted"; | ||
| break; | ||
| } | ||
| } | ||
| else { | ||
| if (regex_search(line, match, fileLinePattern)) { | ||
| CartesianPosition pos; | ||
| pos.xCoord_m = stod(match[1]); | ||
| pos.yCoord_m = stod(match[2]); | ||
| pos.zCoord_m = (maxHeight + minHeight) / 2.0; | ||
| pos.isPositionValid = true; | ||
| pos.heading_rad = 0; | ||
| pos.isHeadingValid = false; | ||
|
|
||
| LogMessage(LOG_LEVEL_DEBUG, "Point: (%.3f, %.3f, %.3f)", | ||
| pos.xCoord_m, | ||
| pos.yCoord_m, | ||
| pos.zCoord_m); | ||
| polygonPoints.push_back(pos); | ||
| } | ||
| else { | ||
| errMsg = "Line " + to_string(lineCount) + " of geofence file <" | ||
| + geofenceFilePath + "> badly formatted"; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| file.close(); | ||
| LogMessage(LOG_LEVEL_DEBUG, "Closed <%s>", geofenceFilePath.c_str()); | ||
| LogMessage(LOG_LEVEL_ERROR, errMsg.c_str()); | ||
| throw invalid_argument(errMsg); | ||
| } | ||
|
|
||
| bool Geofence::forbids(const CartesianPosition &position) const { | ||
| return !permits(position); | ||
| } | ||
|
|
||
| bool Geofence::permits(const CartesianPosition &position) const { | ||
| char isInPolygon = UtilIsPointInPolygon(position, polygonPoints.data(), | ||
| static_cast<unsigned int>(polygonPoints.size())); | ||
| if (isInPolygon < 0) { | ||
| throw std::invalid_argument("No points in geofence"); | ||
| } | ||
|
|
||
| if ((isPermitted && isInPolygon) | ||
| || (!isPermitted && !isInPolygon)) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.