-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrive.c
71 lines (59 loc) · 1.47 KB
/
Drive.c
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
// Drive.c
//
// Brandon Coll
//
// Code for basic robot drive functions.
float avgEncoders;
int drivePIDOutput;
bool driveDone = false;
bool turnDone = false;
void resetEncoders() {
SensorValue(leftEncoder) = 0;
SensorValue(rightEncoder) = 0;
}
float getLeftEncoder() {
return ((float)SensorValue(leftEncoder) / 360.0) * 3.25 * PI;
}
float getRightEncoder() {
return ((float)SensorValue(rightEncoder) / 360.0) * 3.25 * PI;
}
float getGyro(){
return (SensorValue(leftEncoder) - SensorValue(rightEncoder)) * 0.239;
}
float getAvgEncoder(){
return (getRightEncoder() + getLeftEncoder()) /2 ;
}
//Drives the left drive at the given voltage.
void leftDrive(int voltage){
motor(FLD) = motor(BLD) = removeDeadband(voltage);
}
//Drives the right drive at the given voltage.
void rightDrive(int voltage){
motor(FRD) = motor(BRD) = removeDeadband(voltage);
}
//ARCADE DRIVE SYSTEM
void arcadeDrive(){
int throttle = removeDeadband(vexRT(Ch3));
int turnThrottle = removeDeadband(vexRT(Ch1));
if(vexRT(Btn5D)){
leftDrive(throttle + turnThrottle/2);
rightDrive(throttle - turnThrottle/2);
}
else{
leftDrive(throttle + turnThrottle);
rightDrive(throttle - turnThrottle);
}
}
//TANK DRIVE SYSTEM
void tankDrive(){
leftDrive(vexRT(Ch3));
rightDrive(vexRT(Ch2));
}
void autoDrive(int voltage) {
int turn = 0;
if(abs(voltage) > 15){
turn = getGyro() * 4;
}
//motor(LD1) = motor(LD2) = motor(LD3) = voltage - turn;
//motor(RD1) = motor(RD2) = motor(RD3) = voltage + turn;
}