git.haldean.org droidcopter / 53858d8
Revisions: comments, hashcode, efficiency Benjamin Bardin 8 years ago
2 changed file(s) with 12 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
11
22 import java.util.ArrayList;
33
4 /**
5 * Note: this class has a natural ordering that is inconsistent with equals.
6 */
47 public class PidExperiment implements Comparable<PidExperiment> {
58 public static final long MAX_TIME_MILLIS = 10000;
69 public static final double THRESHOLD_ANGLE = 20.0;
6164 // mScore saved once processed (lazy evaluation)
6265 if (mScore != -1) return mScore;
6366
67 // If we don't get to the start of a third cycle, this experiment
68 // was really bad. Return MAX_VALUE.
6469 if (isTimeUp()) {
6570 mScore = Integer.MAX_VALUE;
6671 return mScore;
123128 return (getP() == other.getP()) && (getI() == other.getI()) && (getD() == other.getD());
124129 }
125130
131 public int hashCode() {
132 return new Double(getP()).hashCode() ^
133 new Double(getI()).hashCode() ^
134 new Double(getD()).hashCode();
135 }
136
126137 public int compareTo(PidExperiment other) {
127138 if (getScore() == other.getScore()) return 0;
128139 if (getScore() < other.getScore()) return -1;
4545 }
4646 } catch (IllegalArgumentException e) {
4747 // Default state; no tuning.
48 return;
4849 }
4950 mFringe = new ArrayList<PidExperiment>();
5051 mHistory = new TreeSet<PidExperiment>();