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