-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutonomous.c
104 lines (91 loc) · 2.67 KB
/
Autonomous.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
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Hubs, S2, HTMotor, none, none, none)
#pragma config(Sensor, S3, GYRO, sensorI2CHiTechnicGyro)
#pragma config(Sensor, S4, HTIRS2, sensorI2CCustom)
#pragma config(Motor, motorC, autoArm, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, leftDrive, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, winch, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_1, flag, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_2, unused2, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S2_C1_1, rightDrive, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S2_C1_2, collector, tmotorTetrix, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "drivers/hitechnic-irseeker-v2.h"
#include "lib/FTC_PID.c"
#include "lib/FTC_Gyro.c"
#include "constants.c"
#include "subsystems/Drivetrain.c"
#include "JoystickDriver.c"
void throwCube()
{
while ( nMotorEncoder[autoArm] < 150 )
{
motor[autoArm] = 100;
}
motor[autoArm] = -100;
wait1Msec(500);
motor[autoArm] = 0;
wait1Msec(200);
}
task main()
{
initGyro();
drivetrainInit();
drivetrainGyroDrivestraight = false;
bDisplayDiagnostics = false;
HTIRS2setDSPMode(HTIRS2, DSP_1200);
while (nPgmTime < 5000 )
{
int v1,v2,v3,v4,v5;
HTIRS2readAllACStrength(HTIRS2, v1,v2,v3,v4,v5);
nxtDisplayString(0, "%i ", gyroData.offset);
nxtDisplayString(1, "%2.4f ", getGyroAngle());
nxtDisplayString(2, "%2.4f ", gyroData.degsec);
nxtDisplayString(3, "%i ", v3);
updateGyro();
}
gyroData.deg = 0;
bDisplayDiagnostics = true;
waitForStart();
resetDrivetrainDistance();
nMotorEncoder[autoArm] = 0;
int counter = 0;
// drive out
setDrivetrainSetpoint(4700);
drivetrainMaxSpeed = 40;
bool threwCube = false;
while ( !atDrivetrainSetpoint(counter) )
{
int v1,v2,v3,v4,v5;
if ( HTIRS2readAllACStrength(HTIRS2, v1,v2,v3,v4,v5) )
{
if ( v4 >= 170 && !threwCube ) // at backet
{
motor[leftDrive] = 0;
motor[rightDrive] = 0;
throwCube();
drivetrainMaxSpeed = 100;
threwCube = true;
}
updateDrivetrain();
}
}
if ( !threwCube )
{
throwCube();
drivetrainMaxSpeed = 100;
}
resetDrivetrainDistance();
synchronousDriveTo(2300);
synchronousDriveTurn(30);
resetDrivetrainDistance();
synchronousDriveTo(1000);
synchronousDriveTurn(60);
resetDrivetrainDistance();
synchronousDriveTo(3650);
synchronousDriveTurn(0);
resetDrivetrainDistance();
synchronousDriveTo(-4800);
motor[autoArm] = 50;
wait1Msec(200);
}