Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Commit c14a4d8

Browse files
committed
have Followers do the actual following
1 parent 7ca4709 commit c14a4d8

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

road-runner/ftc/src/main/java/com/acmerobotics/roadrunner/ftc/FollowTrajectoryAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class FollowTrajectoryAction(
5252
val yPoints = points.ys().toDoubleArray()
5353

5454
override fun run(p: TelemetryPacket): Boolean {
55-
drive.setDrivePowersWithFF(follower.follow())
55+
follower.follow()
5656

5757
p.put("x", drive.localizer.pose.position.x)
5858
p.put("y", drive.localizer.pose.position.y)

road-runner/ftc/src/main/java/com/acmerobotics/roadrunner/ftc/Following.kt

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,23 @@ data class FollowerParams(
2929
interface Follower {
3030
val trajectory: Trajectory<*>
3131
val currentTarget: Pose2d
32+
val lastCommand: PoseVelocity2dDual<Time>
3233

3334
val isDone: Boolean
3435

35-
fun follow() : PoseVelocity2dDual<Time>
36+
fun follow()
3637
}
3738

3839
class DisplacementFollower(
3940
override val trajectory: DisplacementTrajectory,
40-
@JvmField val controller: RobotPosVelController,
41-
@JvmField val localizer: Localizer
41+
val drive: Drive
4242
) : Follower {
4343
constructor(
4444
traj: Trajectory<*>,
4545
drive: Drive
4646
) : this(
4747
traj.wrtDisp(),
48-
drive.controller,
49-
drive.localizer
48+
drive
5049
)
5150

5251
@JvmOverloads
@@ -78,9 +77,12 @@ class DisplacementFollower(
7877
override var currentTarget = trajectory.path.begin(1).value()
7978
private set
8079

81-
override fun follow() : PoseVelocity2dDual<Time> {
82-
val robotVel = localizer.update()
83-
val robotPose = localizer.pose
80+
override var lastCommand = PoseVelocity2dDual.constant<Time>(PoseVelocity2d(Vector2d(0.0, 0.0), 0.0), 1)
81+
private set
82+
83+
fun getDriveCommand() : PoseVelocity2dDual<Time> {
84+
val robotVel = drive.localizer.update()
85+
val robotPose = drive.localizer.pose
8486

8587
ds = trajectory.project(robotPose.position, ds)
8688

@@ -93,26 +95,29 @@ class DisplacementFollower(
9395
val target = trajectory[ds]
9496
currentTarget = target.value()
9597

96-
return controller.compute(
98+
return drive.controller.compute(
9799
target,
98100
robotPose,
99101
robotVel
100102
)
101103
}
104+
105+
override fun follow() {
106+
lastCommand = getDriveCommand()
107+
drive.setDrivePowersWithFF(lastCommand)
108+
}
102109
}
103110

104111
class TimeFollower(
105112
override val trajectory: TimeTrajectory,
106-
@JvmField val controller: RobotPosVelController,
107-
@JvmField val localizer: Localizer
113+
val drive: Drive
108114
) : Follower {
109115
constructor(
110116
traj: Trajectory<*>,
111117
drive: Drive
112118
) : this(
113119
traj.wrtTime(),
114-
drive.controller,
115-
drive.localizer
120+
drive
116121
)
117122

118123
@JvmOverloads
@@ -144,7 +149,10 @@ class TimeFollower(
144149
override var isDone = false
145150
private set
146151

147-
override fun follow(): PoseVelocity2dDual<Time> {
152+
override var lastCommand = PoseVelocity2dDual.constant<Time>(PoseVelocity2d(Vector2d(0.0, 0.0), 0.0), 1)
153+
private set
154+
155+
fun getDriveCommand(): PoseVelocity2dDual<Time> {
148156
if (startTime < 0) {
149157
startTime = now()
150158
} else {
@@ -157,12 +165,17 @@ class TimeFollower(
157165
}
158166

159167
val target = trajectory[dt]
160-
val robotVel = localizer.update()
168+
val robotVel = drive.localizer.update()
161169

162-
return controller.compute(
170+
return drive.controller.compute(
163171
target,
164-
localizer.pose,
172+
drive.localizer.pose,
165173
robotVel
166174
)
167175
}
176+
177+
override fun follow() {
178+
lastCommand = getDriveCommand()
179+
drive.setDrivePowersWithFF(lastCommand)
180+
}
168181
}

0 commit comments

Comments
 (0)