-
Notifications
You must be signed in to change notification settings - Fork 0
/
robo.h
124 lines (95 loc) · 2.29 KB
/
robo.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
/*
* Copyright (C) 2016 Tolga Ceylan
*
* CopyPolicy: Released under the terms of the GNU GPL v3.0.
*/
#ifndef ROBO_H_
#define ROBO_H_
#include "i2c.h"
#include "car.h"
#include "thread.h"
#include "poller.h"
// sensors
#include "bmp085.h"
#include "l3gd20.h"
#include "lsm303accel.h"
#include "lsm303mag.h"
#include "encoder.h"
#include "sensor_state.h"
namespace robo {
//
// Robot state for sonar search gap and advance
// algorithm
//
struct State
{
bool isTriggerAdvance;
int distance;
uint64_t maxRun;
uint64_t minFrameTime;
uint64_t warmupDeadline;
bool isDone;
State();
void reset(uint64_t start_deadline = 0);
void start();
void print() const;
};
//
// Stats for robot such as frame rate, etc.
//
struct Stats
{
uint64_t m_maxFrameTime;
uint64_t m_minFrameTime;
uint64_t m_avgFrameTime;
uint64_t m_numOfFrames;
uint64_t m_avgFrameSmoother;
uint64_t m_displayPeriod;
uint64_t m_totalFrameTime;
Stats();
void reset();
void print() const;
bool update_stats(uint64_t elapsed);
};
class Robot
{
public:
Robot(int demo_num);
~Robot();
int initialize();
void shutdown();
int update();
private:
// no copy
Robot(const Robot &);
Robot& operator=(const Robot &);
int update_car(uint64_t now);
int update_driver(uint64_t now);
int update_sensor_state(uint64_t now);
int update_bmp085(uint64_t now);
int update_l3gd20(uint64_t now);
int update_lsm303accel(uint64_t now);
int update_lsm303mag(uint64_t now);
int update_encoder(uint64_t now);
int update_io_thread(uint64_t now);
int update_poller(uint64_t start, uint64_t &elapsed);
void error_shut_sequence();
private:
const int m_demo_num;
robo::Timer m_timer;
robo::Poller m_poller;
robo::Thread m_thread1;
robo::I2C m_i2c1;
robo::MotorDriver m_driver;
robo::Car m_car;
robo::BMP085 m_bmp085;
robo::L3GD20 m_l3gd20;
robo::LSM303Accel m_lsm303accel;
robo::LSM303Mag m_lsm303mag;
robo::Encoder m_encoder;
robo::Stats m_stats;
robo::SensorState m_sensor_state;
State m_state;
};
} // namespace robo
#endif /* ROBO_H_ */