-
Notifications
You must be signed in to change notification settings - Fork 0
/
LearningGui.h
163 lines (129 loc) · 4.38 KB
/
LearningGui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef LEARNINGGUI_H
#define LEARNINGGUI_H
#define WINDOW_WIDTH 1024
#define WINDOW_HEIGHT 768
#include <boost/lexical_cast.hpp>
#include <tuple>
#include <glog/logging.h>
#include <pangolin/pangolin.h>
#include <SceneGraph/SceneGraph.h>
#include <SceneGraph/GLMesh.h>
#include <cvars/CVar.h>
#include "CarMessages.pb.h"
#include <CarPlanner/CarPlannerCommon.h>
#include <CarPlanner/BulletCarModel.h>
#include <CarPlanner/Localizer.h>
#include <CarPlanner/CarRegressor.h>
#include <node/Node.h>
#include <SensorFusionCeres.h>
#include "JoystickHandler.h"
#include "PlannerGui.h"
#include "GLBulletDebugDrawer.h"
#include "CarMessages.pb.h"
#include "GLLearningPanel.h"
#include "ProcessModelFusion.h"
#include "EventLogger.h"
using namespace CVarUtils;
enum Mode
{
Mode_Experiment = 1,
Mode_Simulation = 2
};
class LearningGui
{
public:
LearningGui();
/// Initializes the GUI
void Init(const std::string& sRefPlane, const std::string& sMeshName,
bool bLocalizerTransform, const Mode eMode,
const std::string& sLearningParamsFile,
const std::string& sCarMesh, const std::string& sWheelMesh);
/// Runs the GUI
void Run();
static LearningGui *GetInstance();
private:
static bool SaveDataHandler(std::vector<std::string> *vArgs) { return GetInstance()->_SaveData(vArgs); }
static bool LoadDataHandler(std::vector<std::string> *vArgs) { return GetInstance()->_LoadData(vArgs); }
bool _SaveData(std::vector<std::string> *vArgs);
bool _LoadData(std::vector<std::string> *vArgs);
void _UpdateTrajectories();
/// Adds a command and vehicle state to the learning queue and starts the learning thread if enough
/// samples have been collected
void _UpdateLearning(ControlCommand command, VehicleState &state);
/// The function which is called by the learning thread
void _LearningFunc(MotionSample *pRegressionPlan);
void _LearningCaptureFunc();
/// Populates the initial scenegraph items
void _PopulateSceneGraph();
/// Function that pushes forward the physics based on the input commands
void _PhysicsFunc();
void _SetPoseFromFusion();
void _JoystickReadFunc();
//void _ImuReadFunc();
void _LocalizerReadFunc();
void _CommandHandler(const MochaCommands& command);
/// localizer reader
Localizer m_Localizer;
/// node for capturing IMU data from the car
//node::node m_Node;
/// name of the car used for localizer tracking
std::string m_sCarObjectName;
std::string m_sLearningParamsFile;
//view related variables
JoystickHandler m_Joystick;
BulletCarModel m_FusionCarModel;
BulletCarModel m_DriveCarModel;
BulletCarModel m_LearningCarModel;
SceneGraph::GLMesh m_TerrainMesh;
GLBulletDebugDrawer m_BulletDebugDrawer;
PlannerGui m_Gui;
int m_nDriveCarId;
int m_nPlayBackCarId;
double& m_dT;
double m_dImuRate;
double m_dLocalizerRate;
bool& m_bLearn;
bool m_bLearningRunning;
MotionSample m_PlaybackSample;
MotionSample* m_pRegressionSample;
CarRegressor m_Regressor;
double& m_dLearnEps;
int m_nCollectedRegressionSamples;
int& m_nTotalRegressionSamples;
boost::thread* m_pPhysicsThread;
boost::thread* m_pLearningThread;
boost::thread* m_pLearningCaptureThread;
//boost::thread* m_pImuThread;
boost::thread* m_pLocalizerThread;
boost::thread* m_pJoystickThread;
boost::mutex m_JoystickMutex;
boost::mutex m_RenderkMutex;
ControlCommand m_JoystickCommand;
//ui widgets
GLLearningPanel m_LearningPanel;
ProcessModelFusion m_Fusion;
Mode m_eMode;
std::vector<RegressionParameter> m_vDriveLearningParams;
std::vector<RegressionParameter> m_vLearningParams;
std::list<GLLineStrip> m_lGLLineSegments;
std::vector<MotionSample> m_vSamples;
std::vector<int> m_vSampleIndices;
std::vector<RegressionParameter> m_vTweakParams;
double m_dLastPoseTime;
double m_dTotalLearningTime;
bool m_bPlayback;
bool m_bStep;
bool m_bPaused;
bool m_bMapSteering;
bool m_bProcessModelEnabled;
bool m_bRefresh;
bool m_bRegress;
//bool m_bProcessModelFusionActive;
std::vector<std::pair<double,double> > m_vSteeringPairs;
Eigen::Vector6d m_dLastSteeringPose;
int m_nSteeringCount;
double m_dLastCurv;
EventLogger m_Logger;
CarParameterMap m_mParameters;
};
#endif // LEARNINGGUI_H