-
Notifications
You must be signed in to change notification settings - Fork 0
/
DriveUtils.cpp
executable file
·81 lines (73 loc) · 1.65 KB
/
DriveUtils.cpp
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
#include "DriveUtils.h"
void initMotors()
{
pinMode(DIRECTION_LEFT, OUTPUT);
pinMode(DIRECTION_RIGHT, OUTPUT);
//pinMode(BREAK_LEFT, OUTPUT);
//pinMode(BREAK_RIGHT, OUTPUT);
analogWrite(PWM_LEFT, 0);
analogWrite(PWM_RIGHT, 0);
//digitalWrite(BREAK_LEFT, HIGH);
//digitalWrite(BREAK_RIGHT, HIGH);
}
void setMotorLeft(int velocity)
{
velocity=(int)(velocity*2.55);
if(velocity>0)
{
if(velocity>VELOCITY_MAX)
velocity=VELOCITY_MAX;
analogWrite(PWM_LEFT, velocity);
digitalWrite(DIRECTION_LEFT, LOW);
}
else
{
velocity=velocity*(-1);
if(velocity>VELOCITY_MAX)
velocity=VELOCITY_MAX;
analogWrite(PWM_LEFT, velocity);
digitalWrite(DIRECTION_LEFT, HIGH);
}
//digitalWrite(BREAK_LEFT, LOW);
}
void setMotorRight(int velocity)
{
velocity=(int)(velocity*2.55);
if(velocity>0)
{
if(velocity>VELOCITY_MAX)
velocity=VELOCITY_MAX;
analogWrite(PWM_RIGHT, velocity);
digitalWrite(DIRECTION_RIGHT, LOW);
}
else
{
velocity=velocity*(-1);
if(velocity>VELOCITY_MAX)
velocity=VELOCITY_MAX;
analogWrite(PWM_RIGHT, velocity);
digitalWrite(DIRECTION_RIGHT, HIGH);
}
//digitalWrite(BREAK_RIGHT, LOW);
}
void setMotors(int velocityLeft, int velocityRight)
{
setMotorLeft(velocityLeft);
setMotorRight(velocityRight);
}
void breakMotorLeft()
{
analogWrite(PWM_LEFT, 0);
//digitalWrite(BREAK_LEFT, HIGH);
}
void breakMotorRight()
{
analogWrite(PWM_LEFT, 0);
//digitalWrite(BREAK_LEFT, HIGH);
}
void breakMotors(int timeMs)
{
breakMotorLeft();
breakMotorRight();
delay(timeMs);
}