@@ -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 ();
0 commit comments