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 | |
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 | */ | |
25 | public 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 | ||
0d4900b6 | 65 | if (position == 1) { |
5e1e9b1e | 66 | |
0d4900b6 | 67 | // position 1 is always the low bar |
ff5c6dcc | 68 | |
4347c80d ME |
69 | addSequential(new DriveForDistance(POS1_DIST1, DEFAULT_SPEED)); |
70 | addSequential(new TurnForAngle(POS1_TURN1)); | |
71 | addSequential(new DriveForDistance(POS1_DIST2, DEFAULT_SPEED)); | |
ff9a504f | 72 | horizontalDistToGoal = 0; |
0d4900b6 | 73 | } else if (position == 2) { |
a2b9c4a9 ME |
74 | |
75 | addSequential(new DriveForDistance(POS2_DIST1, DEFAULT_SPEED)); | |
76 | addSequential(new TurnForAngle(POS2_TURN1)); | |
77 | addSequential(new DriveForDistance(POS2_DIST2, DEFAULT_SPEED)); | |
ff9a504f | 78 | horizontalDistToGoal = 0; |
a2b9c4a9 | 79 | |
0d4900b6 | 80 | } else if (position == 3) { |
ff5c6dcc | 81 | |
a2b9c4a9 ME |
82 | addSequential(new DriveForDistance(POS3_DIST1, DEFAULT_SPEED)); |
83 | addSequential(new TurnForAngle(POS3_TURN1)); | |
84 | addSequential(new DriveForDistance(POS3_DIST2, DEFAULT_SPEED)); | |
85 | addSequential(new TurnForAngle(POS3_TURN2)); | |
86 | addSequential(new DriveForDistance(POS3_DIST3, DEFAULT_SPEED)); | |
ff9a504f | 87 | horizontalDistToGoal = 0; |
ff5c6dcc | 88 | |
0d4900b6 | 89 | } else if (position == 4) { |
ff5c6dcc | 90 | |
1696ae28 ME |
91 | addSequential(new DriveForDistance(POS4_DIST1, DEFAULT_SPEED)); |
92 | addSequential(new TurnForAngle(POS4_TURN1)); | |
93 | addSequential(new DriveForDistance(POS4_DIST2, DEFAULT_SPEED)); | |
94 | addSequential(new TurnForAngle(POS4_TURN2)); | |
95 | addSequential(new DriveForDistance(POS4_DIST3, DEFAULT_SPEED)); | |
ff9a504f | 96 | horizontalDistToGoal = 0; |
ff5c6dcc | 97 | |
0d4900b6 | 98 | } else if (position == 5) { |
ff5c6dcc | 99 | |
1696ae28 ME |
100 | addSequential(new DriveForDistance(POS5_DIST1, DEFAULT_SPEED)); |
101 | addSequential(new TurnForAngle(POS5_TURN1)); | |
102 | addSequential(new DriveForDistance(POS5_DIST2, DEFAULT_SPEED)); | |
ff9a504f | 103 | horizontalDistToGoal = 0; |
ff5c6dcc ME |
104 | } |
105 | } | |
1696ae28 | 106 | |
1e9f4600 | 107 | public static double lidarCalculateAngleToTurn(int position, |
ff9a504f ME |
108 | double horizontalDistToGoal) { |
109 | double leftDist = Robot.driveTrain.getLeftLidarDistance(); | |
110 | double rightDist = Robot.driveTrain.getRightLidarDistance(); | |
111 | ||
112 | double errorAngle = Math.atan(Math.abs(leftDist - rightDist) / 2); | |
113 | double distToTower; | |
114 | // TODO: figure out if we do want to shoot into the side goal if we are | |
115 | // in position 1 or 2, or if we want to change that | |
116 | if (position == 1 || position == 2) { | |
117 | distToTower = Math | |
118 | .cos(CENTER_OF_MASS_TO_ROBOT_FRONT + (leftDist - rightDist) / 2) | |
119 | - DIST_CASTLE_WALL_TO_SIDE_GOAL; | |
120 | } | |
121 | ||
122 | // TODO: figure out if we do want to shoot into the font goal if we are | |
123 | // in position 3, 4, 5, or if we want to change that | |
124 | else { | |
125 | distToTower = Math | |
126 | .cos(CENTER_OF_MASS_TO_ROBOT_FRONT + (leftDist - rightDist) / 2) | |
127 | - DIST_CASTLE_WALL_TO_SIDE_GOAL; | |
128 | } | |
129 | ||
130 | double angleToTurn = Math.atan(distToTower / horizontalDistToGoal); | |
131 | ||
132 | return angleToTurn; | |
1696ae28 | 133 | } |
ff5c6dcc | 134 | } |