Skip to content

Commit b90405e

Browse files
committed
Add documentation for the Encoder Follower
1 parent 31111a9 commit b90405e

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

Pathfinder-Java/src/main/java/jaci/pathfinder/followers/EncoderFollower.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package jaci.pathfinder.followers;
22

3-
import jaci.pathfinder.PathfinderJNI;
43
import jaci.pathfinder.Trajectory;
54

5+
/**
6+
* The EncoderFollower is an object designed to follow a trajectory based on encoder input. This class can be used
7+
* for Tank or Swerve drive implementations.
8+
*
9+
* @author Jaci
10+
*/
611
public class EncoderFollower {
712

813
int encoder_offset, encoder_tick_count;
@@ -21,26 +26,56 @@ public EncoderFollower(Trajectory traj) {
2126

2227
public EncoderFollower() { }
2328

29+
/**
30+
* Set a new trajectory to follow, and reset the cumulative errors and segment counts
31+
*/
2432
public void setTrajectory(Trajectory traj) {
2533
this.trajectory = traj;
2634
reset();
2735
}
2836

37+
/**
38+
* Configure the PID/VA Variables for the Follower
39+
* @param kp The proportional term. This is usually quite high (0.8 - 1.0 are common values)
40+
* @param ki The integral term. Currently unused.
41+
* @param kd The derivative term. Adjust this if you are unhappy with the tracking of the follower. 0.0 is the default
42+
* @param kv The velocity ratio. This should be 1 over your maximum velocity @ 100% throttle.
43+
* This converts m/s given by the algorithm to a scale of -1..1 to be used by your
44+
* motor controllers
45+
* @param ka The acceleration term. Adjust this if you want to reach higher or lower speeds faster. 0.0 is the default
46+
*/
2947
public void configurePIDVA(double kp, double ki, double kd, double kv, double ka) {
3048
this.kp = kp; this.ki = ki; this.kd = kd;
3149
this.kv = kv; this.ka = ka;
3250
}
3351

52+
/**
53+
* Configure the Encoders being used in the follower.
54+
* @param initial_position The initial 'offset' of your encoder. This should be set to the encoder value just
55+
* before you start to track
56+
* @param ticks_per_revolution How many ticks per revolution the encoder has
57+
* @param wheel_diameter The diameter of your wheels (or pulleys for track systems) in meters
58+
*/
3459
public void configureEncoder(int initial_position, int ticks_per_revolution, double wheel_diameter) {
3560
encoder_offset = initial_position;
3661
encoder_tick_count = ticks_per_revolution;
3762
wheel_circumference = Math.PI * wheel_diameter;
3863
}
3964

65+
/**
66+
* Reset the follower to start again. Encoders must be reconfigured.
67+
*/
4068
public void reset() {
4169
last_error = 0; segment = 0;
4270
}
4371

72+
/**
73+
* Calculate the desired output for the motors, based on the amount of ticks the encoder has gone through.
74+
* This does not account for heading of the robot. To account for heading, add some extra terms in your control
75+
* loop for realignment based on gyroscope input and the desired heading given by this object.
76+
* @param encoder_tick The amount of ticks the encoder has currently measured.
77+
* @return The desired output for your motor controller
78+
*/
4479
public double calculate(int encoder_tick) {
4580
// Number of Revolutions * Wheel Circumference
4681
double distance_covered = ((double)(encoder_tick - encoder_offset) / encoder_tick_count)
@@ -60,14 +95,23 @@ public double calculate(int encoder_tick) {
6095
} else return 0;
6196
}
6297

98+
/**
99+
* @return the desired heading of the current point in the trajectory
100+
*/
63101
public double getHeading() {
64102
return heading;
65103
}
66104

105+
/**
106+
* @return the current segment being operated on
107+
*/
67108
public Trajectory.Segment getSegment() {
68109
return trajectory.get(segment);
69110
}
70111

112+
/**
113+
* @return whether we have finished tracking this trajectory or not.
114+
*/
71115
public boolean isFinished() {
72116
return segment >= trajectory.length();
73117
}

0 commit comments

Comments
 (0)