-
Notifications
You must be signed in to change notification settings - Fork 0
/
973G 2017.c
129 lines (115 loc) · 3.71 KB
/
973G 2017.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
#pragma config(Sensor, in1, armPot, sensorPotentiometer)
#pragma config(Sensor, in2, clawPot, sensorPotentiometer)
#pragma config(Sensor, dgtl7, FLEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl9, FREncoder, sensorQuadEncoder)
#pragma config(Motor, port2, frontRight, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port3, frontLeft, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port4, LRLiftM, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, LLiftM, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port6, RLiftM, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port7, ClawM, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port8, backRight, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port9, backLeft, tmotorVex393TurboSpeed_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)//3500, 4095
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#define yAxis vexRT[Ch3]
#define xAxis vexRT[Ch1]
#define rotation vexRT[Ch1]
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
float clawTarget = SensorValue[clawPot]; //base value need to change in testing
float clawGain = 0.2;
int clawOutput = 0;
bool isHanging = false;
int deadband(int joystickTarget) {
if (abs(joystickTarget) <= 20) {
joystickTarget = 0;
}
return joystickTarget;
}
void liftMotorSet(int value) {
motor[LLiftM] = deadband(value);// #8
motor[RLiftM] = deadband(value);// #9
motor[LRLiftM] = deadband(value);// #7
}
task clawMotorControl(){
while(true) {
motor[ClawM] = clawOutput;
if (vexRT[Btn6D] == true) { // star clamp
clawTarget = 1450;
}
else if (vexRT[Btn6U] == true) { //cube prep
clawTarget = 2100;
}
else if (vexRT[Btn8D] == true) { //outWide
clawTarget = 2715;
}
else if(vexRT[Btn8DXmtr2] == true) {
clawTarget = 3500;
}
else if(vexRT[Btn8UXmtr2] == true) {
clawTarget = 4095;
}
if(abs(clawTarget - SensorValue[clawPot]) > 10){
clawOutput = clawGain * (clawTarget - SensorValue[clawPot]);
}
else {
clawOutput = 0;
}
}
}
task noPidArm() {
while(isHanging == false){
liftMotorSet(deadband(vexRT[Ch2Xmtr2]));
if(SensorValue[armPot] > 1900) {
clawTarget = 2715;
}
}
}
task Hang() {
while(vexRT[Btn8RXmtr2] == true) {
isHanging = true;
clawTarget = 3700;
liftMotorSet(127);
if(SensorValue[armPot] < 500) {
clawTarget = 4095;
wait1Msec(1000);
liftMotorSet(0);
}
}
isHanging = false;
}
void autoDrive(int xValue, int yValue, int rValue){
motor[frontLeft] = +xValue + yValue - rValue;//Black-Black
motor[frontRight] = -xValue + yValue + rValue;//??
motor[backLeft] = +xValue - yValue + rValue;//Black-Black
motor[backRight] = -xValue - yValue- rValue;//Black-Red
}
void pre_auton()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
}
task autonomous()
{
autoDrive(0,-110,0);
wait1Msec(50);
autoDrive(0,0,0);
}
task usercontrol(){
while (true) {
startTask (Hang);
startTask (noPidArm);
startTask (clawMotorControl);
liftMotorSet(vexRT[Ch2Xmtr2]);
if (vexRT[Btn5U]) {
autoDrive(xAxis, 0, rotation);
}
else {
autoDrive(xAxis, yAxis, 0);
}
}
}