-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewFile_Template001.c
172 lines (160 loc) · 4.71 KB
/
NewFile_Template001.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
#pragma config(Sensor, in1, redBlueSwitch, sensorPotentiometer)
#pragma config(Sensor, dgtl11, , sensorQuadEncoder)
#pragma config(Motor, port1, frontLeft, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, frontRight, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, backRight, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, conveyer1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, conveyer2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, leftExpand, tmotorVex269_MC29, openLoop)
#pragma config(Motor, port7, rightExpand, tmotorVex269_MC29, openLoop)
#pragma config(Motor, port9, topArm, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port10, backLeft, tmotorVex393_HBridge, openLoop, reversed, encoderPort, dgtl11)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(60)
#pragma userControlDuration(60)
#define WHEELDIAMETER 4
#define ROTATION 699
#define SWITCH 2000
/*
* Function: strafe()
* Description: Provides ability to strafe left and right.
* Parameters: Variable joystick input
* Returns: None
*/
void strafe( int strafeValue ){
motor[ frontLeft ] = strafeValue;
motor[ backLeft ] = -strafeValue;
motor[ frontRight ] = strafeValue;
motor[ backRight ] = -strafeValue;
//lengthens update time
if( strafeValue != 0){
wait10Msec( 1 );
}
}//end strafe
/*
* Function: chassisMotion()
* Description: implements user control for chassis movement
* Parameters: Two Variable joystick input
* Returns: None
*/
void chassisMotion( int yMove , int xMove ){
int tempVal = 0 , tempTurn = 0;//temporary holder variables
//input from right joystick is transfered to the motors
if( xMove == 0 ){
motor[ frontLeft ] = yMove;
motor[ backLeft ] = yMove;
motor[ frontRight ] = yMove;
motor[ backRight ] = yMove;
}else if( xMove < 0 ){
motor[ frontLeft ] = yMove;
motor[ backLeft ] = yMove;
motor[ frontRight ] = yMove + xMove;
motor[ backRight ] = yMove + xMove;
}else{
motor[ frontLeft ] = yMove - xMove;
motor[ backLeft ] = yMove - xMove;
motor[ frontRight ] = yMove;
motor[ backRight ] = yMove;
}
//lengthens update time
if( yMove != 0 && xMove != 0 ){
wait10Msec( 1 );
}
}//end chassisMotion
/*void get_big( int expand_number , int contract_number ){
if( expand_number == 1 ){
motor[ leftExpand ] = 127;
motor[ rightExpand ] = -127;
}else if( contract_number ){
motor[ leftExpand ] = -127;
motor[ rightExpand ] = 127;
}else{
motor[ leftExpand ] = motor[ rightExpand ] = 0;
}
}//end get_big
*/
/*
* Function: manipMotion()
* Description: Controls conveyer belt
* Parameters: int button values
* Returns: None
*/
void manipMotion( int forward , int backward ){
if( forward == 1 ){
motor[ conveyer1 ] = 127;
motor[ conveyer2 ] = 127;
}else if( backward == 1 ){
motor[ conveyer1 ] = -127;
motor[ conveyer2 ] = -127;
}else{
motor[ conveyer1 ] = 0;
motor[ conveyer2 ] = 0;
}
}//end mattMotion
void moveUp( float dist , int speed ){
nMotorEncoder[ backLeft ] = 0;
dist = dist * 24 / (2 * WHEELDIAMETER * pi ) * ROTATION;
while( abs( nMotorEncoder[ backLeft ] ) < dist ){
chassisMotion( speed , 0 );
wait10Msec( 2 );
}
}
void moveStrafe( float dist , int speed ){
nMotorEncoder[ backLeft ] = 0;
dist = dist * 24 / (2 * WHEELDIAMETER * pi ) * ROTATION;
while( abs( nMotorEncoder[ backLeft ] ) < dist ){
strafe( speed );
wait10Msec( 2 );
}
}
void pointTurn( float dist ){
nMotorEncoder[ backLeft ] = 0;
dist = dist / (2 * WHEELDIAMETER * pi ) * ROTATION;
while( abs( nMotorEncoder[ backLeft ] ) < abs(dist) ){
if(dist>0){
motor[ frontLeft ] = motor[ backLeft ] = -100;
motor[ frontRight ] = motor[backRight ] = 100;
}
else{
motor[frontLeft] = motor[backLeft] = 100;
motor[frontRight] = motor[backRight] = -100;
}
wait10Msec( 2 );
}
motor[ frontLeft ] = motor[ backLeft ] = 0;
motor[ frontRight ] = motor[backRight ] = 0;
}
void balls( int count ){
int temp = 0;
while( temp < count){
motor[ conveyer1 ] = 127;
motor[ conveyer2 ] = 127;
wait10Msec( 10 );
}
motor[ conveyer1 ] =0;
motor[conveyer2 ] = 0;
}
task main(){
wait10Msec(2);
moveUp(1,127);
wait10Msec(100);
motor[conveyer1]=motor[conveyer2]=-127;
wait10Msec(2);
motor[topArm] = 127;
wait10Msec(100);
motor[topArm] = 0;
wait10Msec(100);
moveUp(0.2, -127);
wait10Msec(2);
moveStrafe(3, -127);
/*
wait10Msec(2);
moveUp(0.2, 127);
wait10Msec(2);
motor[topArm] = 127;
wait10Msec(100);
motor[topArm] = 0;*/
}