-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
643b44a
commit 031ec31
Showing
17 changed files
with
1,160 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | ||
project(Ranger) | ||
add_executable(ranger "main.cpp" "ranger.cpp" "laser.cpp" | ||
"radar.cpp" "sonar.cpp" "user_interface.cpp" | ||
"ranger_fusion_interface.cpp" "ranger_fusion.cpp") |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,19 @@ | ||
// 11970720 | ||
// Vincent Jadraque | ||
|
||
#include "laser.h" | ||
|
||
Laser::Laser() | ||
{ | ||
setModel("UTM-XXL"); | ||
setBaud(38400); // default; 38400 or 115200 | ||
setPort(0); // default; 0-20 | ||
setFieldOfView(180); | ||
setAngularResolution(15); // default; 15 or 30 | ||
setMaxDistance(8.0); | ||
} | ||
|
||
Laser::~Laser() | ||
{ | ||
// for demonstration only | ||
} |
This file contains 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,13 @@ | ||
#ifndef LASER_H | ||
#define LASER_H | ||
|
||
#include "ranger.h" | ||
|
||
class Laser : public Ranger | ||
{ | ||
public: | ||
Laser(); | ||
~Laser(); | ||
}; | ||
|
||
#endif // LASER_H |
This file contains 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,76 @@ | ||
// 11970720 | ||
// Vincent Jadraque | ||
|
||
#include <iostream> // cout | ||
#include <unistd.h> // usleep | ||
|
||
#include "ranger.h" | ||
#include "laser.h" | ||
#include "sonar.h" | ||
#include "radar.h" | ||
#include "user_interface.h" | ||
#include "ranger_fusion.h" | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
// initialise laser sensor | ||
Laser laser; | ||
|
||
// query fixed parameters | ||
showFixedParameters(laser); | ||
cout << "Field of View ............. " << laser.getFieldOfView() << "\n\n" << endl; | ||
// configure rest of parameters | ||
askBaud(laser); | ||
askPort(laser); | ||
askAngularResolution(laser); | ||
showNumberOfSamples(laser); | ||
std::cout << "\n\n" << std::endl; | ||
// printReadings(laser); | ||
|
||
// initialise radar sensor | ||
Radar radar; | ||
|
||
// query fixed parameters | ||
showFixedParameters(radar); | ||
// configure rest of parameters | ||
askFOV(radar); | ||
askBaud(radar); | ||
askPort(radar); | ||
showNumberOfSamples(radar); | ||
std::cout << "\n\n" << std::endl; | ||
// printReadings(radar); | ||
|
||
// initialise sonar sensor | ||
Sonar sonar; | ||
|
||
// query fixed parameters | ||
showFixedParameters(sonar); | ||
cout << "Field of View ............. " << sonar.getFieldOfView() << "\n\n" << endl; | ||
// configure rest of parameters | ||
askBaud(sonar); | ||
askPort(sonar); | ||
showNumberOfSamples(sonar); | ||
std::cout << "\n\n" << std::endl; | ||
// printReadings(sonar); | ||
|
||
std::vector<Ranger*> rangers; | ||
rangers = {&laser, &radar, &sonar}; | ||
|
||
RangerFusion fusion(rangers); | ||
int a = 1; | ||
askFusionType(fusion); | ||
|
||
while(1) | ||
{ | ||
std::cout << "\n\nData set " << a << ":" << std::endl; | ||
printRawData(fusion); | ||
|
||
printFusedData(fusion); | ||
usleep(2000000); | ||
a++; | ||
} | ||
|
||
return 0; | ||
} |
This file contains 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,27 @@ | ||
// 11970720 | ||
// Vincent Jadraque | ||
|
||
#include "radar.h" | ||
|
||
Radar::Radar() | ||
{ | ||
setModel("RAD-001"); | ||
setBaud(38400); // default; 38400 or 115200 | ||
setPort(0); // default; 0-20 | ||
setFieldOfView(20); // default; 20 or 40 | ||
setMaxDistance(16.0); | ||
setNumberOfSamples(1); | ||
} | ||
|
||
Radar::~Radar() | ||
{ | ||
// for demonstration purposes only | ||
} | ||
|
||
int Radar::getNumberOfSamples() | ||
{ | ||
setNumberOfSamples(1); | ||
return number_of_samples_; | ||
} | ||
|
||
|
This file contains 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,15 @@ | ||
#ifndef RADAR_H | ||
#define RADAR_H | ||
|
||
#include "ranger.h" | ||
|
||
class Radar : public Ranger | ||
{ | ||
public: | ||
Radar(); | ||
~Radar(); | ||
|
||
int getNumberOfSamples(); | ||
}; | ||
|
||
#endif // RADAR_H |
This file contains 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,185 @@ | ||
// 11970720 | ||
// Vincent Jadraque | ||
|
||
#include "ranger.h" | ||
|
||
#include <string.h> | ||
|
||
|
||
Ranger::Ranger() | ||
{ | ||
min_distance_ = 0.2; | ||
setMeanRNG(6.0); | ||
setStdDevRNG(5.0); | ||
angular_resolution_ = 15; | ||
} | ||
|
||
Ranger::~Ranger() | ||
{ | ||
// demonstration only | ||
} | ||
|
||
std::string Ranger::getModel() const | ||
{ | ||
return model_; | ||
} | ||
|
||
bool Ranger::checkBaud(int baud) | ||
{ | ||
checkOption(baud); | ||
} | ||
|
||
int Ranger::getBaud() const | ||
{ | ||
return baud_; | ||
} | ||
|
||
void Ranger::setBaud(int baud) | ||
{ | ||
baud_ = baud; | ||
} | ||
|
||
// check whether port chosen is between 0 and 20 | ||
bool Ranger::checkPort(int port) | ||
{ | ||
if(port >= 0 && port < 21) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
void Ranger::setPort(int port) | ||
{ | ||
char portString[3] = {0}; | ||
|
||
memset(port_, '\0', sizeof port_); | ||
strcat(port_, "/dev/ttyACM"); | ||
|
||
sprintf(portString, "%d", port); | ||
|
||
strcat(port_, portString); | ||
} | ||
|
||
char *Ranger::getPort() | ||
{ | ||
return port_; | ||
} | ||
|
||
bool Ranger::checkFieldOfView(int test_FOV) | ||
{ | ||
checkOption(test_FOV); | ||
} | ||
|
||
int Ranger::getFieldOfView() const | ||
{ | ||
return field_of_view_; | ||
} | ||
|
||
void Ranger::setFieldOfView(int field_of_view) | ||
{ | ||
field_of_view_ = field_of_view; | ||
} | ||
|
||
bool Ranger::checkAngularResolution(int angular_resolution) | ||
{ | ||
checkOption(angular_resolution); | ||
} | ||
|
||
int Ranger::getAngularResolution() | ||
{ | ||
return angular_resolution_; | ||
} | ||
|
||
void Ranger::setAngularResolution(int angular_resolution) | ||
{ | ||
angular_resolution_ = angular_resolution; | ||
} | ||
|
||
double Ranger::getMaxDistance() const | ||
{ | ||
return max_distance_; | ||
} | ||
|
||
void Ranger::setMaxDistance(double max_distance) | ||
{ | ||
max_distance_ = max_distance; | ||
} | ||
|
||
double Ranger::getMinDistance() const | ||
{ | ||
return min_distance_; | ||
} | ||
|
||
void Ranger::setMinDistance(double min_distance) | ||
{ | ||
min_distance_ = min_distance; | ||
} | ||
|
||
int Ranger::getNumberOfSamples() | ||
{ | ||
number_of_samples_ = 1 + 2 * ((field_of_view_/2)/angular_resolution_); | ||
return number_of_samples_; | ||
} | ||
|
||
void Ranger::setNumberOfSamples(int number_of_samples) | ||
{ | ||
number_of_samples_ = number_of_samples; | ||
} | ||
|
||
double Ranger::getStdDevRNG() const | ||
{ | ||
return std_dev_RNG_; | ||
} | ||
|
||
std::vector<double> Ranger::readSensor() | ||
{ | ||
std::random_device rd; | ||
std::default_random_engine generator(rd()); | ||
|
||
std::normal_distribution<double> normal(getMeanRNG(), getStdDevRNG()); | ||
|
||
int n = getNumberOfSamples(); | ||
std::vector<double> vi1 = {}; | ||
|
||
for(int i = 0; i < n; i++) | ||
{ | ||
// add check to limit max value | ||
double v = normal(generator); | ||
if(v > getMaxDistance()) | ||
vi1.push_back(getMaxDistance()); | ||
else if(v < getMinDistance()) | ||
vi1.push_back(getMinDistance()); | ||
else | ||
vi1.push_back(v); | ||
} | ||
return vi1; | ||
} | ||
|
||
void Ranger::setStdDevRNG(double std_dev_RNG) | ||
{ | ||
std_dev_RNG_ = std_dev_RNG; | ||
} | ||
|
||
double Ranger::getMeanRNG() const | ||
{ | ||
return mean_RNG_; | ||
} | ||
|
||
void Ranger::setMeanRNG(double mean_RNG) | ||
{ | ||
mean_RNG_ = mean_RNG; | ||
} | ||
|
||
bool Ranger::checkOption(int input) | ||
{ | ||
return (input == 1 || input == 2) ? true : false; | ||
} | ||
|
||
void Ranger::setModel(const std::string &model) | ||
{ | ||
model_ = model; | ||
} |
Oops, something went wrong.