-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalltsamanbuttons.c
177 lines (159 loc) · 5.13 KB
/
alltsamanbuttons.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#pragma config(Motor, port2, rightMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port3, leftMotor, tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor, port4, claw, tmotorVex269, openLoop, reversed)
#pragma config(Motor, port5, liftRightMotor, tmotorVex269, openLoop)
#pragma config(Motor, port6, liftLeftMotor, tmotorVex269, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*----------------------------------------------------------------------------------------------------*\
|* - Dual Joystick Control - *|
|* ROBOTC on VEX 2.0 Cortex *|
|* *|
|* This program uses both the Left and the Right joysticks to run the robot using "tank control". *|
|* *|
|* ROBOT CONFIGURATION *|
|* NOTES: *|
|* 1) Ch1 is the X axis and Ch2 is the Y axis for the RIGHT joystick. *|
|* 2) Ch3 is the Y axis and Ch4 is the X axis for the LEFT joystick. *|
|* *|
|* MOTORS & SENSORS: *|
|* [I/O Port] [Name] [Type] [Description] *|
|* Motor - Port 2 rightMotor VEX Motor Right motor *|
|* Motor - Port 3 leftMotor VEX Motor Left motor *|
\*----------------------------------------------------------------------------------------------------*/
//+++++++++++++++++++++++++++++++++++++++++++++| VOID FUNCTIONS |+++++++++++++++++++++++++++++++++++++++++++++++
void forward() {
// forward
motor[rightMotor] = 32;
motor[leftMotor] = 30;
wait1Msec(800);
motor[rightMotor] = 0;
motor[leftMotor] = 0;
}
void turnleft90() {
// turns 90 degrees left
motor[rightMotor] = 50;
motor[leftMotor] = -50;
wait1Msec(2800);
motor[rightMotor] = 0;
motor[leftMotor] = 0;
}
void turnright90() {
// turns right 90 degrees
motor[rightMotor] = -50;
motor[leftMotor] = 50;
wait1Msec(2600);
motor[rightMotor] = 0;
motor[leftMotor] = 0;
}
void reverse () {
// reverses
motor[leftMotor] = -30;
motor[rightMotor] = -32;
wait1Msec(800);
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
void liftclaw () {
// lifts claw
motor(liftRightMotor) = 34;
motor(liftLeftMotor) = 34;
wait1Msec(500);
// stop lifting claw
motor(liftRightMotor) = 0;
motor(liftLeftMotor) = 0;
}
void lowerclaw() {
// lower clow
motor(liftRightMotor) = -18;
motor(liftLeftMotor) = -18;
wait1Msec (500);
motor(liftRightMotor) = 0;
motor(liftLeftMotor) = 0;
}
void openclaw() {
// open clow
motor (claw) = -30;
wait1Msec(1000);
motor (claw) = 0;
}
void closeclaw() {
// Close Clow
motor (claw) = 30;
wait1Msec(1000);
motor (claw) = 0;
}
void finish() {
motor[rightMotor] = 0;
motor[leftMotor] = 0;
motor(liftRightMotor) = 0;
motor(liftLeftMotor) = 0;
motor (claw) = 0;
}
void clawstop(){
motor (claw) = 0;
motor (liftRightMotor) = 0;
motor (liftLeftMotor) = 0;
}
//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main ()
{
int i = 0;
while(1 == 1)
{
if (vexRT[Btn7U] == 1) { // claw up
liftclaw();
}
else if (vexRT[Btn7D] == 1) { // claw down
lowerclaw();
}
else if (vexRT[Btn7R] == 1) { // close claw
closeclaw();
}
else if (vexRT[Btn7L] == 1) { // open claw
openclaw();
}
else { // all them zeros if the above is not used.
clawstop();
}
if (vexRT[Btn8U] == 1 && i == 0) { // forward short
forward();
}
else if (vexRT[Btn8D] == 1 && i == 0) { // backward short
reverse();
}
else if (vexRT[Btn8R] == 1 && i == 0) { // right short
turnright90();
}
else if (vexRT[Btn8L] == 1 && i == 0) { // left short
turnleft90();
}
if (vexRT[Btn5U] == 1) {
i = 1;
}
if (vexRT[Btn5D] == 1) {
i = 0;
}
if (i == 1) {
motor[leftMotor] = vexRT[Ch3]; // Left Joystick Y value
motor[rightMotor] = vexRT[Ch2]; // Right Joystick Y value
}
if (vexRT[Btn6D] == 1) {
forward();
forward();
turnright90();
openclaw();
forward();
closeclaw();
liftclaw();
reverse();
turnleft90();
forward();
forward();
lowerclaw();
openclaw();
//fullstop
finish();
}
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++