@@ -20,20 +20,20 @@ public class FindTurnTimeConstant extends Command {
2020 private SmartDashboardInterface sd ;
2121 private AHRS gyro ;
2222 private Robot robot ;
23- private Timer tim = new Timer () ;
24- private ArrayList <DataPoint > dataPoints = new ArrayList < DataPoint >() ;
23+ private Timer tim ;
24+ private ArrayList <DataPoint > dataPoints ;
2525
2626 private class DataPoint {
2727 public double seconds ;
28- public double degreesPerSecond ;
28+ public double radiansPerSecond ;
2929
30- public DataPoint (double seconds , double degreesPerSecond ) {
30+ public DataPoint (double seconds , double radiansPerSecond ) {
3131 this .seconds = seconds ;
32- this .degreesPerSecond = degreesPerSecond ;
32+ this .radiansPerSecond = radiansPerSecond ;
3333 }
3434
3535 public String toString () {
36- return "Time: " + seconds + " seconds; rotational velocity: " + degreesPerSecond + " degrees per second" ;
36+ return "Time: " + seconds + " seconds; rotational velocity: " + radiansPerSecond + " radians per second" ;
3737 }
3838 }
3939
@@ -53,12 +53,18 @@ public FindTurnTimeConstant(Robot robot, DrivetrainInterface dt, AHRS gyro, Smar
5353 // Called just before this Command runs the first time
5454 protected void initialize () {
5555 System .out .println ("FindTurnTimeConstant is in init()" );
56- if (!robot .isTest ()) {
57- System .out .println ("but you're not in test mode." );
58- return ;
59- }
56+ // if (!robot.isTest()) {
57+ // System.out.println("but you're not in test mode.");
58+ // return;
59+ // }
60+
61+ // this should be done in low gear
62+ Robot .dt .shiftGears (false );
63+
64+ dataPoints = new ArrayList <DataPoint >();
6065
6166 System .out .println ("and you're in test mode" );
67+ tim = new Timer ();
6268 tim .start ();
6369 // spin at full speed
6470 dt .arcadeDrive (0 , 1 );
@@ -70,6 +76,7 @@ protected void execute() {
7076 DataPoint newMeasurement = new DataPoint (tim .get (), gyro .getRate ());
7177 System .out .println (newMeasurement );
7278 dataPoints .add (newMeasurement );
79+ dt .arcadeDrive (0 , 1 );
7380 }
7481
7582 // Make this return true when this Command no longer needs to run execute()
@@ -78,26 +85,34 @@ protected boolean isFinished() {
7885 // true if the last and second-to-last rotational velocities measured are within
7986 // 5 degrees per second squared of each other. or if it's not a test, finish
8087 // immediately
81- if (numberOfDataPoints < 2 ) {
88+
89+ // if we're still in the first 51 cycles (don't have enough data), then not
90+ // finished. also, we're probably still accelerating if we haven't reached 3
91+ // radians per second (the max will be around 5).
92+ if (numberOfDataPoints < 51 || Math .abs (dataPoints .get (numberOfDataPoints - 1 ).radiansPerSecond ) < 3.0 ) {
8293 return false ;
8394 }
84- return (Math .abs (dataPoints .get (numberOfDataPoints - 1 ).degreesPerSecond
85- - dataPoints .get (numberOfDataPoints - 2 ).degreesPerSecond ) < 5 ) || !robot .isTest ();
95+
96+ return (Math .abs (dataPoints .get (numberOfDataPoints - 1 ).radiansPerSecond
97+ - dataPoints .get (numberOfDataPoints - 51 ).radiansPerSecond ) < 0.02 );
8698 }
8799
88100 // Called once after isFinished returns true
89101 protected void end () {
90102 // stop moving
91103 dt .arcadeDrive (0 , 0 );
92104
93- DataPoint lastDataPoint = dataPoints .get (dataPoints .size () - 1 );
94- System .out .println ("Finished when " + lastDataPoint );
95- // the rotvel of the data point we're looking for to find the time constant
96- double magicValue = lastDataPoint .degreesPerSecond * (1 - (1 / Math .E ));
105+ double lastRadiansPerSecond = dataPoints .get (dataPoints .size () - 1 ).radiansPerSecond ;
106+ System .out .println ("Finished at " + lastRadiansPerSecond + " radians per second" );
107+ Robot .putConst ("Max Turn Radians Per Second" , lastRadiansPerSecond );
108+
109+ // the radians per second of the data point we're looking for to find the time
110+ // constant
111+ double magicValue = lastRadiansPerSecond * (1 - (1 / Math .E ));
97112
98113 for (DataPoint datum : dataPoints ) {
99114 // if we've past the magic value, we're done
100- if (Math .abs (datum .degreesPerSecond ) > Math .abs (magicValue )) {
115+ if (Math .abs (datum .radiansPerSecond ) > Math .abs (magicValue )) {
101116 System .out .println ("The magic value is " + datum );
102117 Robot .putConst ("TurnTimeConstant" , datum .seconds );
103118 // stop checking data
0 commit comments