Question: I cannot get this C++ program to run. need some help please --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // main.cpp // // promary driver of the GPS-Satellite system #include #include
I cannot get this C++ program to run. need some help please




---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// main.cpp
//
// promary driver of the GPS-Satellite system
#include
#include "GPS.h"
#include "Satellite.h"
int main()
{
GPS gps("raw_gps.dat",
"noise_gps.dat",
0.0,
0.0,
5.0,
10.0,
20.0);
Satellite satellite("filtered_gps.dat");
satellite.registerGPS(&gps);
double time = 0.0;
while (time
{
satellite.updateSystem(2.0);
time += 2.0;
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// AlphaBetaFilter.cpp
//
// Contains the implementation for a 2D alpha beta filter
//
#include "AlphaBetaFilter.h"
// TODO: Implement the class here!
class AlphaBetaFilter { public: void setAlphaBeta(double a, double b); private: double a; double b; };
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// AlphaBetaFilter.h
//
// Contains the class definition for a 2D alpha beta filter
//
#pragma once
#include
class AlphaBetaFilter
{
// TODO: define the class!
void AlphaBetaFilter::setAlphaBeta(double a, double b) { this -> a = a; this -> b = b; }
};
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GPS.cpp
//
//
#include
#include
#include "GPS.h"
static const double PI = 4.0 * std::atan(1.0);
GPS::GPS(const std::string &rawLogFileName,
const std::string &noiseLogFileName,
double x,
double y,
double vx,
double vy,
double u)
{
rawLog.open(rawLogFileName.c_str());
noiseLog.open(noiseLogFileName.c_str());
xpos = x;
ypos = y;
xvel = vx;
yvel = vy;
uncertainty = u;
rawLog
noiseLog
}
std::pair
{
return {xpos, ypos};
}
std::pair
{
return {xvel, yvel};
}
std::pair
{
xpos += xvel * dt;
ypos += yvel * dt;
rawLog
std::mt19937 rng;
rng.seed(static_cast
std::uniform_real_distribution
std::uniform_real_distribution
double theta = thetadis(rng);
double radius = std::sqrt(dis(rng)) * uncertainty;
std::pair
uncertainState.first = xpos + radius * std::cos(theta);
uncertainState.second = ypos + radius * std::sin(theta);
noiseLog
return uncertainState;
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// GPS.h
//
// the GPS class defined here is a simple data reporter. it maintains its own
// state information and provides it to consumers with noise layered on. the
// noise generated is just random within some uncertainty.
//
#pragma once
#include
#include
#include
class GPS
{
public:
// this constructor gives the GPS its initial state.
GPS(const std::string &rawLogFileName,
const std::string &noiseLogFileName,
double x,
double y,
double vx,
double vy,
double u);
std::pair
std::pair
std::pair
private:
double xpos;
double ypos;
double xvel;
double yvel;
double uncertainty;
std::ofstream rawLog;
std::ofstream noiseLog;
};
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//plot.py
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('raw_gps.dat', unpack=True)
fildata = np.genfromtxt('filtered_gps.dat', unpack=True)
noisedata = np.genfromtxt('noise_gps.dat', unpack=True)
plt.plot(rawdata[0,:], rawdata[1,:], 'r-', label='raw')
plt.plot(noisedata[0,:], noisedata[1,:], 'g-', label='noise')
plt.plot(fildata[0,:], fildata[1,:], 'b-', label='filtered')
plt.grid()
plt.legend()
plt.show()
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Satellite.cpp
//
#include "Satellite.h"
#include "GPS.h"
Satellite::Satellite(const std::string &logFileName)
{
log.open(logFileName.c_str());
filter.setAlphaBeta(0.55, 0.05);
}
void Satellite::updateSystem(double dt)
{
auto data = gps->update(dt);
filter.update(dt, data.first, data.second);
auto filtered = filter.getState();
log
}
void Satellite::registerGPS(GPS *newGPS)
{
gps = newGPS;
auto pos = gps->getRawPosition();
auto vel = gps->getRawVelocity();
log
filter.initializeState(pos.first, pos.second, vel.first, vel.second);
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Satellite.h
//
// the Satellite class defined here is a simple representation of an observer
// entity in our system. it uses an alpha-beta filter to smooth input data from
// a connected GPS-like object.
//
#pragma once
#include
#include
#include "AlphaBetaFilter.h"
// forward declaring the GPS class
class GPS;
class Satellite
{
public:
Satellite(const std::string &logFileName);
void updateSystem(double dt);
void registerGPS(GPS *newGPS);
private:
GPS *gps;
AlphaBetaFilter filter;
std::ofstream log;
};
The task here is to implement the AlphaBetaFilter class 1. The alpha beta filter class needs to have the following public functions. place the class definition in a header file and the implementations in a separate source file (.cpp) setAlphaBeta void double a, double b sets the alpha and beta members of the class to a and b respectively a. name return parameters: purpose initializeState void double x, double y, double vx, double vy sets the x and and y position and velocity to the input values b. name return parameters: purpose update void double dt, double x, double y uses the input time differential dt and input signals x and y to update the state of the filter C name return parameters: purpose this is done by doing the following i. update the xpos and ypos by adding in their respective velocities multiplied by the time differential
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
