-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobot.h
88 lines (70 loc) · 1.63 KB
/
Robot.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
#pragma once
#include <Arduino.h>
#include "CentraleUltrasonicSensor.h"
#include "MeRGBLineFollower.h"
#include "Motors.h"
#include "Encoders.h"
#include "pid.h"
#define LEDPIN 2
#define STRAIGHTSPEED 130
#define WAITINGCURVESPEED 60
#define CURVESPEED 40
#define BASESPEED 50
enum RobotState {
INITIALSTATE,
STRAIGHT,
WAITINGCURVE,
CURVE,
AFTERCURVE,
OBSTACLEFOUND,
TRANSITIONPATHCURVE,
PATHOBSTACLE,
STABILIZE,
VOITUREFOUND
};
class Robot {
private:
RobotState currState, nextState, prevState;
int DT, curveTimeout, curveCooldown, obstacleCooldown, exitTimeout, leftEncoder, rightEncoder, curveCount;
float averageOffset;
bool obstacleAhead, carOnTheRight;
public:
MeRGBLineFollower *RGBLineFollower;
CentraleUltrasonicSensor *FrontObstacleSensor, *RightCarSensor;
int16_t offset;
Robot(MeRGBLineFollower *lineFollower, CentraleUltrasonicSensor *obstacleSensor, CentraleUltrasonicSensor *carSensor, int samplingTime);
/*
* Initializes Motors, Encoders and sets up the RGB Line Follower
*/
void init();
/*
* Checks wether it has obstacle or not. Also counts as
*/
void checkObstacle();
/*
* Checks wether it has voiture or not. Also counts as
*/
void checkVoiture();
/*
* Main routine. Robot acts accordingly with its states.
*
*/
void routine();
/*
* Handles state transition at every cycle
*/
void stateTransition();
/*
* Helps determine if the robot has stabilized
*/
void movingAverage();
/*
* Turns 90 degrees to the right
*/
void turnRight();
void goStraight(int decoderNumber, int speed);
/*
* Prints stuff
*/
void printInfo();
};