-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwoWDRobot.h
108 lines (88 loc) · 2.43 KB
/
TwoWDRobot.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
#include <stdint.h>
#ifndef TwoWDRobot_H
#define TwoWDRobot_H
#include <Arduino.h>
enum MODE{PWM_PWM,PWM_DIR};
class MDD3A
{
protected:
MODE _mode;
uint8_t motorPins[4];
public:
MDD3A(MODE mode, uint8_t M1_pinA, uint8_t M1_pinB, uint8_t M2_pinA, uint8_t M2_pinB);
void motorDrive(int M1_speed, int M2_speed, int duration);
};
class ultraSound
{
protected:
int echo, trigger;
public:
ultraSound(int trigPin, int echoPin);
float getUltrasoundDistance();
};
class infraredDigital
{
protected:
int digitalPin;
public:
infraredDigital(int IR_signalPin);
bool getInfraredDigitalSignal();
};
class infraredAnalog
{
protected:
int analogPin;
public:
infraredAnalog(int IR_signalPin);
int getInfraredAnalogSignal();
};
class obstacleAvoidanceRobot : public ultraSound, public MDD3A
{
public:
obstacleAvoidanceRobot(int trigPin, int echoPin, uint8_t M1_A, uint8_t M1_B, uint8_t M2_A, uint8_t M2_B, MODE motorsPinMode);
void runObstacleRobot(int obstacleDistance, int turnTime, int leftWheelSpeed = 50, int rightWheelSpeed = 50);
};
enum sensorType
{
ACTIVE_LOW,
ACTIVE_HIGH
};
class cliffDetectionRobot : public MDD3A
{
private:
int leftSignalPin, rightSignalPin;
public:
cliffDetectionRobot(int leftSensorPin, int rightSensorPin, uint8_t M1_A, uint8_t M1_B, uint8_t M2_A, uint8_t M2_B, MODE motorsPinMode);
void runCliffRobot(sensorType type, int turnDelay, int leftWheelSpeed = 50, int rightWheelSpeed = 50);
};
class bluetoothRobotCar : public MDD3A
{
public:
bluetoothRobotCar(uint8_t M1_A, uint8_t M1_B, uint8_t M2_A, uint8_t M2_B, MODE motorsPinMode);
void runRobotCar(int leftWheelSpeed = 50, int rightWheelSpeed = 50);
char bluetoothData();
};
enum wallFollowMode
{
LEFT_FOLLOW,
RIGHT_FOLLOW
};
class wallFollowRobot : public MDD3A
{
private:
wallFollowMode _mode;
int trigger1, trigger2, echo1, echo2;
public:
wallFollowRobot(wallFollowMode mode, int USfrontPins[2], int USsidePins[2], uint8_t M1_A, uint8_t M1_B, uint8_t M2_A, uint8_t M2_B, MODE motorsPinMode);
void runWallFollowRobot(float frontDistance, float sideDistance, int leftWheelSpeed = 20, int rightWheelSpeed = 20);
};
class lineFollowRobot : public MDD3A
{
private:
int sensorPins[5];
public:
lineFollowRobot(int sensorpins[], uint8_t M1_A, uint8_t M1_B, uint8_t M2_A, uint8_t M2_B, MODE motorsPinMode);
void runLineFollowRobot(sensorType type, int leftWheelSpeed = 50, int rightWheelSpeed = 50);
byte lineSensorRead(int pins[]);
};
#endif