1 package org
.usfirst
.frc
.team3501
.robot
.commands
.auton
;
3 import org
.usfirst
.frc
.team3501
.robot
.Robot
;
4 import org
.usfirst
.frc
.team3501
.robot
.commands
.driving
.DriveDistance
;
5 import org
.usfirst
.frc
.team3501
.robot
.commands
.driving
.TurnForAngle
;
7 import edu
.wpi
.first
.wpilibj
.command
.CommandGroup
;
10 * This command group will be used in autonomous. Based on what position the
11 * robot is in, the robot will align with the goal. In the Software 2015-2016
12 * Google folder is a picture explaining each of the cases.
14 * dependency on sensors: lidars, encoders, gyro
16 * dependency on subsystems: drivetrain
18 * dependency on other commands: TurnForAngle(), DriveForDistance()
20 * pre-condition: robot is flush against a defense at the specified position in
21 * the opponent's courtyard
23 * post-condition: the robot is parallel to one of the three goals and the
24 * shooter is facing that goal
27 public class AlignToScore
extends CommandGroup
{
28 private final static double CENTER_OF_MASS_TO_ROBOT_FRONT
= 0;
29 private final static double DIST_CASTLE_WALL_TO_SIDE_GOAL
= 0;
30 private final static double DIST_CASTLE_WALL_TO_FRONT_GOAL
= 0;
32 private final double DEFAULT_SPEED
= 0.5;
33 private final double maxTimeout
= 5;
36 // assuming that positive angle means turning right
37 // and negative angle means turning left
39 // constants for position 1: low bar
40 private final double POS1_DIST1
= 109;
41 private final double POS1_TURN1
= 60;
42 private final double POS1_DIST2
= 0;
44 // constants for position 2
45 private final double POS2_DIST1
= 140;
46 private final double POS2_TURN1
= 60;
47 private final double POS2_DIST2
= 0;
49 // constants for position 3
50 private final double POS3_DIST1
= 0;
51 private final double POS3_TURN1
= 90;
52 private final double POS3_DIST2
= 35.5;
53 private final double POS3_TURN2
= -90;
54 private final double POS3_DIST3
= 0;
56 // constants for position 4
57 private final double POS4_DIST1
= 0;
58 private final double POS4_TURN1
= -90;
59 private final double POS4_DIST2
= 18.5;
60 private final double POS4_TURN2
= 90;
61 private final double POS4_DIST3
= 0;
63 // constants for position 5
64 private final double POS5_DIST1
= 0;
65 private final double POS5_TURN1
= -90;
66 private final double POS5_DIST2
= 72.5;
67 private final double POS5_TURN2
= 90;
68 private final double POS5_DIST3
= 0;
70 public double horizontalDistToGoal
;
72 public AlignToScore(int position
) {
76 // position 1 is always the low bar
78 addSequential(new DriveDistance(POS1_DIST1
, DEFAULT_SPEED
));
79 addSequential(new TurnForAngle(POS1_TURN1
, maxTimeout
));
80 addSequential(new DriveDistance(POS1_DIST2
, DEFAULT_SPEED
));
81 horizontalDistToGoal
= 0;
82 } else if (position
== 2) {
84 addSequential(new DriveDistance(POS2_DIST1
, DEFAULT_SPEED
));
85 addSequential(new TurnForAngle(POS2_TURN1
, maxTimeout
));
86 addSequential(new DriveDistance(POS2_DIST2
, DEFAULT_SPEED
));
87 horizontalDistToGoal
= 0;
89 } else if (position
== 3) {
91 addSequential(new DriveDistance(POS3_DIST1
, DEFAULT_SPEED
));
92 addSequential(new TurnForAngle(POS3_TURN1
, maxTimeout
));
93 addSequential(new DriveDistance(POS3_DIST2
, DEFAULT_SPEED
));
94 addSequential(new TurnForAngle(POS3_TURN2
, maxTimeout
));
95 addSequential(new DriveDistance(POS3_DIST3
, DEFAULT_SPEED
));
96 horizontalDistToGoal
= 0;
98 } else if (position
== 4) {
100 addSequential(new DriveDistance(POS4_DIST1
, DEFAULT_SPEED
));
101 addSequential(new TurnForAngle(POS4_TURN1
, maxTimeout
));
102 addSequential(new DriveDistance(POS4_DIST2
, DEFAULT_SPEED
));
103 addSequential(new TurnForAngle(POS4_TURN2
, maxTimeout
));
104 addSequential(new DriveDistance(POS4_DIST3
, DEFAULT_SPEED
));
105 horizontalDistToGoal
= 0;
107 } else if (position
== 5) {
109 addSequential(new DriveDistance(POS5_DIST1
, DEFAULT_SPEED
));
110 addSequential(new TurnForAngle(POS5_TURN1
, maxTimeout
));
111 addSequential(new DriveDistance(POS5_DIST2
, DEFAULT_SPEED
));
112 addSequential(new TurnForAngle(POS5_TURN2
, maxTimeout
));
113 addSequential(new DriveDistance(POS5_DIST3
, DEFAULT_SPEED
));
114 horizontalDistToGoal
= 0;
119 public static double lidarCalculateAngleToTurn(int position
,
120 double horizontalDistToGoal
) {
121 double leftDist
= Robot
.driveTrain
.getLeftLidarDistance();
122 double rightDist
= Robot
.driveTrain
.getRightLidarDistance();
124 double errorAngle
= Math
.atan(Math
.abs(leftDist
- rightDist
) / 2);
126 // TODO: figure out if we do want to shoot into the side goal if we are
127 // in position 1 or 2, or if we want to change that
128 if (position
== 1 || position
== 2) {
130 .cos(CENTER_OF_MASS_TO_ROBOT_FRONT
+ (leftDist
- rightDist
) / 2)
131 - DIST_CASTLE_WALL_TO_SIDE_GOAL
;
134 // TODO: figure out if we do want to shoot into the font goal if we are
135 // in position 3, 4, 5, or if we want to change that
138 .cos(CENTER_OF_MASS_TO_ROBOT_FRONT
+ (leftDist
- rightDist
) / 2)
139 - DIST_CASTLE_WALL_TO_SIDE_GOAL
;
142 double angleToTurn
= Math
.atan(distToTower
/ horizontalDistToGoal
);