Skip to content

Commit 5da2e06

Browse files
committed
部分注释
1 parent f5a7cfc commit 5da2e06

4 files changed

Lines changed: 52 additions & 35 deletions

File tree

src/org/usfirst/frc/team6414/robot/RobotMap.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* floating around.
88
*/
99
public class RobotMap {
10-
public static final int CHASSIS_ADJUST = 2;
10+
public static final int CHASSIS_ADJUST = 2; //Buttons & sticks
1111
public static final int INTAKE_FWD = 3;
1212
public static final int MIXER_FWD = 4;
1313
public static final int INTAKE_BWD = 5;
@@ -16,7 +16,7 @@ public class RobotMap {
1616
public static final int SHOOTER_BWD = 11;
1717
static final int STICK = 0;
1818

19-
public static final int RIGHT_MASTER = 1;
19+
public static final int RIGHT_MASTER = 1; //Motors
2020
public static final int RIGHT_SLAVE = 2;
2121
public static final int LEFT_MASTER = 3;
2222
public static final int LEFT_SLAVE = 4;
@@ -25,16 +25,17 @@ public class RobotMap {
2525
public static final int RIGHT_SHOOTER = 7;
2626
public static final int MIXER_MOTOR = 8;
2727

28-
public static final double INTAKE_DEF = 1;
28+
public static final double INTAKE_DEF = 1; //Default speed
2929
public static final double SHOOTER_DEFAULT = 0.7;
3030
public static final double MIXER_DEF = 0.5;
3131

32-
public static final double US_PULSE = 0.00001; //10us per ping for hc-SR04 module
32+
public static final double US_PULSE = 0.00001; //others
3333
public static final int LEFT_ECHO = 0;
3434
public static final int LEFT_PULSE = 1;
3535
public static final int RIGHT_ECHO = 2;
3636
public static final int RIGHT_PULSE = 3;
3737
public static final double SPEED_OF_SOUND = 340;
3838
public static final double SENSOR_DIST = 100;
3939
public static final double START_DISTANT = 300;
40+
public static final int AUTO_TIMEOUT = 15;
4041
}

src/org/usfirst/frc/team6414/robot/commands/Autonomous.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,62 @@ public Autonomous() {
1717
requires(Robot.chassis);
1818
}
1919

20-
2120
/**
2221
* The initialize method is called just before the first time
2322
* this Command is run after being started.
24-
*
23+
* make sure robot will atop after 15s
2524
*/
2625
protected void initialize() {
27-
this.setTimeout(15);
26+
this.setTimeout(RobotMap.AUTO_TIMEOUT);
2827
}
2928

3029
/**
30+
* constructor
31+
* speed: max=1, min=0, f'(x)=-2sqrt(a)/(2sqrt(-x+a))
32+
* f(x)=sqrt(-x+a)/sqrt(a) => sqrt(-x/a+1)
33+
*
3134
* @param distant distant form robot to the wall of control station (average)
3235
* @return the speed it should go at a certain distance. Closer, slower.
33-
* max=1, min=0, f'(x)=-2sqrt(a)/(2sqrt(-x+a))
34-
* f(x)=sqrt(-x+a)/sqrt(a) => sqrt(-x/a+1)
3536
*/
3637
private double speed(double distant) {
3738
return Math.sqrt(-distant / RobotMap.START_DISTANT + 1);
3839
}
3940

41+
/**
42+
* @return get average distance of both sensor
43+
*/
4044
private double getDistance() {
4145
return 0.5 * (Robot.uSensor.getLeftDistant() + Robot.uSensor.getRightDistant());
4246
}
4347

48+
/**
49+
* get turning speed
50+
*
51+
* @return From 0.5 to -0.5. Reach Max / Min when perform a 45 degree angle to the wall
52+
*/
4453
private double getRotate() {
45-
return (Robot.uSensor.getRightDistant() - Robot.uSensor.getLeftDistant())
46-
/ 1.414 * RobotMap.SENSOR_DIST;
54+
return Robot.limit(-1, 1,
55+
(Robot.uSensor.getRightDistant() - Robot.uSensor.getLeftDistant())
56+
/ 2 * Math.sqrt(2) * RobotMap.SENSOR_DIST);
4757
}
4858

4959
/**
5060
* The execute method is called repeatedly when this Command is
5161
* scheduled to run until this Command either finishes or is canceled.
62+
* Make robot go at the speed we calculated above
5263
*/
5364
protected void execute() {
5465
Robot.chassis.move(speed(getDistance()), getRotate());
5566
}
5667

5768

5869
/**
59-
* <p>
60-
* Returns whether this command is finished. If it is, then the command will be removed and
61-
* {@link #end()} will be called.
62-
* </p><p>
63-
* It may be useful for a team to reference the {@link #isTimedOut()}
64-
* method for time-sensitive commands.
65-
* </p><p>
66-
* Returning false will result in the command never ending automatically. It may still be
67-
* cancelled manually or interrupted by another command. Returning true will result in the
68-
* command executing once and finishing immediately. It is recommended to use
69-
* {@link edu.wpi.first.wpilibj.command.InstantCommand} (added in 2017) for this.
70-
* </p>
71-
*
70+
* Die at time out
7271
* @return whether this command is finished.
7372
* @see Command#isTimedOut() isTimedOut()
7473
*/
7574
protected boolean isFinished() {
76-
return false;
75+
return isTimedOut();
7776
}
7877

7978

@@ -82,6 +81,7 @@ protected boolean isFinished() {
8281
* after {@link #isFinished()} returns true. This is where you may want to
8382
* wrap up loose ends, like shutting off a motor that was being used in the
8483
* command.
84+
* Stop the chassis for safty reason
8585
*/
8686
protected void end() {
8787
Robot.chassis.stop();

src/org/usfirst/frc/team6414/robot/commands/Intake.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,49 @@
88
*/
99
public class Intake extends Command {
1010

11+
/**
12+
* Standard Constructor.
13+
*/
1114
public Intake() {
1215
requires(Robot.intaker);
1316
}
1417

15-
// Called just before this Command runs the first time
18+
/**
19+
* o(* ̄▽ ̄*)ブ
20+
*/
21+
@Override
1622
protected void initialize() {
1723
System.out.println("Intake command init");
1824
}
1925

20-
// Called repeatedly when this Command is scheduled to run
26+
/**
27+
*
28+
*/
29+
@Override
2130
protected void execute() {
2231
Robot.intaker.intake();
2332
}
2433

25-
// Make this return true when this Command no longer needs to run execute()
34+
/**
35+
* @return is this comma
36+
*/
37+
@Override
2638
protected boolean isFinished() {
2739
return false;
2840
}
2941

30-
// Called once after isFinished returns true
42+
/**
43+
*
44+
*/
45+
@Override
3146
protected void end() {
3247
Robot.intaker.stop();
3348
}
3449

35-
// Called when another command which requires one or more of the same
36-
// subsystems is scheduled to run
50+
/**
51+
*
52+
*/
53+
@Override
3754
protected void interrupted() {
3855
}
3956
}

src/org/usfirst/frc/team6414/robot/subsystems/MonitoredSystem.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
public abstract class MonitoredSystem extends Subsystem {
1212

13-
private Thread monitor; //The thread used to mkonitor the whole subsystem
13+
private Thread monitor; //This thread is used to monitor the whole subsystem
1414
private boolean isRunning = true; //run state indicator.
1515
private long sleepTime = 200; //How many milliseconds between 2 inspect
1616

@@ -60,9 +60,8 @@ public void stopMonitor() {
6060
}
6161

6262
/**
63-
* Empty, Make it sure to override it in subsystems.
63+
* Empty. Make sure to override it in subsystems.
6464
*/
6565
@Override
66-
protected void initDefaultCommand() {
67-
}
66+
protected abstract void initDefaultCommand();
6867
}

0 commit comments

Comments
 (0)