fix misc. comments
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / commands / AlignToScore.java
CommitLineData
ff5c6dcc
ME
1package org.usfirst.frc.team3501.robot.commands;
2
1696ae28
ME
3import org.usfirst.frc.team3501.robot.Robot;
4
ff5c6dcc
ME
5import edu.wpi.first.wpilibj.command.CommandGroup;
6
7/**
8 * This command group will be used in autonomous. Based on what position the
10ca638d
ME
9 * robot is in, the robot will align with the goal. In the Software 2015-2016
10 * Google folder is a picture explaining each of the cases.
11 *
9d87dd2d
ME
12 * dependency on sensors: lidars, encoders, gyro
13 *
14 * dependency on subsystems: drivetrain
15 *
16 * dependency on other commands: TurnForAngle(), DriveForDistance()
ff5c6dcc
ME
17 *
18 * pre-condition: robot is flush against a defense at the specified position in
19 * the opponent's courtyard
20 *
21 * post-condition: the robot is parallel to one of the three goals and the
22 * shooter is facing that goal
23 *
24 */
25public class AlignToScore extends CommandGroup {
ff9a504f
ME
26 private final static double CENTER_OF_MASS_TO_ROBOT_FRONT = 0;
27 private final static double DIST_CASTLE_WALL_TO_SIDE_GOAL = 0;
28 private final static double DIST_CASTLE_WALL_TO_FRONT_GOAL = 0;
1696ae28 29
5e1e9b1e 30 private final double DEFAULT_SPEED = 0.5;
5e1e9b1e 31
1696ae28 32 // constants for position 1: low bar
5e1e9b1e
ME
33 private final double POS1_DIST1 = 0;
34 private final double POS1_TURN1 = 0;
35 private final double POS1_DIST2 = 0;
36
37 // constants for position 2
4347c80d
ME
38 private final double POS2_DIST1 = 0;
39 private final double POS2_TURN1 = 0;
40 private final double POS2_DIST2 = 0;
41
5e1e9b1e 42 // constants for position 3
a2b9c4a9
ME
43 private final double POS3_DIST1 = 0;
44 private final double POS3_TURN1 = 0;
45 private final double POS3_DIST2 = 0;
46 private final double POS3_TURN2 = 0;
47 private final double POS3_DIST3 = 0;
5e1e9b1e
ME
48
49 // constants for position 4
1696ae28
ME
50 private final double POS4_DIST1 = 0;
51 private final double POS4_TURN1 = 0;
52 private final double POS4_DIST2 = 0;
53 private final double POS4_TURN2 = 0;
54 private final double POS4_DIST3 = 0;
5e1e9b1e
ME
55
56 // constants for position 5
1696ae28
ME
57 private final double POS5_DIST1 = 0;
58 private final double POS5_TURN1 = 0;
59 private final double POS5_DIST2 = 0;
ff5c6dcc 60
ff9a504f
ME
61 public double horizontalDistToGoal;
62
ff5c6dcc
ME
63 public AlignToScore(int position) {
64
65 switch (position) {
5e1e9b1e
ME
66
67 // position 1 is always the low bar
ff5c6dcc
ME
68 case 1:
69
4347c80d
ME
70 addSequential(new DriveForDistance(POS1_DIST1, DEFAULT_SPEED));
71 addSequential(new TurnForAngle(POS1_TURN1));
72 addSequential(new DriveForDistance(POS1_DIST2, DEFAULT_SPEED));
ff9a504f 73 horizontalDistToGoal = 0;
ff5c6dcc 74
a2b9c4a9
ME
75 case 2:
76
77 addSequential(new DriveForDistance(POS2_DIST1, DEFAULT_SPEED));
78 addSequential(new TurnForAngle(POS2_TURN1));
79 addSequential(new DriveForDistance(POS2_DIST2, DEFAULT_SPEED));
ff9a504f 80 horizontalDistToGoal = 0;
a2b9c4a9 81
ff5c6dcc
ME
82 case 3:
83
a2b9c4a9
ME
84 addSequential(new DriveForDistance(POS3_DIST1, DEFAULT_SPEED));
85 addSequential(new TurnForAngle(POS3_TURN1));
86 addSequential(new DriveForDistance(POS3_DIST2, DEFAULT_SPEED));
87 addSequential(new TurnForAngle(POS3_TURN2));
88 addSequential(new DriveForDistance(POS3_DIST3, DEFAULT_SPEED));
ff9a504f 89 horizontalDistToGoal = 0;
ff5c6dcc
ME
90
91 case 4:
92
1696ae28
ME
93 addSequential(new DriveForDistance(POS4_DIST1, DEFAULT_SPEED));
94 addSequential(new TurnForAngle(POS4_TURN1));
95 addSequential(new DriveForDistance(POS4_DIST2, DEFAULT_SPEED));
96 addSequential(new TurnForAngle(POS4_TURN2));
97 addSequential(new DriveForDistance(POS4_DIST3, DEFAULT_SPEED));
ff9a504f 98 horizontalDistToGoal = 0;
ff5c6dcc
ME
99
100 case 5:
101
1696ae28
ME
102 addSequential(new DriveForDistance(POS5_DIST1, DEFAULT_SPEED));
103 addSequential(new TurnForAngle(POS5_TURN1));
104 addSequential(new DriveForDistance(POS5_DIST2, DEFAULT_SPEED));
ff9a504f 105 horizontalDistToGoal = 0;
ff5c6dcc
ME
106 }
107 }
1696ae28 108
10ca638d 109 public static double calculateAngleToTurn(int position,
ff9a504f
ME
110 double horizontalDistToGoal) {
111 double leftDist = Robot.driveTrain.getLeftLidarDistance();
112 double rightDist = Robot.driveTrain.getRightLidarDistance();
113
114 double errorAngle = Math.atan(Math.abs(leftDist - rightDist) / 2);
115 double distToTower;
116 // TODO: figure out if we do want to shoot into the side goal if we are
117 // in position 1 or 2, or if we want to change that
118 if (position == 1 || position == 2) {
119 distToTower = Math
120 .cos(CENTER_OF_MASS_TO_ROBOT_FRONT + (leftDist - rightDist) / 2)
121 - DIST_CASTLE_WALL_TO_SIDE_GOAL;
122 }
123
124 // TODO: figure out if we do want to shoot into the font goal if we are
125 // in position 3, 4, 5, or if we want to change that
126 else {
127 distToTower = Math
128 .cos(CENTER_OF_MASS_TO_ROBOT_FRONT + (leftDist - rightDist) / 2)
129 - DIST_CASTLE_WALL_TO_SIDE_GOAL;
130 }
131
132 double angleToTurn = Math.atan(distToTower / horizontalDistToGoal);
133
134 return angleToTurn;
1696ae28 135 }
ff5c6dcc 136}