Skip to content

Commit c886469

Browse files
committed
Correct a couple mistakes. Add mecanum to field oriented driving
1 parent 4265aac commit c886469

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

source/docs/software/basic-programming/coordinate-system.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ Games such as CHARGED UP in 2023 and CRESCENDO in 2024 used a mirrored layout. A
228228
.. figure:: images/coordinate-system/charged-up-field.jpg
229229
:alt: Mirrored CHARGED UP field from 2023
230230

231-
Mirrored field from Charged Up in 2023 [#]_
231+
Mirrored field from CHARGED UP in 2023 [#]_
232232

233233
Dealing with red or blue alliance
234234
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -255,9 +255,9 @@ Some advantages to this approach are:
255255
- Pose estimation with AprilTags is simplified. AprilTags throughout the field are unique. If you keep the coordinate system the same regardless of alliance, there is no need for special logic to deal the location of AprilTags on the field relative to your alliance.
256256
- Many of the tools and libraries used in FRC follow this convention. Some of the tools include: PathPlanner, Choreo, and the ShuffleBoard and Glass Field2d widget.
257257

258-
In order to use this approach for field oriented driving, driver input needs to consider the alliance color. When your alliance is red and the driver is standing behind the red alliance wall, they will want the robot to move toward down field toward the blue alliance wall. However, when your alliance is blue, the driver will want the robot to go down field toward the red alliance wall.
258+
In order to use this approach for field oriented driving, driver input needs to consider the alliance color. When your alliance is red and the driver is standing behind the red alliance wall, they will want the robot to move down field toward the blue alliance wall. However, when your alliance is blue, the driver will want the robot to go down field toward the red alliance wall.
259259

260-
A simple way to deal with field oriented driving is to check the alliance color reported by the `DriverStation` class, and invert the drivers controls based on the alliance. As noted above, your alliance color can change so it needs to be check on every robot iteration.
260+
A simple way to deal with field oriented driving is to check the alliance color reported by the `DriverStation` class, and invert the drivers controls based on the alliance. As noted above, your alliance color can change so it needs to be checked on every robot iteration.
261261

262262
.. tab-set-code::
263263

@@ -270,8 +270,12 @@ A simple way to deal with field oriented driving is to check the alliance color
270270
invert = -1;
271271
}
272272
273+
// Create field relative ChassisSpeeds for controlling Swerve
273274
var chassisSpeeds = ChassisSpeeds
274-
.fromFieldRelativeSpeeds(xSpeed * invert, ySpeed * invert, zRotation * invert, imu.getRotation2d());
275+
.fromFieldRelativeSpeeds(xSpeed * invert, ySpeed * invert, zRotation, imu.getRotation2d());
276+
277+
// Control a mecanum drivetrain
278+
m_robotDrive.driveCartesian(xSpeed * invert, ySpeed * invert, zRotation, imu.getRotation2d());
275279
276280
.. code-block:: c++
277281

@@ -281,8 +285,12 @@ A simple way to deal with field oriented driving is to check the alliance color
281285
invert = -1;
282286
}
283287

288+
// Create field relative ChassisSpeeds for controlling Swerve
284289
frc::ChassisSpeeds chassisSpeeds =
285-
frc::ChassisSpeeds::FromFieldRelativeSpeeds(xSpeed * invert, ySpeed * invert, zRotation * invert, imu.GetRotation2d());
290+
frc::ChassisSpeeds::FromFieldRelativeSpeeds(xSpeed * invert, ySpeed * invert, zRotation, imu.GetRotation2d());
291+
292+
// Control a mecanum drivetrain
293+
m_robotDrive.driveCartesian(xSpeed * invert, ySpeed * invert, zRotation, imu.GetRotation2d());
286294

287295
.. code-block:: python
288296
@@ -291,10 +299,14 @@ A simple way to deal with field oriented driving is to check the alliance color
291299
if wpilib.DriverStation.GetInstance().GetAlliance() == wpilib.DriverStation.Alliance.kRed:
292300
invert = -1
293301
302+
# Create field relative ChassisSpeeds for controlling Swerve
294303
chassis_speeds = wpilib.ChassisSpeeds.FromFieldRelativeSpeeds(
295-
xSpeed * invert, ySpeed * invert, zRotation * invert, self.imu.GetAngle()
304+
xSpeed * invert, ySpeed * invert, zRotation, self.imu.GetAngle()
296305
)
297306
307+
# Control a mecanum drivetrain
308+
self.robotDrive.driveCartesian(xSpeed * invert, ySpeed * invert, zRotation, self.imu.GetAngle())
309+
298310
Origin follows your alliance
299311
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300312

0 commit comments

Comments
 (0)