Skip to content
Snippets Groups Projects
Commit 68186ba5 authored by Franz Bethke's avatar Franz Bethke
Browse files

Merge branch 'master' of gitlab.informatik.hu-berlin.de:badenhop/Hochautomatisiertes-Fahren

* 'master' of gitlab.informatik.hu-berlin.de:badenhop/Hochautomatisiertes-Fahren:
  Added readConfigFile() to Environment
parents ac3ba621 0b77eaea
No related merge requests found
...@@ -26,6 +26,7 @@ public: ...@@ -26,6 +26,7 @@ public:
private: private:
ros::NodeHandle nh_; ros::NodeHandle nh_;
std::string name_; std::string name_;
void readConfigFile();
float distance; float distance;
float relativeSpeed; float relativeSpeed;
...@@ -34,17 +35,16 @@ private: ...@@ -34,17 +35,16 @@ private:
ros::Subscriber ussData; ros::Subscriber ussData;
ros::Subscriber camData; ros::Subscriber camData;
void ussDataCallback(const ussDataMsg::ConstPtr & inMsg); void ussDataCallback(const ussDataMsg::ConstPtr & inMsg);
void camDataCallback(const camDataMsg::ConstPtr & inMsg); void camDataCallback(const camDataMsg::ConstPtr & inMsg);
zero_vector<double> x {2}; //Notation like in Kalamanfilter <Wikipedia>
zero_matrix<double> P {2, 2}; vector<double> x {2}; // current state (distance, velocity)^T
zero_matrix<double> F {2, 2}; matrix<double> P {2, 2}; // covariance matrix
zero_matrix<double> Q {2, 2}; matrix<double> F {2, 2}; // dynamic model
zero_vector<double> H {2}; matrix<double> Q {2, 2}; // process error
zero_vector<double> R {1}; vector<double> H {2}; // mesure vector (refers to distance)
vector<double> R {1}; // measurement error
void predict(); void predict();
void update(vector<double> mesVec); void update(vector<double> mesVec);
......
...@@ -2,25 +2,101 @@ ...@@ -2,25 +2,101 @@
#include <ros/ros.h> #include <ros/ros.h>
#include "environment/Environment.h" #include "environment/Environment.h"
#include "exceptions/Exceptions.h"
#include "car/camDataMsg.h" #include "car/camDataMsg.h"
#include "car/environmentDataMsg.h" #include "car/environmentDataMsg.h"
#include "car/ussDataMsg.h" #include "car/ussDataMsg.h"
#include <fstream>
#include <vector>
#include <iterator>
PLUGINLIB_EXPORT_CLASS(car::Environment, nodelet::Nodelet); PLUGINLIB_EXPORT_CLASS(car::Environment, nodelet::Nodelet);
namespace car namespace car
{ {
Environment::Environment(ros::NodeHandle &nh, std::string &name) : Environment::Environment(ros::NodeHandle &nh, std::string &name) :
nh_(nh), nh_(nh)
name_(name), , name_(name)
distance(0), , distance(0)
relativeSpeed(0) {} , relativeSpeed(0)
{
readConfigFile();
}
Environment::Environment() {} Environment::Environment() :
distance(0)
, relativeSpeed(0)
{
readConfigFile();
}
Environment::~Environment() {} Environment::~Environment() {}
void Environment::readConfigFile()
{
// open config file
std::string userHome = getenv("HOME");
std::ifstream configFile;
configFile.open(userHome + "/.CarConfig/environment.config", std::ifstream::in);
if (!configFile.is_open()) { throw FileNotFound(); }
// desired parameters
// read file
std::string contentLine;
while (!configFile.eof())
{
std::getline(configFile, contentLine);
// split this line
std::istringstream iss(contentLine);
std::vector<std::string> words {std::istream_iterator<std::string>(iss), {} };
if ( words.size() > 1 ) // this line contains parameter[at (0)] and value [at (1)]
{
if (words.at(0) == "x1:") {
x(0) = std::stod(words.at(1));
} else if (words.at(0) == "x2:"){
x(1) = std::stof(words.at(1));
} else if (words.at(0) == "p11:"){
P(0, 0) = std::stof(words.at(1));
} else if (words.at(0) == "p12:"){
P(0,1) = std::stof(words.at(1));
} else if (words.at(0) == "p21:"){
P(1,0) = std::stof(words.at(1));
} else if (words.at(0) == "p22:"){
P(1,1) = std::stof(words.at(1));
} else if (words.at(0) == "f11:"){
F(0,0) = std::stof(words.at(1));
} else if (words.at(0) == "f12:"){
F(0,1) = std::stof(words.at(1));
} else if (words.at(0) == "f21:"){
F(1,0) = std::stof(words.at(1));
} else if (words.at(0) == "f22:"){
F(1,1) = std::stof(words.at(1));
} else if (words.at(0) == "q11:"){
Q(0,0) = std::stof(words.at(1));
} else if (words.at(0) == "q12:"){
Q(0,1) = std::stof(words.at(1));
} else if (words.at(0) == "q21:"){
Q(1,0) = std::stof(words.at(1));
} else if (words.at(0) == "q22:"){
Q(1,1) = std::stof(words.at(1));
} else if (words.at(0) == "h1:"){
H(0) = std::stof(words.at(1));
} else if (words.at(0) == "h2:"){
H(1) = std::stof(words.at(1));
} else if (words.at(0) == "r:"){
R(0) = std::stof(words.at(1));
}
}
}
configFile.close();
return;
}
void Environment::onInit() void Environment::onInit()
{ {
NODELET_INFO("Environment::onInit -- START"); NODELET_INFO("Environment::onInit -- START");
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment