-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar.h
62 lines (42 loc) · 1.03 KB
/
car.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
/*
* Copyright (C) 2016 Tolga Ceylan
*
* CopyPolicy: Released under the terms of the GNU GPL v3.0.
*/
#ifndef CAR_H_
#define CAR_H_
#include "wheel.h"
#include "pid.h"
#include <stdint.h>
namespace robo {
class SensorState;
class Car
{
public:
Car(robo::MotorDriver *driver, SensorState *sensors);
~Car();
void shutdown();
int initialize(int left_id, int right_id, uint64_t period);
int update(uint64_t now);
int turn(int angle);
int run(int distance);
void stop();
private:
void reset_state();
int update_wheel(robo::Wheel &wheel, int &speed, robo::Pid &pid, bool &isExecute);
int update_pid(uint64_t now, Pid &pid_left, Pid &pid_right);
static int convert_to_speed(const Pid &pid);
private:
robo::MotorDriver *m_driver;
robo::SensorState *m_sensors;
robo::Wheel m_left;
robo::Wheel m_right;
int m_leftSpeed;
int m_rightSpeed;
Pid m_leftPid;
Pid m_rightPid;
uint64_t m_previous;
uint64_t m_period;
};
} // namespace robo
#endif /* CAR_H_ */