CTRE Phoenix 6 C++ 26.50.0-alpha-1
Loading...
Searching...
No Matches
SwerveRequest.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
11
12namespace ctre {
13namespace phoenix6 {
14namespace swerve {
15namespace requests {
16
17/**
18 * \brief In field-centric control, the direction of "forward" is sometimes different
19 * depending on perspective. This addresses which forward to use.
20 */
22 /**
23 * \brief "Forward" (positive X) is determined from the operator's perspective.
24 * This is important for most teleop driven field-centric requests, where positive
25 * X means to drive away from the operator.
26 *
27 * Important: Users must specify the OperatorPerspective in the SwerveDrivetrain object
28 */
30 /**
31 * \brief "Forward" (positive X) is always from the perspective of the blue alliance (i.e.
32 * towards the red alliance). This is important in situations such as path following where
33 * positive X is always from the blue alliance perspective, regardless of where the operator
34 * is physically located.
35 */
37};
38
39/**
40 * \brief In field-centric control, the direction of "forward" for the target direction
41 * sometimes differs from "forward" for translation. This addresses which forward to use.
42 */
44 /**
45 * \brief Match the ForwardPerspective parameter for heading control.
46 */
48 /**
49 * \brief "Forward" (0 deg) is always from the perspective of the blue alliance (i.e.
50 * towards the red alliance). This can be used to allow for the robot rotation to track
51 * vision targets while using operator-perspective joystick control for translation.
52 */
54};
55
56/**
57 * \brief Container for all the Swerve Requests. Use this to find all applicable swerve
58 * drive requests.
59 *
60 * This is also an interface common to all swerve drive control requests that
61 * allow the request to calculate the state to apply to the modules.
62 */
64public:
66
67 virtual ~SwerveRequest() = default;
68
69 /**
70 * \brief Applies this swerve request to the given modules.
71 * This is typically called by the SwerveDrivetrain.
72 *
73 * \param parameters Parameters the control request needs to calculate the module state
74 * \param modulesToApply Modules to which the control request is applied
75 * \returns Status code of sending the request
76 */
77 virtual ctre::phoenix::StatusCode Apply(ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) = 0;
78};
79
80/**
81 * \brief Does nothing to the swerve module state. This is the default state of a newly
82 * created swerve drive mechanism.
83 */
84class Idle : public SwerveRequest {
85public:
86 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> ) override
87 {
89 }
90};
91
92/**
93 * \brief Sets the swerve drive module states to point inward on the
94 * robot in an "X" fashion, creating a natural brake which will
95 * oppose any motion.
96 */
98public:
99 /**
100 * \brief The type of control request to use for the drive motor.
101 */
103 /**
104 * \brief The type of control request to use for the steer motor.
105 */
107
108 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
109 {
110 auto moduleRequest = impl::SwerveModuleImpl::ModuleRequest{}
113 .WithUpdatePeriod(parameters.updatePeriod);
114 for (size_t i = 0; i < modulesToApply.size(); ++i) {
115 modulesToApply[i]->Apply(moduleRequest.WithVelocity({0_mps, parameters.moduleLocations[i].Angle()}));
116 }
117
119 }
120
121 /**
122 * \brief Modifies the DriveRequestType parameter and returns itself.
123 *
124 * The type of control request to use for the drive motor.
125 *
126 * \param newDriveRequestType Parameter to modify
127 * \returns this object
128 */
130 {
131 this->DriveRequestType = std::move(newDriveRequestType);
132 return *this;
133 }
134 /**
135 * \brief Modifies the DriveRequestType parameter and returns itself.
136 *
137 * The type of control request to use for the drive motor.
138 *
139 * \param newDriveRequestType Parameter to modify
140 * \returns this object
141 */
143 {
144 this->DriveRequestType = std::move(newDriveRequestType);
145 return std::move(*this);
146 }
147
148 /**
149 * \brief Modifies the SteerRequestType parameter and returns itself.
150 *
151 * The type of control request to use for the steer motor.
152 *
153 * \param newSteerRequestType Parameter to modify
154 * \returns this object
155 */
157 {
158 this->SteerRequestType = std::move(newSteerRequestType);
159 return *this;
160 }
161 /**
162 * \brief Modifies the SteerRequestType parameter and returns itself.
163 *
164 * The type of control request to use for the steer motor.
165 *
166 * \param newSteerRequestType Parameter to modify
167 * \returns this object
168 */
170 {
171 this->SteerRequestType = std::move(newSteerRequestType);
172 return std::move(*this);
173 }
174};
175
176/**
177 * \brief Drives the swerve drivetrain in a field-centric manner. This request
178 * is optimized for joystick control during teleop with built-in deadbands.
179 *
180 * This request specifies the direction the robot should travel oriented against
181 * the field, and the rate at which their robot should rotate about the center
182 * of the robot.
183 *
184 * An example scenario is that the robot is oriented to the field +Y (left), the
185 * VelocityX is +5 m/s, VelocityY is 0 m/s, and RotationRate is 0.5 rad/s. In
186 * this scenario, the robot would drive along the field +X (forward) at 5 m/s
187 * and turn counterclockwise at 0.5 rad/s.
188 */
190public:
191 /**
192 * \brief The velocity in the X direction. X is defined as forward according
193 * toWPILib convention, so this determines how fast to travel forward.
194 */
195 wpi::units::meters_per_second_t VelocityX = 0_mps;
196 /**
197 * \brief The velocity in the Y direction. Y is defined as to the left
198 * according to WPILib convention, so this determines how fast to travel to
199 * the left.
200 */
201 wpi::units::meters_per_second_t VelocityY = 0_mps;
202 /**
203 * \brief The angular rate to rotate at. Angular rate is defined as
204 * counterclockwise positive, so this determines how fast to turn
205 * counterclockwise.
206 */
207 wpi::units::radians_per_second_t RotationalRate = 0_rad_per_s;
208 /**
209 * \brief The allowable deadband of the request.
210 */
211 wpi::units::meters_per_second_t Deadband = 0_mps;
212 /**
213 * \brief The rotational deadband of the request.
214 */
215 wpi::units::radians_per_second_t RotationalDeadband = 0_rad_per_s;
216 /**
217 * \brief The center of rotation the robot should rotate around. This is
218 * (0,0) by default, which will rotate around the center of the robot.
219 */
220 Translation2d CenterOfRotation{};
221
222 /**
223 * \brief The type of control request to use for the drive motor.
224 */
226 /**
227 * \brief The type of control request to use for the steer motor.
228 */
230 /**
231 * \brief Whether to desaturate wheel velocities before applying.
232 * For more information, see the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
233 */
235
236 /**
237 * \brief The perspective to use when determining which direction is forward.
238 */
240
241 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
242 {
243 auto toApplyX = VelocityX;
244 auto toApplyY = VelocityY;
245 auto toApplyOmega = RotationalRate;
246
248 /* If we're operator perspective, modify the X/Y translation by the angle */
249 Translation2d tmp{toApplyX * 1_s, toApplyY * 1_s};
250 tmp = tmp.RotateBy(parameters.operatorForwardDirection);
251 toApplyX = tmp.X() / 1_s;
252 toApplyY = tmp.Y() / 1_s;
253 }
254
255 if (wpi::units::math::hypot(toApplyX, toApplyY) < Deadband) {
256 toApplyX = 0_mps;
257 toApplyY = 0_mps;
258 }
259 if (wpi::units::math::abs(toApplyOmega) < RotationalDeadband) {
260 toApplyOmega = 0_rad_per_s;
261 }
262
263 auto const velocity = ChassisVelocities{toApplyX, toApplyY, toApplyOmega}
264 .ToRobotRelative(parameters.currentPose.Rotation())
265 .Discretize(parameters.updatePeriod);
266
267 auto moduleVelocities = parameters.kinematics->ToSwerveModuleVelocities(velocity, CenterOfRotation);
268 if (DesaturateWheelVelocities && parameters.kMaxSpeed > 0_mps) {
269 moduleVelocities = impl::SwerveDriveKinematics::DesaturateWheelVelocities(moduleVelocities, parameters.kMaxSpeed);
270 }
271
272 auto moduleRequest = impl::SwerveModuleImpl::ModuleRequest{}
275 .WithUpdatePeriod(parameters.updatePeriod);
276 for (size_t i = 0; i < modulesToApply.size(); ++i) {
277 modulesToApply[i]->Apply(moduleRequest.WithVelocity(moduleVelocities[i]));
278 }
279
281 }
282
283 /**
284 * \brief Modifies the VelocityX parameter and returns itself.
285 *
286 * The velocity in the X direction. X is defined as forward according to
287 * WPILib convention, so this determines how fast to travel forward.
288 *
289 * \param newVelocityX Parameter to modify
290 * \returns this object
291 */
292 FieldCentric &WithVelocityX(wpi::units::meters_per_second_t newVelocityX) &
293 {
294 this->VelocityX = std::move(newVelocityX);
295 return *this;
296 }
297 /**
298 * \brief Modifies the VelocityX parameter and returns itself.
299 *
300 * The velocity in the X direction. X is defined as forward according to
301 * WPILib convention, so this determines how fast to travel forward.
302 *
303 * \param newVelocityX Parameter to modify
304 * \returns this object
305 */
306 FieldCentric &&WithVelocityX(wpi::units::meters_per_second_t newVelocityX) &&
307 {
308 this->VelocityX = std::move(newVelocityX);
309 return std::move(*this);
310 }
311
312 /**
313 * \brief Modifies the VelocityY parameter and returns itself.
314 *
315 * The velocity in the Y direction. Y is defined as to the left according
316 * to WPILib convention, so this determines how fast to travel to the
317 * left.
318 *
319 * \param newVelocityY Parameter to modify
320 * \returns this object
321 */
322 FieldCentric &WithVelocityY(wpi::units::meters_per_second_t newVelocityY) &
323 {
324 this->VelocityY = std::move(newVelocityY);
325 return *this;
326 }
327 /**
328 * \brief Modifies the VelocityY parameter and returns itself.
329 *
330 * The velocity in the Y direction. Y is defined as to the left according
331 * to WPILib convention, so this determines how fast to travel to the
332 * left.
333 *
334 * \param newVelocityY Parameter to modify
335 * \returns this object
336 */
337 FieldCentric &&WithVelocityY(wpi::units::meters_per_second_t newVelocityY) &&
338 {
339 this->VelocityY = std::move(newVelocityY);
340 return std::move(*this);
341 }
342
343 /**
344 * \brief Modifies the RotationalRate parameter and returns itself.
345 *
346 * The angular rate to rotate at. Angular rate is defined as counterclockwise
347 * positive, so this determines how fast to turn counterclockwise.
348 *
349 * \param newRotationalRate Parameter to modify
350 * \returns this object
351 */
352 FieldCentric &WithRotationalRate(wpi::units::radians_per_second_t newRotationalRate) &
353 {
354 this->RotationalRate = std::move(newRotationalRate);
355 return *this;
356 }
357 /**
358 * \brief Modifies the RotationalRate parameter and returns itself.
359 *
360 * The angular rate to rotate at. Angular rate is defined as counterclockwise
361 * positive, so this determines how fast to turn counterclockwise.
362 *
363 * \param newRotationalRate Parameter to modify
364 * \returns this object
365 */
366 FieldCentric &&WithRotationalRate(wpi::units::radians_per_second_t newRotationalRate) &&
367 {
368 this->RotationalRate = std::move(newRotationalRate);
369 return std::move(*this);
370 }
371
372 /**
373 * \brief Modifies the Deadband parameter and returns itself.
374 *
375 * The allowable deadband of the request.
376 *
377 * \param newDeadband Parameter to modify
378 * \returns this object
379 */
380 FieldCentric &WithDeadband(wpi::units::meters_per_second_t newDeadband) &
381 {
382 this->Deadband = std::move(newDeadband);
383 return *this;
384 }
385 /**
386 * \brief Modifies the Deadband parameter and returns itself.
387 *
388 * The allowable deadband of the request.
389 *
390 * \param newDeadband Parameter to modify
391 * \returns this object
392 */
393 FieldCentric &&WithDeadband(wpi::units::meters_per_second_t newDeadband) &&
394 {
395 this->Deadband = std::move(newDeadband);
396 return std::move(*this);
397 }
398
399 /**
400 * \brief Modifies the RotationalDeadband parameter and returns itself.
401 *
402 * The rotational deadband of the request.
403 *
404 * \param newRotationalDeadband Parameter to modify
405 * \returns this object
406 */
407 FieldCentric &WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband) &
408 {
409 this->RotationalDeadband = std::move(newRotationalDeadband);
410 return *this;
411 }
412 /**
413 * \brief Modifies the RotationalDeadband parameter and returns itself.
414 *
415 * The rotational deadband of the request.
416 *
417 * \param newRotationalDeadband Parameter to modify
418 * \returns this object
419 */
420 FieldCentric &&WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband) &&
421 {
422 this->RotationalDeadband = std::move(newRotationalDeadband);
423 return std::move(*this);
424 }
425
426 /**
427 * \brief Modifies the CenterOfRotation parameter and returns itself.
428 *
429 * The center of rotation the robot should rotate around. This is (0,0) by
430 * default, which will rotate around the center of the robot.
431 *
432 * \param newCenterOfRotation Parameter to modify
433 * \returns this object
434 */
435 FieldCentric &WithCenterOfRotation(Translation2d newCenterOfRotation) &
436 {
437 this->CenterOfRotation = std::move(newCenterOfRotation);
438 return *this;
439 }
440 /**
441 * \brief Modifies the CenterOfRotation parameter and returns itself.
442 *
443 * The center of rotation the robot should rotate around. This is (0,0) by
444 * default, which will rotate around the center of the robot.
445 *
446 * \param newCenterOfRotation Parameter to modify
447 * \returns this object
448 */
449 FieldCentric &&WithCenterOfRotation(Translation2d newCenterOfRotation) &&
450 {
451 this->CenterOfRotation = std::move(newCenterOfRotation);
452 return std::move(*this);
453 }
454
455 /**
456 * \brief Modifies the DriveRequestType parameter and returns itself.
457 *
458 * The type of control request to use for the drive motor.
459 *
460 * \param newDriveRequestType Parameter to modify
461 * \returns this object
462 */
464 {
465 this->DriveRequestType = std::move(newDriveRequestType);
466 return *this;
467 }
468 /**
469 * \brief Modifies the DriveRequestType parameter and returns itself.
470 *
471 * The type of control request to use for the drive motor.
472 *
473 * \param newDriveRequestType Parameter to modify
474 * \returns this object
475 */
477 {
478 this->DriveRequestType = std::move(newDriveRequestType);
479 return std::move(*this);
480 }
481
482 /**
483 * \brief Modifies the SteerRequestType parameter and returns itself.
484 *
485 * The type of control request to use for the steer motor.
486 *
487 * \param newSteerRequestType Parameter to modify
488 * \returns this object
489 */
491 {
492 this->SteerRequestType = std::move(newSteerRequestType);
493 return *this;
494 }
495 /**
496 * \brief Modifies the SteerRequestType parameter and returns itself.
497 *
498 * The type of control request to use for the steer motor.
499 *
500 * \param newSteerRequestType Parameter to modify
501 * \returns this object
502 */
504 {
505 this->SteerRequestType = std::move(newSteerRequestType);
506 return std::move(*this);
507 }
508
509 /**
510 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
511 *
512 * Whether to desaturate wheel velocities before applying. For more information, see
513 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
514 *
515 * \param newDesaturateWheelVelocities Parameter to modify
516 * \returns this object
517 */
518 FieldCentric &WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &
519 {
520 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
521 return *this;
522 }
523 /**
524 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
525 *
526 * Whether to desaturate wheel velocities before applying. For more information, see
527 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
528 *
529 * \param newDesaturateWheelVelocities Parameter to modify
530 * \returns this object
531 */
532 FieldCentric &&WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &&
533 {
534 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
535 return std::move(*this);
536 }
537
538 /**
539 * \brief Modifies the ForwardPerspective parameter and returns itself.
540 *
541 * The perspective to use when determining which direction is forward.
542 *
543 * \param newForwardPerspective Parameter to modify
544 * \returns this object
545 */
547 {
548 this->ForwardPerspective = std::move(newForwardPerspective);
549 return *this;
550 }
551 /**
552 * \brief Modifies the ForwardPerspective parameter and returns itself.
553 *
554 * The perspective to use when determining which direction is forward.
555 *
556 * \param newForwardPerspective Parameter to modify
557 * \returns this object
558 */
560 {
561 this->ForwardPerspective = std::move(newForwardPerspective);
562 return std::move(*this);
563 }
564};
565
566/**
567 * \brief Drives the swerve drivetrain in a robot-centric manner. This request
568 * is optimized for joystick control during teleop with built-in deadbands.
569 *
570 * This request specifies the direction the robot should travel oriented against
571 * the robot itself, and the rate at which their robot should rotate about the
572 * center of the robot.
573 *
574 * An example scenario is that the robot is oriented to the field +Y (left), the
575 * VelocityX is +5 m/s, VelocityY is 0 m/s, and RotationRate is 0.5 rad/s. In
576 * this scenario, the robot would drive forward relative to itself (or left
577 * along the field +Y) at 5 m/s and turn counterclockwise at 0.5 rad/s.
578 */
580public:
581 /**
582 * \brief The velocity in the X direction. X is defined as forward according
583 * toWPILib convention, so this determines how fast to travel forward.
584 */
585 wpi::units::meters_per_second_t VelocityX = 0_mps;
586 /**
587 * \brief The velocity in the Y direction. Y is defined as to the left
588 * according to WPILib convention, so this determines how fast to travel to
589 * the left.
590 */
591 wpi::units::meters_per_second_t VelocityY = 0_mps;
592 /**
593 * \brief The angular rate to rotate at. Angular rate is defined as
594 * counterclockwise positive, so this determines how fast to turn
595 * counterclockwise.
596 */
597 wpi::units::radians_per_second_t RotationalRate = 0_rad_per_s;
598
599 /**
600 * \brief The allowable deadband of the request.
601 */
602 wpi::units::meters_per_second_t Deadband = 0_mps;
603 /**
604 * \brief The rotational deadband of the request.
605 */
606 wpi::units::radians_per_second_t RotationalDeadband = 0_rad_per_s;
607 /**
608 * \brief The center of rotation the robot should rotate around. This is
609 * (0,0) by default, which will rotate around the center of the robot.
610 */
611 Translation2d CenterOfRotation{};
612
613 /**
614 * \brief The type of control request to use for the drive motor.
615 */
617 /**
618 * \brief The type of control request to use for the steer motor.
619 */
621 /**
622 * \brief Whether to desaturate wheel velocities before applying.
623 * For more information, see the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
624 */
626
627 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
628 {
629 auto toApplyX = VelocityX;
630 auto toApplyY = VelocityY;
631 auto toApplyOmega = RotationalRate;
632 if (wpi::units::math::hypot(toApplyX, toApplyY) < Deadband) {
633 toApplyX = 0_mps;
634 toApplyY = 0_mps;
635 }
636 if (wpi::units::math::abs(toApplyOmega) < RotationalDeadband) {
637 toApplyOmega = 0_rad_per_s;
638 }
639 ChassisVelocities const velocity{toApplyX, toApplyY, toApplyOmega};
640
641 auto moduleVelocities = parameters.kinematics->ToSwerveModuleVelocities(velocity, CenterOfRotation);
642 if (DesaturateWheelVelocities && parameters.kMaxSpeed > 0_mps) {
643 moduleVelocities = impl::SwerveDriveKinematics::DesaturateWheelVelocities(moduleVelocities, parameters.kMaxSpeed);
644 }
645
646 auto moduleRequest = impl::SwerveModuleImpl::ModuleRequest{}
649 .WithUpdatePeriod(parameters.updatePeriod);
650 for (size_t i = 0; i < modulesToApply.size(); ++i) {
651 modulesToApply[i]->Apply(moduleRequest.WithVelocity(moduleVelocities[i]));
652 }
653
655 }
656
657 /**
658 * \brief Modifies the VelocityX parameter and returns itself.
659 *
660 * The velocity in the X direction. X is defined as forward according to
661 * WPILib convention, so this determines how fast to travel forward.
662 *
663 * \param newVelocityX Parameter to modify
664 * \returns this object
665 */
666 RobotCentric &WithVelocityX(wpi::units::meters_per_second_t newVelocityX) &
667 {
668 this->VelocityX = std::move(newVelocityX);
669 return *this;
670 }
671 /**
672 * \brief Modifies the VelocityX parameter and returns itself.
673 *
674 * The velocity in the X direction. X is defined as forward according to
675 * WPILib convention, so this determines how fast to travel forward.
676 *
677 * \param newVelocityX Parameter to modify
678 * \returns this object
679 */
680 RobotCentric &&WithVelocityX(wpi::units::meters_per_second_t newVelocityX) &&
681 {
682 this->VelocityX = std::move(newVelocityX);
683 return std::move(*this);
684 }
685
686 /**
687 * \brief Modifies the VelocityY parameter and returns itself.
688 *
689 * The velocity in the Y direction. Y is defined as to the left according
690 * to WPILib convention, so this determines how fast to travel to the
691 * left.
692 *
693 * \param newVelocityY Parameter to modify
694 * \returns this object
695 */
696 RobotCentric &WithVelocityY(wpi::units::meters_per_second_t newVelocityY) &
697 {
698 this->VelocityY = std::move(newVelocityY);
699 return *this;
700 }
701 /**
702 * \brief Modifies the VelocityY parameter and returns itself.
703 *
704 * The velocity in the Y direction. Y is defined as to the left according
705 * to WPILib convention, so this determines how fast to travel to the
706 * left.
707 *
708 * \param newVelocityY Parameter to modify
709 * \returns this object
710 */
711 RobotCentric &&WithVelocityY(wpi::units::meters_per_second_t newVelocityY) &&
712 {
713 this->VelocityY = std::move(newVelocityY);
714 return std::move(*this);
715 }
716
717 /**
718 * \brief Modifies the RotationalRate parameter and returns itself.
719 *
720 * The angular rate to rotate at. Angular rate is defined as counterclockwise
721 * positive, so this determines how fast to turn counterclockwise.
722 *
723 * \param newRotationalRate Parameter to modify
724 * \returns this object
725 */
726 RobotCentric &WithRotationalRate(wpi::units::radians_per_second_t newRotationalRate) &
727 {
728 this->RotationalRate = std::move(newRotationalRate);
729 return *this;
730 }
731 /**
732 * \brief Modifies the RotationalRate parameter and returns itself.
733 *
734 * The angular rate to rotate at. Angular rate is defined as counterclockwise
735 * positive, so this determines how fast to turn counterclockwise.
736 *
737 * \param newRotationalRate Parameter to modify
738 * \returns this object
739 */
740 RobotCentric &&WithRotationalRate(wpi::units::radians_per_second_t newRotationalRate) &&
741 {
742 this->RotationalRate = std::move(newRotationalRate);
743 return std::move(*this);
744 }
745
746 /**
747 * \brief Modifies the Deadband parameter and returns itself.
748 *
749 * The allowable deadband of the request.
750 *
751 * \param newDeadband Parameter to modify
752 * \returns this object
753 */
754 RobotCentric &WithDeadband(wpi::units::meters_per_second_t newDeadband) &
755 {
756 this->Deadband = std::move(newDeadband);
757 return *this;
758 }
759 /**
760 * \brief Modifies the Deadband parameter and returns itself.
761 *
762 * The allowable deadband of the request.
763 *
764 * \param newDeadband Parameter to modify
765 * \returns this object
766 */
767 RobotCentric &&WithDeadband(wpi::units::meters_per_second_t newDeadband) &&
768 {
769 this->Deadband = std::move(newDeadband);
770 return std::move(*this);
771 }
772
773 /**
774 * \brief Modifies the RotationalDeadband parameter and returns itself.
775 *
776 * The rotational deadband of the request.
777 *
778 * \param newRotationalDeadband Parameter to modify
779 * \returns this object
780 */
781 RobotCentric &WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband) &
782 {
783 this->RotationalDeadband = std::move(newRotationalDeadband);
784 return *this;
785 }
786 /**
787 * \brief Modifies the RotationalDeadband parameter and returns itself.
788 *
789 * The rotational deadband of the request.
790 *
791 * \param newRotationalDeadband Parameter to modify
792 * \returns this object
793 */
794 RobotCentric &&WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband) &&
795 {
796 this->RotationalDeadband = std::move(newRotationalDeadband);
797 return std::move(*this);
798 }
799
800 /**
801 * \brief Modifies the CenterOfRotation parameter and returns itself.
802 *
803 * The center of rotation the robot should rotate around. This is (0,0) by
804 * default, which will rotate around the center of the robot.
805 *
806 * \param newCenterOfRotation Parameter to modify
807 * \returns this object
808 */
809 RobotCentric &WithCenterOfRotation(Translation2d newCenterOfRotation) &
810 {
811 this->CenterOfRotation = std::move(newCenterOfRotation);
812 return *this;
813 }
814 /**
815 * \brief Modifies the CenterOfRotation parameter and returns itself.
816 *
817 * The center of rotation the robot should rotate around. This is (0,0) by
818 * default, which will rotate around the center of the robot.
819 *
820 * \param newCenterOfRotation Parameter to modify
821 * \returns this object
822 */
823 RobotCentric &&WithCenterOfRotation(Translation2d newCenterOfRotation) &&
824 {
825 this->CenterOfRotation = std::move(newCenterOfRotation);
826 return std::move(*this);
827 }
828
829 /**
830 * \brief Modifies the DriveRequestType parameter and returns itself.
831 *
832 * The type of control request to use for the drive motor.
833 *
834 * \param newDriveRequestType Parameter to modify
835 * \returns this object
836 */
838 {
839 this->DriveRequestType = std::move(newDriveRequestType);
840 return *this;
841 }
842 /**
843 * \brief Modifies the DriveRequestType parameter and returns itself.
844 *
845 * The type of control request to use for the drive motor.
846 *
847 * \param newDriveRequestType Parameter to modify
848 * \returns this object
849 */
851 {
852 this->DriveRequestType = std::move(newDriveRequestType);
853 return std::move(*this);
854 }
855
856 /**
857 * \brief Modifies the SteerRequestType parameter and returns itself.
858 *
859 * The type of control request to use for the steer motor.
860 *
861 * \param newSteerRequestType Parameter to modify
862 * \returns this object
863 */
865 {
866 this->SteerRequestType = std::move(newSteerRequestType);
867 return *this;
868 }
869 /**
870 * \brief Modifies the SteerRequestType parameter and returns itself.
871 *
872 * The type of control request to use for the steer motor.
873 *
874 * \param newSteerRequestType Parameter to modify
875 * \returns this object
876 */
878 {
879 this->SteerRequestType = std::move(newSteerRequestType);
880 return std::move(*this);
881 }
882
883 /**
884 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
885 *
886 * Whether to desaturate wheel velocities before applying. For more information, see
887 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
888 *
889 * \param newDesaturateWheelVelocities Parameter to modify
890 * \returns this object
891 */
892 RobotCentric &WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &
893 {
894 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
895 return *this;
896 }
897 /**
898 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
899 *
900 * Whether to desaturate wheel velocities before applying. For more information, see
901 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
902 *
903 * \param newDesaturateWheelVelocities Parameter to modify
904 * \returns this object
905 */
906 RobotCentric &&WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &&
907 {
908 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
909 return std::move(*this);
910 }
911};
912
913/**
914 * \brief Sets the swerve drive modules to point to a specified direction.
915 */
917public:
918 /**
919 * \brief The direction to point the modules toward. This direction is still
920 * optimized to what the module was previously at.
921 */
922 Rotation2d ModuleDirection{};
923 /**
924 * \brief The type of control request to use for the drive motor.
925 */
927 /**
928 * \brief The type of control request to use for the steer motor.
929 */
931
932 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
933 {
934 auto moduleRequest = impl::SwerveModuleImpl::ModuleRequest{}
937 .WithUpdatePeriod(parameters.updatePeriod);
938 for (size_t i = 0; i < modulesToApply.size(); ++i) {
939 modulesToApply[i]->Apply(moduleRequest.WithVelocity({0_mps, ModuleDirection}));
940 }
941
943 }
944
945 /**
946 * \brief Modifies the ModuleDirection parameter and returns itself.
947 *
948 * The direction to point the modules toward. This direction is still optimized
949 * to what the module was previously at.
950 *
951 * \param newModuleDirection Parameter to modify
952 * \returns this object
953 */
954 PointWheelsAt &WithModuleDirection(Rotation2d newModuleDirection) &
955 {
956 this->ModuleDirection = std::move(newModuleDirection);
957 return *this;
958 }
959 /**
960 * \brief Modifies the ModuleDirection parameter and returns itself.
961 *
962 * The direction to point the modules toward. This direction is still optimized
963 * to what the module was previously at.
964 *
965 * \param newModuleDirection Parameter to modify
966 * \returns this object
967 */
968 PointWheelsAt &&WithModuleDirection(Rotation2d newModuleDirection) &&
969 {
970 this->ModuleDirection = std::move(newModuleDirection);
971 return std::move(*this);
972 }
973
974 /**
975 * \brief Modifies the DriveRequestType parameter and returns itself.
976 *
977 * The type of control request to use for the drive motor.
978 *
979 * \param newDriveRequestType Parameter to modify
980 * \returns this object
981 */
983 {
984 this->DriveRequestType = std::move(newDriveRequestType);
985 return *this;
986 }
987 /**
988 * \brief Modifies the DriveRequestType parameter and returns itself.
989 *
990 * The type of control request to use for the drive motor.
991 *
992 * \param newDriveRequestType Parameter to modify
993 * \returns this object
994 */
996 {
997 this->DriveRequestType = std::move(newDriveRequestType);
998 return std::move(*this);
999 }
1000
1001 /**
1002 * \brief Modifies the SteerRequestType parameter and returns itself.
1003 *
1004 * The type of control request to use for the steer motor.
1005 *
1006 * \param newSteerRequestType Parameter to modify
1007 * \returns this object
1008 */
1010 {
1011 this->SteerRequestType = std::move(newSteerRequestType);
1012 return *this;
1013 }
1014 /**
1015 * \brief Modifies the SteerRequestType parameter and returns itself.
1016 *
1017 * The type of control request to use for the steer motor.
1018 *
1019 * \param newSteerRequestType Parameter to modify
1020 * \returns this object
1021 */
1023 {
1024 this->SteerRequestType = std::move(newSteerRequestType);
1025 return std::move(*this);
1026 }
1027};
1028
1029/**
1030 * \brief Accepts a generic robot-centric ChassisVelocities to apply to the drivetrain.
1031 * This request is optimized for autonomous or profiled control, which typically
1032 * directly provides ChassisVelocities and optionally wheel force feedforwards.
1033 *
1034 * Unlike the field-centric requests, this request does not automatically
1035 * discretize the provided ChassisVelocities.
1036 */
1038public:
1039 /**
1040 * \brief The robot-centric chassis velocity to apply to the drivetrain.
1041 * Users must manually discretize the velocity if appropriate.
1042 */
1043 ChassisVelocities Velocity{};
1044 /**
1045 * \brief Robot-centric wheel force feedforwards to apply in the
1046 * X direction. X is defined as forward according to WPILib
1047 * convention, so this determines the forward forces to apply.
1048 *
1049 * These forces should include friction applied to the ground.
1050 *
1051 * The order of the forces should match the order of the modules
1052 * returned from SwerveDrivetrain.
1053 */
1054 std::vector<wpi::units::newton_t> WheelForceFeedforwardsX;
1055 /**
1056 * \brief Robot-centric wheel force feedforwards to apply in the
1057 * Y direction. Y is defined as to the left according to WPILib
1058 * convention, so this determines the forces to apply to the left.
1059 *
1060 * These forces should include friction applied to the ground.
1061 *
1062 * The order of the forces should match the order of the modules
1063 * returned from SwerveDrivetrain.
1064 */
1065 std::vector<wpi::units::newton_t> WheelForceFeedforwardsY;
1066 /**
1067 * \brief The center of rotation to rotate around.
1068 */
1069 Translation2d CenterOfRotation{};
1070 /**
1071 * \brief The type of control request to use for the drive motor.
1072 */
1074 /**
1075 * \brief The type of control request to use for the steer motor.
1076 */
1078 /**
1079 * \brief Whether to desaturate wheel velocities before applying.
1080 * For more information, see the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
1081 */
1083
1084 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
1085 {
1086 auto moduleVelocities = parameters.kinematics->ToSwerveModuleVelocities(Velocity, CenterOfRotation);
1087 if (DesaturateWheelVelocities && parameters.kMaxSpeed > 0_mps) {
1088 moduleVelocities = impl::SwerveDriveKinematics::DesaturateWheelVelocities(moduleVelocities, parameters.kMaxSpeed);
1089 }
1090
1091 auto moduleRequest = impl::SwerveModuleImpl::ModuleRequest{}
1094 .WithUpdatePeriod(parameters.updatePeriod);
1095 for (size_t i = 0; i < modulesToApply.size(); ++i) {
1096 if (i < WheelForceFeedforwardsX.size() && i < WheelForceFeedforwardsY.size()) {
1097 moduleRequest.WithWheelForceFeedforwardX(WheelForceFeedforwardsX[i])
1098 .WithWheelForceFeedforwardY(WheelForceFeedforwardsY[i]);
1099 }
1100 modulesToApply[i]->Apply(moduleRequest.WithVelocity(moduleVelocities[i]));
1101 }
1102
1104 }
1105
1106 /**
1107 * \brief Modifies the Velocity parameter and returns itself.
1108 *
1109 * The robot-centric chassis velocity to apply to the drivetrain.
1110 * Users must manually discretize the velocity if appropriate.
1111 *
1112 * \param newVelocity Parameter to modify
1113 * \returns this object
1114 */
1115 ApplyRobotVelocity &WithVelocity(ChassisVelocities newVelocity) &
1116 {
1117 this->Velocity = std::move(newVelocity);
1118 return *this;
1119 }
1120 /**
1121 * \brief Modifies the Velocity parameter and returns itself.
1122 *
1123 * The robot-centric chassis velocity to apply to the drivetrain.
1124 * Users must manually discretize the velocity if appropriate.
1125 *
1126 * \param newVelocity Parameter to modify
1127 * \returns this object
1128 */
1129 ApplyRobotVelocity &&WithVelocity(ChassisVelocities newVelocity) &&
1130 {
1131 this->Velocity = std::move(newVelocity);
1132 return std::move(*this);
1133 }
1134
1135 /**
1136 * \brief Modifies the WheelForceFeedforwardsX parameter and returns itself.
1137 *
1138 * Robot-centric wheel force feedforwards to apply in the
1139 * X direction. X is defined as forward according to WPILib
1140 * convention, so this determines the forward forces to apply.
1141 *
1142 * These forces should include friction applied to the ground.
1143 *
1144 * The order of the forces should match the order of the modules
1145 * returned from SwerveDrivetrain.
1146 *
1147 * \param newWheelForceFeedforwardsX Parameter to modify
1148 * \returns this object
1149 */
1150 ApplyRobotVelocity &WithWheelForceFeedforwardsX(std::vector<wpi::units::newton_t> newWheelForceFeedforwardsX) &
1151 {
1152 this->WheelForceFeedforwardsX = std::move(newWheelForceFeedforwardsX);
1153 return *this;
1154 }
1155 /**
1156 * \brief Modifies the WheelForceFeedforwardsX parameter and returns itself.
1157 *
1158 * Robot-centric wheel force feedforwards to apply in the
1159 * X direction. X is defined as forward according to WPILib
1160 * convention, so this determines the forward forces to apply.
1161 *
1162 * These forces should include friction applied to the ground.
1163 *
1164 * The order of the forces should match the order of the modules
1165 * returned from SwerveDrivetrain.
1166 *
1167 * \param newWheelForceFeedforwardsX Parameter to modify
1168 * \returns this object
1169 */
1170 ApplyRobotVelocity &&WithWheelForceFeedforwardsX(std::vector<wpi::units::newton_t> newWheelForceFeedforwardsX) &&
1171 {
1172 this->WheelForceFeedforwardsX = std::move(newWheelForceFeedforwardsX);
1173 return std::move(*this);
1174 }
1175
1176 /**
1177 * \brief Modifies the WheelForceFeedforwardsY parameter and returns itself.
1178 *
1179 * Robot-centric wheel force feedforwards to apply in the
1180 * Y direction. Y is defined as to the left according to WPILib
1181 * convention, so this determines the forces to apply to the left.
1182 *
1183 * These forces should include friction applied to the ground.
1184 *
1185 * The order of the forces should match the order of the modules
1186 * returned from SwerveDrivetrain.
1187 *
1188 * \param newWheelForceFeedforwardsY Parameter to modify
1189 * \returns this object
1190 */
1191 ApplyRobotVelocity &WithWheelForceFeedforwardsY(std::vector<wpi::units::newton_t> newWheelForceFeedforwardsY) &
1192 {
1193 this->WheelForceFeedforwardsY = std::move(newWheelForceFeedforwardsY);
1194 return *this;
1195 }
1196 /**
1197 * \brief Modifies the WheelForceFeedforwardsY parameter and returns itself.
1198 *
1199 * Robot-centric wheel force feedforwards to apply in the
1200 * Y direction. Y is defined as to the left according to WPILib
1201 * convention, so this determines the forces to apply to the left.
1202 *
1203 * These forces should include friction applied to the ground.
1204 *
1205 * The order of the forces should match the order of the modules
1206 * returned from SwerveDrivetrain.
1207 *
1208 * \param newWheelForceFeedforwardsY Parameter to modify
1209 * \returns this object
1210 */
1211 ApplyRobotVelocity &&WithWheelForceFeedforwardsY(std::vector<wpi::units::newton_t> newWheelForceFeedforwardsY) &&
1212 {
1213 this->WheelForceFeedforwardsY = std::move(newWheelForceFeedforwardsY);
1214 return std::move(*this);
1215 }
1216
1217 /**
1218 * \brief Modifies the CenterOfRotation parameter and returns itself.
1219 *
1220 * The center of rotation the robot should rotate around. This is (0,0) by
1221 * default, which will rotate around the center of the robot.
1222 *
1223 * \param newCenterOfRotation Parameter to modify
1224 * \return this object
1225 */
1226 ApplyRobotVelocity &WithCenterOfRotation(Translation2d newCenterOfRotation) &
1227 {
1228 this->CenterOfRotation = std::move(newCenterOfRotation);
1229 return *this;
1230 }
1231 /**
1232 * \brief Modifies the CenterOfRotation parameter and returns itself.
1233 *
1234 * The center of rotation the robot should rotate around. This is (0,0) by
1235 * default, which will rotate around the center of the robot.
1236 *
1237 * \param newCenterOfRotation Parameter to modify
1238 * \return this object
1239 */
1240 ApplyRobotVelocity &&WithCenterOfRotation(Translation2d newCenterOfRotation) &&
1241 {
1242 this->CenterOfRotation = std::move(newCenterOfRotation);
1243 return std::move(*this);
1244 }
1245
1246 /**
1247 * \brief Modifies the DriveRequestType parameter and returns itself.
1248 *
1249 * The type of control request to use for the drive motor.
1250 *
1251 * \param newDriveRequestType Parameter to modify
1252 * \returns this object
1253 */
1255 {
1256 this->DriveRequestType = std::move(newDriveRequestType);
1257 return *this;
1258 }
1259 /**
1260 * \brief Modifies the DriveRequestType parameter and returns itself.
1261 *
1262 * The type of control request to use for the drive motor.
1263 *
1264 * \param newDriveRequestType Parameter to modify
1265 * \returns this object
1266 */
1268 {
1269 this->DriveRequestType = std::move(newDriveRequestType);
1270 return std::move(*this);
1271 }
1272
1273 /**
1274 * \brief Modifies the SteerRequestType parameter and returns itself.
1275 *
1276 * The type of control request to use for the steer motor.
1277 *
1278 * \param newSteerRequestType Parameter to modify
1279 * \returns this object
1280 */
1282 {
1283 this->SteerRequestType = std::move(newSteerRequestType);
1284 return *this;
1285 }
1286 /**
1287 * \brief Modifies the SteerRequestType parameter and returns itself.
1288 *
1289 * The type of control request to use for the steer motor.
1290 *
1291 * \param newSteerRequestType Parameter to modify
1292 * \returns this object
1293 */
1295 {
1296 this->SteerRequestType = std::move(newSteerRequestType);
1297 return std::move(*this);
1298 }
1299
1300 /**
1301 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
1302 *
1303 * Whether to desaturate wheel velocities before applying. For more information, see
1304 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
1305 *
1306 * \param newDesaturateWheelVelocities Parameter to modify
1307 * \returns this object
1308 */
1309 ApplyRobotVelocity &WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &
1310 {
1311 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
1312 return *this;
1313 }
1314 /**
1315 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
1316 *
1317 * Whether to desaturate wheel velocities before applying. For more information, see
1318 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
1319 *
1320 * \param newDesaturateWheelVelocities Parameter to modify
1321 * \returns this object
1322 */
1323 ApplyRobotVelocity &&WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &&
1324 {
1325 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
1326 return std::move(*this);
1327 }
1328};
1329
1330/**
1331 * \brief Accepts a generic field-centric ChassisVelocities to apply to the drivetrain.
1332 * This request is optimized for autonomous or profiled control, which typically
1333 * directly provides ChassisVelocities and optionally wheel force feedforwards.
1334 */
1336public:
1337 /**
1338 * \brief The field-centric chassis velocity to apply to the drivetrain.
1339 */
1340 ChassisVelocities Velocity{};
1341 /**
1342 * \brief Field-centric wheel force feedforwards to apply in the
1343 * X direction. X is defined as forward according to WPILib
1344 * convention, so this determines the forward forces to apply.
1345 *
1346 * These forces should include friction applied to the ground.
1347 *
1348 * The order of the forces should match the order of the modules
1349 * returned from SwerveDrivetrain.
1350 */
1351 std::vector<wpi::units::newton_t> WheelForceFeedforwardsX;
1352 /**
1353 * \brief Field-centric wheel force feedforwards to apply in the
1354 * Y direction. Y is defined as to the left according to WPILib
1355 * convention, so this determines the forces to apply to the left.
1356 *
1357 * These forces should include friction applied to the ground.
1358 *
1359 * The order of the forces should match the order of the modules
1360 * returned from SwerveDrivetrain.
1361 */
1362 std::vector<wpi::units::newton_t> WheelForceFeedforwardsY;
1363 /**
1364 * \brief The center of rotation to rotate around.
1365 */
1366 Translation2d CenterOfRotation{};
1367 /**
1368 * \brief The type of control request to use for the drive motor.
1369 */
1371 /**
1372 * \brief The type of control request to use for the steer motor.
1373 */
1375 /**
1376 * \brief Whether to desaturate wheel velocities before applying.
1377 * For more information, see the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
1378 */
1380
1381 /**
1382 * \brief The perspective to use when determining which direction is forward.
1383 */
1385
1386 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
1387 {
1388 auto fieldVelocity = Velocity;
1390 /* If we're operator perspective, modify the X/Y translation by the angle */
1391 Translation2d tmp{Velocity.vx * 1_s, Velocity.vy * 1_s};
1392 tmp = tmp.RotateBy(parameters.operatorForwardDirection);
1393 fieldVelocity.vx = tmp.X() / 1_s;
1394 fieldVelocity.vy = tmp.Y() / 1_s;
1395 }
1396
1397 auto const robotVelocity = fieldVelocity
1398 .ToRobotRelative(parameters.currentPose.Rotation())
1399 .Discretize(parameters.updatePeriod);
1400
1401 auto moduleVelocities = parameters.kinematics->ToSwerveModuleVelocities(robotVelocity, CenterOfRotation);
1402 if (DesaturateWheelVelocities && parameters.kMaxSpeed > 0_mps) {
1403 moduleVelocities = impl::SwerveDriveKinematics::DesaturateWheelVelocities(moduleVelocities, parameters.kMaxSpeed);
1404 }
1405
1406 auto moduleRequest = impl::SwerveModuleImpl::ModuleRequest{}
1409 .WithUpdatePeriod(parameters.updatePeriod);
1410
1411 for (size_t i = 0; i < modulesToApply.size(); ++i) {
1412 if (i < WheelForceFeedforwardsX.size() && i < WheelForceFeedforwardsY.size()) {
1413 auto wheelForceFeedforwardX = WheelForceFeedforwardsX[i];
1414 auto wheelForceFeedforwardY = WheelForceFeedforwardsY[i];
1415
1416 Translation2d tmp{wheelForceFeedforwardX * 1_m/1_N, wheelForceFeedforwardY * 1_m/1_N};
1418 /* If we're operator perspective, modify the X/Y forces by the angle */
1419 tmp = tmp.RotateBy(parameters.operatorForwardDirection);
1420 }
1421 /* Convert to robot-centric forces */
1422 tmp = tmp.RotateBy(-parameters.currentPose.Rotation());
1423
1424 wheelForceFeedforwardX = tmp.X() * 1_N/1_m;
1425 wheelForceFeedforwardY = tmp.Y() * 1_N/1_m;
1426
1427 moduleRequest.WithWheelForceFeedforwardX(wheelForceFeedforwardX)
1428 .WithWheelForceFeedforwardY(wheelForceFeedforwardY);
1429 }
1430
1431 modulesToApply[i]->Apply(moduleRequest.WithVelocity(moduleVelocities[i]));
1432 }
1433
1435 }
1436
1437 /**
1438 * \brief Modifies the Velocity parameter and returns itself.
1439 *
1440 * The field-centric chassis velocity to apply to the drivetrain.
1441 *
1442 * \param newVelocity Parameter to modify
1443 * \returns this object
1444 */
1445 ApplyFieldVelocity &WithVelocity(ChassisVelocities newVelocity) &
1446 {
1447 this->Velocity = std::move(newVelocity);
1448 return *this;
1449 }
1450 /**
1451 * \brief Modifies the Velocity parameter and returns itself.
1452 *
1453 * The field-centric chassis velocity to apply to the drivetrain.
1454 *
1455 * \param newVelocity Parameter to modify
1456 * \returns this object
1457 */
1458 ApplyFieldVelocity &&WithVelocity(ChassisVelocities newVelocity) &&
1459 {
1460 this->Velocity = std::move(newVelocity);
1461 return std::move(*this);
1462 }
1463
1464 /**
1465 * \brief Modifies the WheelForceFeedforwardsX parameter and returns itself.
1466 *
1467 * Field-centric wheel force feedforwards to apply in the
1468 * X direction. X is defined as forward according to WPILib
1469 * convention, so this determines the forward forces to apply.
1470 *
1471 * These forces should include friction applied to the ground.
1472 *
1473 * The order of the forces should match the order of the modules
1474 * returned from SwerveDrivetrain.
1475 *
1476 * \param newWheelForceFeedforwardsX Parameter to modify
1477 * \returns this object
1478 */
1479 ApplyFieldVelocity &WithWheelForceFeedforwardsX(std::vector<wpi::units::newton_t> newWheelForceFeedforwardsX) &
1480 {
1481 this->WheelForceFeedforwardsX = std::move(newWheelForceFeedforwardsX);
1482 return *this;
1483 }
1484 /**
1485 * \brief Modifies the WheelForceFeedforwardsX parameter and returns itself.
1486 *
1487 * Field-centric wheel force feedforwards to apply in the
1488 * X direction. X is defined as forward according to WPILib
1489 * convention, so this determines the forward forces to apply.
1490 *
1491 * These forces should include friction applied to the ground.
1492 *
1493 * The order of the forces should match the order of the modules
1494 * returned from SwerveDrivetrain.
1495 *
1496 * \param newWheelForceFeedforwardsX Parameter to modify
1497 * \returns this object
1498 */
1499 ApplyFieldVelocity &&WithWheelForceFeedforwardsX(std::vector<wpi::units::newton_t> newWheelForceFeedforwardsX) &&
1500 {
1501 this->WheelForceFeedforwardsX = std::move(newWheelForceFeedforwardsX);
1502 return std::move(*this);
1503 }
1504
1505 /**
1506 * \brief Modifies the WheelForceFeedforwardsY parameter and returns itself.
1507 *
1508 * Field-centric wheel force feedforwards to apply in the
1509 * Y direction. Y is defined as to the left according to WPILib
1510 * convention, so this determines the forces to apply to the left.
1511 *
1512 * These forces should include friction applied to the ground.
1513 *
1514 * The order of the forces should match the order of the modules
1515 * returned from SwerveDrivetrain.
1516 *
1517 * \param newWheelForceFeedforwardsY Parameter to modify
1518 * \returns this object
1519 */
1520 ApplyFieldVelocity &WithWheelForceFeedforwardsY(std::vector<wpi::units::newton_t> newWheelForceFeedforwardsY) &
1521 {
1522 this->WheelForceFeedforwardsY = std::move(newWheelForceFeedforwardsY);
1523 return *this;
1524 }
1525 /**
1526 * \brief Modifies the WheelForceFeedforwardsY parameter and returns itself.
1527 *
1528 * Field-centric wheel force feedforwards to apply in the
1529 * Y direction. Y is defined as to the left according to WPILib
1530 * convention, so this determines the forces to apply to the left.
1531 *
1532 * These forces should include friction applied to the ground.
1533 *
1534 * The order of the forces should match the order of the modules
1535 * returned from SwerveDrivetrain.
1536 *
1537 * \param newWheelForceFeedforwardsY Parameter to modify
1538 * \returns this object
1539 */
1540 ApplyFieldVelocity &&WithWheelForceFeedforwardsY(std::vector<wpi::units::newton_t> newWheelForceFeedforwardsY) &&
1541 {
1542 this->WheelForceFeedforwardsY = std::move(newWheelForceFeedforwardsY);
1543 return std::move(*this);
1544 }
1545
1546 /**
1547 * \brief Modifies the CenterOfRotation parameter and returns itself.
1548 *
1549 * The center of rotation the robot should rotate around. This is (0,0) by
1550 * default, which will rotate around the center of the robot.
1551 *
1552 * \param newCenterOfRotation Parameter to modify
1553 * \return this object
1554 */
1555 ApplyFieldVelocity &WithCenterOfRotation(Translation2d newCenterOfRotation) &
1556 {
1557 this->CenterOfRotation = std::move(newCenterOfRotation);
1558 return *this;
1559 }
1560 /**
1561 * \brief Modifies the CenterOfRotation parameter and returns itself.
1562 *
1563 * The center of rotation the robot should rotate around. This is (0,0) by
1564 * default, which will rotate around the center of the robot.
1565 *
1566 * \param newCenterOfRotation Parameter to modify
1567 * \return this object
1568 */
1569 ApplyFieldVelocity &&WithCenterOfRotation(Translation2d newCenterOfRotation) &&
1570 {
1571 this->CenterOfRotation = std::move(newCenterOfRotation);
1572 return std::move(*this);
1573 }
1574
1575 /**
1576 * \brief Modifies the DriveRequestType parameter and returns itself.
1577 *
1578 * The type of control request to use for the drive motor.
1579 *
1580 * \param newDriveRequestType Parameter to modify
1581 * \returns this object
1582 */
1584 {
1585 this->DriveRequestType = std::move(newDriveRequestType);
1586 return *this;
1587 }
1588 /**
1589 * \brief Modifies the DriveRequestType parameter and returns itself.
1590 *
1591 * The type of control request to use for the drive motor.
1592 *
1593 * \param newDriveRequestType Parameter to modify
1594 * \returns this object
1595 */
1597 {
1598 this->DriveRequestType = std::move(newDriveRequestType);
1599 return std::move(*this);
1600 }
1601
1602 /**
1603 * \brief Modifies the SteerRequestType parameter and returns itself.
1604 *
1605 * The type of control request to use for the steer motor.
1606 *
1607 * \param newSteerRequestType Parameter to modify
1608 * \returns this object
1609 */
1611 {
1612 this->SteerRequestType = std::move(newSteerRequestType);
1613 return *this;
1614 }
1615 /**
1616 * \brief Modifies the SteerRequestType parameter and returns itself.
1617 *
1618 * The type of control request to use for the steer motor.
1619 *
1620 * \param newSteerRequestType Parameter to modify
1621 * \returns this object
1622 */
1624 {
1625 this->SteerRequestType = std::move(newSteerRequestType);
1626 return std::move(*this);
1627 }
1628
1629 /**
1630 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
1631 *
1632 * Whether to desaturate wheel velocities before applying. For more information, see
1633 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
1634 *
1635 * \param newDesaturateWheelVelocities Parameter to modify
1636 * \returns this object
1637 */
1638 ApplyFieldVelocity &WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &
1639 {
1640 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
1641 return *this;
1642 }
1643 /**
1644 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
1645 *
1646 * Whether to desaturate wheel velocities before applying. For more information, see
1647 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
1648 *
1649 * \param newDesaturateWheelVelocities Parameter to modify
1650 * \returns this object
1651 */
1652 ApplyFieldVelocity &&WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &&
1653 {
1654 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
1655 return std::move(*this);
1656 }
1657
1658 /**
1659 * \brief Modifies the ForwardPerspective parameter and returns itself.
1660 *
1661 * The perspective to use when determining which direction is forward.
1662 *
1663 * \param newForwardPerspective Parameter to modify
1664 * \returns this object
1665 */
1667 {
1668 this->ForwardPerspective = std::move(newForwardPerspective);
1669 return *this;
1670 }
1671 /**
1672 * \brief Modifies the ForwardPerspective parameter and returns itself.
1673 *
1674 * The perspective to use when determining which direction is forward.
1675 *
1676 * \param newForwardPerspective Parameter to modify
1677 * \returns this object
1678 */
1680 {
1681 this->ForwardPerspective = std::move(newForwardPerspective);
1682 return std::move(*this);
1683 }
1684};
1685
1686/**
1687 * \brief Drives the swerve drivetrain in a field-centric manner, maintaining a
1688 * specified heading angle to ensure the robot is facing the desired direction
1689 *
1690 * When users use this request, they specify the direction the robot should
1691 * travel oriented against the field, and the direction the robot should be facing.
1692 *
1693 * An example scenario is that the robot is oriented to the east, the VelocityX
1694 * is +5 m/s, VelocityY is 0 m/s, and TargetDirection is 180 degrees.
1695 * In this scenario, the robot would drive northward at 5 m/s and turn clockwise
1696 * to a target of 180 degrees.
1697 *
1698 * This control request is especially useful for autonomous control, where the
1699 * robot should be facing a changing direction throughout the motion.
1700 */
1702public:
1703 /**
1704 * \brief The velocity in the X direction. X is defined as forward according
1705 * to WPILib convention, so this determines how fast to travel forward.
1706 */
1707 wpi::units::meters_per_second_t VelocityX = 0_mps;
1708 /**
1709 * \brief The velocity in the Y direction. Y is defined as to the left
1710 * according to WPILib convention, so this determines how fast to travel to
1711 * the left.
1712 */
1713 wpi::units::meters_per_second_t VelocityY = 0_mps;
1714 /**
1715 * \brief The desired direction to face.
1716 * 0 Degrees is defined as in the direction of the X axis.
1717 * As a result, a TargetDirection of 90 degrees will point along
1718 * the Y axis, or to the left.
1719 */
1720 Rotation2d TargetDirection{};
1721 /**
1722 * \brief The rotational rate feedforward to add to the output of the heading
1723 * controller, in radians per second. When using a motion profile for the
1724 * target direction, this can be set to the current velocity reference of
1725 * the profile.
1726 */
1727 wpi::units::radians_per_second_t TargetRateFeedforward = 0_rad_per_s;
1728
1729 /**
1730 * \brief The allowable deadband of the request.
1731 */
1732 wpi::units::meters_per_second_t Deadband = 0_mps;
1733 /**
1734 * \brief The rotational deadband of the request.
1735 */
1736 wpi::units::radians_per_second_t RotationalDeadband = 0_rad_per_s;
1737 /**
1738 * \brief The maximum absolute rotational rate to allow.
1739 * Setting this to 0 results in no cap to rotational rate.
1740 */
1741 wpi::units::radians_per_second_t MaxAbsRotationalRate = 0_rad_per_s;
1742 /**
1743 * \brief The center of rotation the robot should rotate around. This is
1744 * (0,0) by default, which will rotate around the center of the robot.
1745 */
1746 Translation2d CenterOfRotation{};
1747
1748 /**
1749 * \brief The type of control request to use for the drive motor.
1750 */
1752 /**
1753 * \brief The type of control request to use for the steer motor.
1754 */
1756 /**
1757 * \brief Whether to desaturate wheel velocities before applying.
1758 * For more information, see the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
1759 */
1761
1762 /**
1763 * \brief The perspective to use when determining which direction is forward.
1764 */
1766 /**
1767 * \brief The perspective to use when determining which direction is forward
1768 * for the #TargetDirection. This allows for the heading control to use a different
1769 * perspective from the translation control.
1770 */
1772
1773 /**
1774 * \brief The PID controller used to maintain the desired heading.
1775 * Users can specify the PID gains to change how aggressively to maintain
1776 * heading.
1777 *
1778 * This PID controller operates on heading radians and outputs a target
1779 * rotational rate in radians per second. Note that continuous input should
1780 * be enabled on the range [-pi, pi].
1781 */
1783
1785 {
1786 HeadingController.EnableContinuousInput(-wpi::units::constants::detail::PI_VAL, wpi::units::constants::detail::PI_VAL);
1787 }
1788
1789 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
1790 {
1791 Rotation2d angleToFace = TargetDirection;
1792 if (
1795 ) {
1796 /* If we're operator perspective, rotate the direction we want to face by the angle */
1797 angleToFace = angleToFace.RotateBy(parameters.operatorForwardDirection);
1798 }
1799
1800 wpi::units::radians_per_second_t toApplyOmega = TargetRateFeedforward +
1801 wpi::units::radians_per_second_t{HeadingController.Calculate(
1802 parameters.currentPose.Rotation().Radians().value(),
1803 angleToFace.Radians().value(),
1804 parameters.timestamp
1805 )};
1806 if (MaxAbsRotationalRate > 0_rad_per_s) {
1807 if (toApplyOmega > MaxAbsRotationalRate) {
1808 toApplyOmega = MaxAbsRotationalRate;
1809 } else if (toApplyOmega < -MaxAbsRotationalRate) {
1810 toApplyOmega = -MaxAbsRotationalRate;
1811 }
1812 }
1813
1814 return FieldCentric{}
1817 .WithRotationalRate(toApplyOmega)
1825 .Apply(parameters, modulesToApply);
1826 }
1827
1828 /**
1829 * \brief Modifies the PID gains of the HeadingController parameter and returns itself.
1830 *
1831 * Sets the proportional, integral, and differential coefficients used to maintain
1832 * the desired heading. Users can specify the PID gains to change how aggressively to
1833 * maintain heading.
1834 *
1835 * This PID controller operates on heading radians and outputs a target
1836 * rotational rate in radians per second.
1837 *
1838 * \param kP The proportional coefficient; must be >= 0
1839 * \param kI The integral coefficient; must be >= 0
1840 * \param kD The differential coefficient; must be >= 0
1841 * \returns this object
1842 */
1843 FieldCentricFacingAngle &WithHeadingPID(double kP, double kI, double kD)
1844 {
1845 this->HeadingController.SetPID(kP, kI, kD);
1846 return *this;
1847 }
1848
1849 /**
1850 * \brief Modifies the VelocityX parameter and returns itself.
1851 *
1852 * The velocity in the X direction. X is defined as forward according to
1853 * WPILib convention, so this determines how fast to travel forward.
1854 *
1855 * \param newVelocityX Parameter to modify
1856 * \returns this object
1857 */
1858 FieldCentricFacingAngle &WithVelocityX(wpi::units::meters_per_second_t newVelocityX)
1859 {
1860 this->VelocityX = std::move(newVelocityX);
1861 return *this;
1862 }
1863
1864 /**
1865 * \brief Modifies the VelocityY parameter and returns itself.
1866 *
1867 * The velocity in the Y direction. Y is defined as to the left according
1868 * to WPILib convention, so this determines how fast to travel to the
1869 * left.
1870 *
1871 * \param newVelocityY Parameter to modify
1872 * \returns this object
1873 */
1874 FieldCentricFacingAngle &WithVelocityY(wpi::units::meters_per_second_t newVelocityY)
1875 {
1876 this->VelocityY = std::move(newVelocityY);
1877 return *this;
1878 }
1879
1880 /**
1881 * \brief Modifies the VelocityY parameter and returns itself.
1882 *
1883 * The desired direction to face. 0 Degrees is defined as in the direction of
1884 * the X axis. As a result, a TargetDirection of 90 degrees will point along
1885 * the Y axis, or to the left.
1886 *
1887 * \param newTargetDirection Parameter to modify
1888 * \returns this object
1889 */
1890 FieldCentricFacingAngle &WithTargetDirection(Rotation2d newTargetDirection)
1891 {
1892 this->TargetDirection = std::move(newTargetDirection);
1893 return *this;
1894 }
1895
1896 /**
1897 * \brief Modifies the VelocityY parameter and returns itself.
1898 *
1899 * The rotational rate feedforward to add to the output of the heading
1900 * controller, in radians per second. When using a motion profile for the
1901 * target direction, this can be set to the current velocity reference of
1902 * the profile.
1903 *
1904 * \param newTargetRateFeedforward Parameter to modify
1905 * \returns this object
1906 */
1907 FieldCentricFacingAngle &WithTargetRateFeedforward(wpi::units::radians_per_second_t newTargetRateFeedforward)
1908 {
1909 this->TargetRateFeedforward = std::move(newTargetRateFeedforward);
1910 return *this;
1911 }
1912
1913 /**
1914 * \brief Modifies the Deadband parameter and returns itself.
1915 *
1916 * The allowable deadband of the request.
1917 *
1918 * \param newDeadband Parameter to modify
1919 * \returns this object
1920 */
1921 FieldCentricFacingAngle &WithDeadband(wpi::units::meters_per_second_t newDeadband)
1922 {
1923 this->Deadband = std::move(newDeadband);
1924 return *this;
1925 }
1926
1927 /**
1928 * \brief Modifies the RotationalDeadband parameter and returns itself.
1929 *
1930 * The rotational deadband of the request.
1931 *
1932 * \param newRotationalDeadband Parameter to modify
1933 * \returns this object
1934 */
1935 FieldCentricFacingAngle &WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband)
1936 {
1937 this->RotationalDeadband = std::move(newRotationalDeadband);
1938 return *this;
1939 }
1940
1941 /**
1942 * \brief Modifies the MaxAbsRotationalRate parameter and returns itself.
1943 *
1944 * The maximum absolute rotational rate to allow.
1945 * Setting this to 0 results in no cap to rotational rate.
1946 *
1947 * \param newMaxAbsRotationalRate Parameter to modify
1948 * \returns this object
1949 */
1950 FieldCentricFacingAngle &WithMaxAbsRotationalRate(wpi::units::radians_per_second_t newMaxAbsRotationalRate)
1951 {
1952 this->MaxAbsRotationalRate = std::move(newMaxAbsRotationalRate);
1953 return *this;
1954 }
1955
1956 /**
1957 * \brief Modifies the CenterOfRotation parameter and returns itself.
1958 *
1959 * The center of rotation the robot should rotate around. This is (0,0) by
1960 * default, which will rotate around the center of the robot.
1961 *
1962 * \param newCenterOfRotation Parameter to modify
1963 * \returns this object
1964 */
1965 FieldCentricFacingAngle &WithCenterOfRotation(Translation2d newCenterOfRotation)
1966 {
1967 this->CenterOfRotation = std::move(newCenterOfRotation);
1968 return *this;
1969 }
1970
1971 /**
1972 * \brief Modifies the DriveRequestType parameter and returns itself.
1973 *
1974 * The type of control request to use for the drive motor.
1975 *
1976 * \param newDriveRequestType Parameter to modify
1977 * \returns this object
1978 */
1980 {
1981 this->DriveRequestType = std::move(newDriveRequestType);
1982 return *this;
1983 }
1984
1985 /**
1986 * \brief Modifies the SteerRequestType parameter and returns itself.
1987 *
1988 * The type of control request to use for the steer motor.
1989 *
1990 * \param newSteerRequestType Parameter to modify
1991 * \returns this object
1992 */
1994 {
1995 this->SteerRequestType = std::move(newSteerRequestType);
1996 return *this;
1997 }
1998
1999 /**
2000 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
2001 *
2002 * Whether to desaturate wheel velocities before applying. For more information, see
2003 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
2004 *
2005 * \param newDesaturateWheelVelocities Parameter to modify
2006 * \returns this object
2007 */
2008 FieldCentricFacingAngle &WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities)
2009 {
2010 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
2011 return *this;
2012 }
2013
2014 /**
2015 * \brief Modifies the ForwardPerspective parameter and returns itself.
2016 *
2017 * The perspective to use when determining which direction is forward.
2018 *
2019 * \param newForwardPerspective Parameter to modify
2020 * \returns this object
2021 */
2023 {
2024 this->ForwardPerspective = std::move(newForwardPerspective);
2025 return *this;
2026 }
2027
2028 /**
2029 * \brief Modifies the TargetDirectionPerspective parameter and returns itself.
2030 *
2031 * The perspective to use when determining which direction is forward for the
2032 * #TargetDirection. This allows for the rotation control to use a different
2033 * perspective from the translation control.
2034 *
2035 * \param newTargetDirectionPerspective Parameter to modify
2036 * \returns this object
2037 */
2039 {
2040 this->TargetDirectionPerspective = std::move(newTargetDirectionPerspective);
2041 return *this;
2042 }
2043};
2044
2045/**
2046 * \brief Drives the swerve drivetrain in a robot-centric manner, maintaining a
2047 * specified heading angle to ensure the robot is facing the desired direction
2048 *
2049 * When users use this request, they specify the direction the robot should
2050 * travel oriented against the robot itself, and the direction the robot should
2051 * be facing relative to the field.
2052 *
2053 * An example scenario is that the robot is oriented to the east, the VelocityX
2054 * is +5 m/s, VelocityY is 0 m/s, and TargetDirection is 180 degrees.
2055 * In this scenario, the robot would drive forward at 5 m/s and turn clockwise
2056 * to a target of 180 degrees.
2057 *
2058 * This control request is especially useful for vision control, where the
2059 * robot should be facing a vision target throughout the motion.
2060 */
2062public:
2063 /**
2064 * \brief The velocity in the X direction. X is defined as forward according
2065 * to WPILib convention, so this determines how fast to travel forward.
2066 */
2067 wpi::units::meters_per_second_t VelocityX = 0_mps;
2068 /**
2069 * \brief The velocity in the Y direction. Y is defined as to the left
2070 * according to WPILib convention, so this determines how fast to travel to
2071 * the left.
2072 */
2073 wpi::units::meters_per_second_t VelocityY = 0_mps;
2074 /**
2075 * \brief The desired direction to face.
2076 * 0 Degrees is defined as in the direction of the X axis.
2077 * As a result, a TargetDirection of 90 degrees will point along
2078 * the Y axis, or to the left.
2079 */
2080 Rotation2d TargetDirection{};
2081 /**
2082 * \brief The rotational rate feedforward to add to the output of the heading
2083 * controller, in radians per second. When using a motion profile for the
2084 * target direction, this can be set to the current velocity reference of
2085 * the profile.
2086 */
2087 wpi::units::radians_per_second_t TargetRateFeedforward = 0_rad_per_s;
2088
2089 /**
2090 * \brief The allowable deadband of the request.
2091 */
2092 wpi::units::meters_per_second_t Deadband = 0_mps;
2093 /**
2094 * \brief The rotational deadband of the request.
2095 */
2096 wpi::units::radians_per_second_t RotationalDeadband = 0_rad_per_s;
2097 /**
2098 * \brief The maximum absolute rotational rate to allow.
2099 * Setting this to 0 results in no cap to rotational rate.
2100 */
2101 wpi::units::radians_per_second_t MaxAbsRotationalRate = 0_rad_per_s;
2102 /**
2103 * \brief The center of rotation the robot should rotate around. This is
2104 * (0,0) by default, which will rotate around the center of the robot.
2105 */
2106 Translation2d CenterOfRotation{};
2107
2108 /**
2109 * \brief The type of control request to use for the drive motor.
2110 */
2112 /**
2113 * \brief The type of control request to use for the steer motor.
2114 */
2116 /**
2117 * \brief Whether to desaturate wheel velocities before applying.
2118 * For more information, see the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
2119 */
2121
2122 /**
2123 * \brief The perspective to use when determining which direction is forward
2124 * for the target heading.
2125 */
2127
2128 /**
2129 * \brief The PID controller used to maintain the desired heading.
2130 * Users can specify the PID gains to change how aggressively to maintain
2131 * heading.
2132 *
2133 * This PID controller operates on heading radians and outputs a target
2134 * rotational rate in radians per second. Note that continuous input should
2135 * be enabled on the range [-pi, pi].
2136 */
2138
2140 {
2141 HeadingController.EnableContinuousInput(-wpi::units::constants::detail::PI_VAL, wpi::units::constants::detail::PI_VAL);
2142 }
2143
2144 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
2145 {
2146 Rotation2d angleToFace = TargetDirection;
2148 /* If we're operator perspective, rotate the direction we want to face by the angle */
2149 angleToFace = angleToFace.RotateBy(parameters.operatorForwardDirection);
2150 }
2151
2152 wpi::units::radians_per_second_t toApplyOmega = TargetRateFeedforward +
2153 wpi::units::radians_per_second_t{HeadingController.Calculate(
2154 parameters.currentPose.Rotation().Radians().value(),
2155 angleToFace.Radians().value(),
2156 parameters.timestamp
2157 )};
2158 if (MaxAbsRotationalRate > 0_rad_per_s) {
2159 if (toApplyOmega > MaxAbsRotationalRate) {
2160 toApplyOmega = MaxAbsRotationalRate;
2161 } else if (toApplyOmega < -MaxAbsRotationalRate) {
2162 toApplyOmega = -MaxAbsRotationalRate;
2163 }
2164 }
2165
2166 return RobotCentric{}
2169 .WithRotationalRate(toApplyOmega)
2176 .Apply(parameters, modulesToApply);
2177 }
2178
2179 /**
2180 * \brief Modifies the PID gains of the HeadingController parameter and returns itself.
2181 *
2182 * Sets the proportional, integral, and differential coefficients used to maintain
2183 * the desired heading. Users can specify the PID gains to change how aggressively to
2184 * maintain heading.
2185 *
2186 * This PID controller operates on heading radians and outputs a target
2187 * rotational rate in radians per second.
2188 *
2189 * \param kP The proportional coefficient; must be >= 0
2190 * \param kI The integral coefficient; must be >= 0
2191 * \param kD The differential coefficient; must be >= 0
2192 * \returns this object
2193 */
2194 RobotCentricFacingAngle &WithHeadingPID(double kP, double kI, double kD)
2195 {
2196 this->HeadingController.SetPID(kP, kI, kD);
2197 return *this;
2198 }
2199
2200 /**
2201 * \brief Modifies the VelocityX parameter and returns itself.
2202 *
2203 * The velocity in the X direction. X is defined as forward according to
2204 * WPILib convention, so this determines how fast to travel forward.
2205 *
2206 * \param newVelocityX Parameter to modify
2207 * \returns this object
2208 */
2209 RobotCentricFacingAngle &WithVelocityX(wpi::units::meters_per_second_t newVelocityX)
2210 {
2211 this->VelocityX = std::move(newVelocityX);
2212 return *this;
2213 }
2214
2215 /**
2216 * \brief Modifies the VelocityY parameter and returns itself.
2217 *
2218 * The velocity in the Y direction. Y is defined as to the left according
2219 * to WPILib convention, so this determines how fast to travel to the
2220 * left.
2221 *
2222 * \param newVelocityY Parameter to modify
2223 * \returns this object
2224 */
2225 RobotCentricFacingAngle &WithVelocityY(wpi::units::meters_per_second_t newVelocityY)
2226 {
2227 this->VelocityY = std::move(newVelocityY);
2228 return *this;
2229 }
2230
2231 /**
2232 * \brief Modifies the VelocityY parameter and returns itself.
2233 *
2234 * The desired direction to face. 0 Degrees is defined as in the direction of
2235 * the X axis. As a result, a TargetDirection of 90 degrees will point along
2236 * the Y axis, or to the left.
2237 *
2238 * \param newTargetDirection Parameter to modify
2239 * \returns this object
2240 */
2241 RobotCentricFacingAngle &WithTargetDirection(Rotation2d newTargetDirection)
2242 {
2243 this->TargetDirection = std::move(newTargetDirection);
2244 return *this;
2245 }
2246
2247 /**
2248 * \brief Modifies the VelocityY parameter and returns itself.
2249 *
2250 * The rotational rate feedforward to add to the output of the heading
2251 * controller, in radians per second. When using a motion profile for the
2252 * target direction, this can be set to the current velocity reference of
2253 * the profile.
2254 *
2255 * \param newTargetRateFeedforward Parameter to modify
2256 * \returns this object
2257 */
2258 RobotCentricFacingAngle &WithTargetRateFeedforward(wpi::units::radians_per_second_t newTargetRateFeedforward)
2259 {
2260 this->TargetRateFeedforward = std::move(newTargetRateFeedforward);
2261 return *this;
2262 }
2263
2264 /**
2265 * \brief Modifies the Deadband parameter and returns itself.
2266 *
2267 * The allowable deadband of the request.
2268 *
2269 * \param newDeadband Parameter to modify
2270 * \returns this object
2271 */
2272 RobotCentricFacingAngle &WithDeadband(wpi::units::meters_per_second_t newDeadband)
2273 {
2274 this->Deadband = std::move(newDeadband);
2275 return *this;
2276 }
2277
2278 /**
2279 * \brief Modifies the RotationalDeadband parameter and returns itself.
2280 *
2281 * The rotational deadband of the request.
2282 *
2283 * \param newRotationalDeadband Parameter to modify
2284 * \returns this object
2285 */
2286 RobotCentricFacingAngle &WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband)
2287 {
2288 this->RotationalDeadband = std::move(newRotationalDeadband);
2289 return *this;
2290 }
2291
2292 /**
2293 * \brief Modifies the MaxAbsRotationalRate parameter and returns itself.
2294 *
2295 * The maximum absolute rotational rate to allow.
2296 * Setting this to 0 results in no cap to rotational rate.
2297 *
2298 * \param newMaxAbsRotationalRate Parameter to modify
2299 * \returns this object
2300 */
2301 RobotCentricFacingAngle &WithMaxAbsRotationalRate(wpi::units::radians_per_second_t newMaxAbsRotationalRate)
2302 {
2303 this->MaxAbsRotationalRate = std::move(newMaxAbsRotationalRate);
2304 return *this;
2305 }
2306
2307 /**
2308 * \brief Modifies the CenterOfRotation parameter and returns itself.
2309 *
2310 * The center of rotation the robot should rotate around. This is (0,0) by
2311 * default, which will rotate around the center of the robot.
2312 *
2313 * \param newCenterOfRotation Parameter to modify
2314 * \returns this object
2315 */
2316 RobotCentricFacingAngle &WithCenterOfRotation(Translation2d newCenterOfRotation)
2317 {
2318 this->CenterOfRotation = std::move(newCenterOfRotation);
2319 return *this;
2320 }
2321
2322 /**
2323 * \brief Modifies the DriveRequestType parameter and returns itself.
2324 *
2325 * The type of control request to use for the drive motor.
2326 *
2327 * \param newDriveRequestType Parameter to modify
2328 * \returns this object
2329 */
2331 {
2332 this->DriveRequestType = std::move(newDriveRequestType);
2333 return *this;
2334 }
2335
2336 /**
2337 * \brief Modifies the SteerRequestType parameter and returns itself.
2338 *
2339 * The type of control request to use for the steer motor.
2340 *
2341 * \param newSteerRequestType Parameter to modify
2342 * \returns this object
2343 */
2345 {
2346 this->SteerRequestType = std::move(newSteerRequestType);
2347 return *this;
2348 }
2349
2350 /**
2351 * \brief Modifies the DesaturateWheelVelocities parameter and returns itself.
2352 *
2353 * Whether to desaturate wheel velocities before applying. For more information, see
2354 * the documentation of impl#SwerveDriveKinematics#DesaturateWheelVelocities.
2355 *
2356 * \param newDesaturateWheelVelocities Parameter to modify
2357 * \returns this object
2358 */
2359 RobotCentricFacingAngle &WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities)
2360 {
2361 this->DesaturateWheelVelocities = std::move(newDesaturateWheelVelocities);
2362 return *this;
2363 }
2364
2365 /**
2366 * \brief Modifies the ForwardPerspective parameter and returns itself.
2367 *
2368 * The perspective to use when determining which direction is forward
2369 * for the target heading.
2370 *
2371 * \param newForwardPerspective Parameter to modify
2372 * \returns this object
2373 */
2375 {
2376 this->ForwardPerspective = std::move(newForwardPerspective);
2377 return *this;
2378 }
2379};
2380
2381/**
2382 * \brief SysId-specific SwerveRequest to characterize the translational
2383 * characteristics of a swerve drivetrain.
2384 */
2386public:
2387 /**
2388 * \brief Voltage to apply to drive wheels.
2389 */
2390 wpi::units::volt_t VoltsToApply = 0_V;
2391
2392 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
2393 {
2394 for (size_t i = 0; i < modulesToApply.size(); ++i) {
2395 switch (modulesToApply[i]->GetSteerClosedLoopOutputType()) {
2397 modulesToApply[i]->Apply(
2400 );
2401 break;
2403 modulesToApply[i]->Apply(
2406 );
2407 break;
2408 }
2409 }
2411 }
2412
2413 /**
2414 * \brief Sets the voltage to apply to drive wheels.
2415 *
2416 * \param volts Voltage to apply
2417 * \returns this request
2418 */
2419 SysIdSwerveTranslation &WithVolts(wpi::units::volt_t volts) &
2420 {
2421 this->VoltsToApply = volts;
2422 return *this;
2423 }
2424 /**
2425 * \brief Sets the voltage to apply to drive wheels.
2426 *
2427 * \param volts Voltage to apply
2428 * \returns this request
2429 */
2430 SysIdSwerveTranslation &&WithVolts(wpi::units::volt_t volts) &&
2431 {
2432 this->VoltsToApply = volts;
2433 return std::move(*this);
2434 }
2435};
2436
2437/**
2438 * \brief SysId-specific SwerveRequest to characterize the rotational
2439 * characteristics of a swerve drivetrain. This is useful to
2440 * characterize the heading controller for FieldCentricFacingAngle.
2441 *
2442 * The RotationalRate of this swerve request should be logged.
2443 * When importing the log to SysId, set the "voltage" to
2444 * RotationalRate, "position" to the Pigeon 2 Yaw, and "velocity"
2445 * to the Pigeon 2 AngularVelocityZWorld. Note that the position
2446 * and velocity will both need to be scaled by pi/180.
2447 *
2448 * Alternatively, the MotorVoltage of one of the drive motors can
2449 * be loaded into the SysId "voltage" field, which can be useful
2450 * when determining the MOI of the robot.
2451 */
2453public:
2454 /**
2455 * \brief The angular rate to rotate at, in radians per second.
2456 */
2457 wpi::units::radians_per_second_t RotationalRate = 0_rad_per_s;
2458
2459 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
2460 {
2461 for (size_t i = 0; i < modulesToApply.size(); ++i) {
2462 auto const velocity = RotationalRate * (parameters.moduleLocations[i].Norm() / 1_rad);
2463 auto const driveVoltage = velocity / parameters.kMaxSpeed * 12_V;
2464
2465 auto const angle = parameters.moduleLocations[i].Angle() + Rotation2d{90_deg};
2466
2467 switch (modulesToApply[i]->GetSteerClosedLoopOutputType()) {
2469 modulesToApply[i]->Apply(
2470 controls::VoltageOut{driveVoltage},
2471 controls::PositionVoltage{angle.Radians()}
2472 );
2473 break;
2475 modulesToApply[i]->Apply(
2476 controls::VoltageOut{driveVoltage},
2477 controls::PositionTorqueCurrentFOC{angle.Radians()}
2478 );
2479 break;
2480 }
2481 }
2483 }
2484
2485 /**
2486 * \brief Update the angular rate to rotate at, in radians per second.
2487 *
2488 * \param rotationalRate Angular rate to rotate at
2489 * \returns this request
2490 */
2491 SysIdSwerveRotation &WithRotationalRate(wpi::units::radians_per_second_t rotationalRate) &
2492 {
2493 this->RotationalRate = rotationalRate;
2494 return *this;
2495 }
2496 /**
2497 * \brief Update the angular rate to rotate at, in radians per second.
2498 *
2499 * \param rotationalRate Angular rate to rotate at
2500 * \returns this request
2501 */
2502 SysIdSwerveRotation &&WithRotationalRate(wpi::units::radians_per_second_t rotationalRate) &&
2503 {
2504 this->RotationalRate = rotationalRate;
2505 return std::move(*this);
2506 }
2507};
2508
2509/**
2510 * \brief SysId-specific SwerveRequest to characterize the steer module
2511 * characteristics of a swerve drivetrain.
2512 */
2514public:
2515 /**
2516 * \brief Voltage to apply to drive wheels.
2517 */
2518 wpi::units::volt_t VoltsToApply = 0_V;
2519
2520 ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span<std::unique_ptr<impl::SwerveModuleImpl> const> modulesToApply) override
2521 {
2522 for (size_t i = 0; i < modulesToApply.size(); ++i) {
2523 modulesToApply[i]->Apply(controls::CoastOut{}, controls::VoltageOut{VoltsToApply});
2524 }
2526 }
2527
2528 /**
2529 * \brief Update the voltage to apply to the drive wheels.
2530 *
2531 * \param volts Voltage to apply
2532 * \returns this request
2533 */
2534 SysIdSwerveSteerGains &WithVolts(wpi::units::volt_t volts) &
2535 {
2536 this->VoltsToApply = volts;
2537 return *this;
2538 }
2539 /**
2540 * \brief Update the voltage to apply to the drive wheels.
2541 *
2542 * \param volts Voltage to apply
2543 * \returns this request
2544 */
2545 SysIdSwerveSteerGains &&WithVolts(wpi::units::volt_t volts) &&
2546 {
2547 this->VoltsToApply = volts;
2548 return std::move(*this);
2549 }
2550};
2551
2552}
2553}
2554}
2555}
Request coast neutral output of actuator.
Definition CoastOut.hpp:21
Requires Phoenix Pro; Request PID to target position with torque current feedforward.
Definition PositionTorqueCurrentFOC.hpp:27
Request PID to target position with voltage feedforward.
Definition PositionVoltage.hpp:26
Request a specified voltage.
Definition VoltageOut.hpp:24
Phoenix-centric PID controller taken from WPI's wpi::math::PIDController class.
Definition PhoenixPIDController.hpp:22
void SetPID(double Kp, double Ki, double Kd)
Sets the PID Controller gain parameters.
WheelVelocities ToSwerveModuleVelocities(ChassisVelocities const &chassisVelocities, Translation2d const &centerOfRotation=Translation2d{}) const
Performs inverse kinematics to return the module states from a desired chassis velocity.
static WheelVelocities DesaturateWheelVelocities(WheelVelocities const &moduleVelocities, wpi::units::meters_per_second_t attainableMaxVelocity)
Renormalizes the wheel velocities if any individual velocity is above the specified maximum.
Accepts a generic field-centric ChassisVelocities to apply to the drivetrain.
Definition SwerveRequest.hpp:1335
ChassisVelocities Velocity
The field-centric chassis velocity to apply to the drivetrain.
Definition SwerveRequest.hpp:1340
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:1386
ApplyFieldVelocity && WithWheelForceFeedforwardsY(std::vector< wpi::units::newton_t > newWheelForceFeedforwardsY) &&
Modifies the WheelForceFeedforwardsY parameter and returns itself.
Definition SwerveRequest.hpp:1540
ApplyFieldVelocity & WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1583
ApplyFieldVelocity & WithCenterOfRotation(Translation2d newCenterOfRotation) &
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:1555
bool DesaturateWheelVelocities
Whether to desaturate wheel velocities before applying.
Definition SwerveRequest.hpp:1379
ApplyFieldVelocity && WithVelocity(ChassisVelocities newVelocity) &&
Modifies the Velocity parameter and returns itself.
Definition SwerveRequest.hpp:1458
std::vector< wpi::units::newton_t > WheelForceFeedforwardsY
Field-centric wheel force feedforwards to apply in the Y direction.
Definition SwerveRequest.hpp:1362
ApplyFieldVelocity && WithCenterOfRotation(Translation2d newCenterOfRotation) &&
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:1569
impl::SteerRequestType SteerRequestType
The type of control request to use for the steer motor.
Definition SwerveRequest.hpp:1374
impl::DriveRequestType DriveRequestType
The type of control request to use for the drive motor.
Definition SwerveRequest.hpp:1370
Translation2d CenterOfRotation
The center of rotation to rotate around.
Definition SwerveRequest.hpp:1366
ApplyFieldVelocity & WithForwardPerspective(ForwardPerspectiveValue newForwardPerspective) &
Modifies the ForwardPerspective parameter and returns itself.
Definition SwerveRequest.hpp:1666
ApplyFieldVelocity & WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:1638
ApplyFieldVelocity & WithWheelForceFeedforwardsY(std::vector< wpi::units::newton_t > newWheelForceFeedforwardsY) &
Modifies the WheelForceFeedforwardsY parameter and returns itself.
Definition SwerveRequest.hpp:1520
ApplyFieldVelocity && WithForwardPerspective(ForwardPerspectiveValue newForwardPerspective) &&
Modifies the ForwardPerspective parameter and returns itself.
Definition SwerveRequest.hpp:1679
ApplyFieldVelocity && WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &&
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1596
ApplyFieldVelocity & WithWheelForceFeedforwardsX(std::vector< wpi::units::newton_t > newWheelForceFeedforwardsX) &
Modifies the WheelForceFeedforwardsX parameter and returns itself.
Definition SwerveRequest.hpp:1479
ApplyFieldVelocity && WithWheelForceFeedforwardsX(std::vector< wpi::units::newton_t > newWheelForceFeedforwardsX) &&
Modifies the WheelForceFeedforwardsX parameter and returns itself.
Definition SwerveRequest.hpp:1499
ApplyFieldVelocity & WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1610
ApplyFieldVelocity & WithVelocity(ChassisVelocities newVelocity) &
Modifies the Velocity parameter and returns itself.
Definition SwerveRequest.hpp:1445
ApplyFieldVelocity && WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &&
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:1652
std::vector< wpi::units::newton_t > WheelForceFeedforwardsX
Field-centric wheel force feedforwards to apply in the X direction.
Definition SwerveRequest.hpp:1351
ApplyFieldVelocity && WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &&
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1623
ForwardPerspectiveValue ForwardPerspective
The perspective to use when determining which direction is forward.
Definition SwerveRequest.hpp:1384
Accepts a generic robot-centric ChassisVelocities to apply to the drivetrain.
Definition SwerveRequest.hpp:1037
ApplyRobotVelocity & WithWheelForceFeedforwardsY(std::vector< wpi::units::newton_t > newWheelForceFeedforwardsY) &
Modifies the WheelForceFeedforwardsY parameter and returns itself.
Definition SwerveRequest.hpp:1191
ApplyRobotVelocity && WithCenterOfRotation(Translation2d newCenterOfRotation) &&
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:1240
ApplyRobotVelocity && WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &&
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1267
ApplyRobotVelocity & WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:1309
ApplyRobotVelocity && WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &&
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1294
impl::DriveRequestType DriveRequestType
The type of control request to use for the drive motor.
Definition SwerveRequest.hpp:1073
ApplyRobotVelocity && WithWheelForceFeedforwardsY(std::vector< wpi::units::newton_t > newWheelForceFeedforwardsY) &&
Modifies the WheelForceFeedforwardsY parameter and returns itself.
Definition SwerveRequest.hpp:1211
ApplyRobotVelocity && WithVelocity(ChassisVelocities newVelocity) &&
Modifies the Velocity parameter and returns itself.
Definition SwerveRequest.hpp:1129
std::vector< wpi::units::newton_t > WheelForceFeedforwardsY
Robot-centric wheel force feedforwards to apply in the Y direction.
Definition SwerveRequest.hpp:1065
Translation2d CenterOfRotation
The center of rotation to rotate around.
Definition SwerveRequest.hpp:1069
ApplyRobotVelocity && WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &&
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:1323
ApplyRobotVelocity & WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1281
std::vector< wpi::units::newton_t > WheelForceFeedforwardsX
Robot-centric wheel force feedforwards to apply in the X direction.
Definition SwerveRequest.hpp:1054
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:1084
ChassisVelocities Velocity
The robot-centric chassis velocity to apply to the drivetrain.
Definition SwerveRequest.hpp:1043
ApplyRobotVelocity & WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1254
bool DesaturateWheelVelocities
Whether to desaturate wheel velocities before applying.
Definition SwerveRequest.hpp:1082
ApplyRobotVelocity & WithWheelForceFeedforwardsX(std::vector< wpi::units::newton_t > newWheelForceFeedforwardsX) &
Modifies the WheelForceFeedforwardsX parameter and returns itself.
Definition SwerveRequest.hpp:1150
impl::SteerRequestType SteerRequestType
The type of control request to use for the steer motor.
Definition SwerveRequest.hpp:1077
ApplyRobotVelocity && WithWheelForceFeedforwardsX(std::vector< wpi::units::newton_t > newWheelForceFeedforwardsX) &&
Modifies the WheelForceFeedforwardsX parameter and returns itself.
Definition SwerveRequest.hpp:1170
ApplyRobotVelocity & WithVelocity(ChassisVelocities newVelocity) &
Modifies the Velocity parameter and returns itself.
Definition SwerveRequest.hpp:1115
ApplyRobotVelocity & WithCenterOfRotation(Translation2d newCenterOfRotation) &
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:1226
TargetDirectionPerspectiveValue TargetDirectionPerspective
The perspective to use when determining which direction is forward for the TargetDirection.
Definition SwerveRequest.hpp:1771
FieldCentricFacingAngle & WithTargetRateFeedforward(wpi::units::radians_per_second_t newTargetRateFeedforward)
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:1907
wpi::units::meters_per_second_t Deadband
The allowable deadband of the request.
Definition SwerveRequest.hpp:1732
FieldCentricFacingAngle & WithTargetDirectionPerspective(TargetDirectionPerspectiveValue newTargetDirectionPerspective)
Modifies the TargetDirectionPerspective parameter and returns itself.
Definition SwerveRequest.hpp:2038
FieldCentricFacingAngle & WithSteerRequestType(impl::SteerRequestType newSteerRequestType)
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1993
wpi::units::radians_per_second_t MaxAbsRotationalRate
The maximum absolute rotational rate to allow.
Definition SwerveRequest.hpp:1741
Rotation2d TargetDirection
The desired direction to face.
Definition SwerveRequest.hpp:1720
bool DesaturateWheelVelocities
Whether to desaturate wheel velocities before applying.
Definition SwerveRequest.hpp:1760
FieldCentricFacingAngle & WithForwardPerspective(ForwardPerspectiveValue newForwardPerspective)
Modifies the ForwardPerspective parameter and returns itself.
Definition SwerveRequest.hpp:2022
FieldCentricFacingAngle & WithTargetDirection(Rotation2d newTargetDirection)
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:1890
FieldCentricFacingAngle & WithDeadband(wpi::units::meters_per_second_t newDeadband)
Modifies the Deadband parameter and returns itself.
Definition SwerveRequest.hpp:1921
impl::SteerRequestType SteerRequestType
The type of control request to use for the steer motor.
Definition SwerveRequest.hpp:1755
FieldCentricFacingAngle & WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband)
Modifies the RotationalDeadband parameter and returns itself.
Definition SwerveRequest.hpp:1935
FieldCentricFacingAngle & WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities)
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:2008
wpi::units::meters_per_second_t VelocityY
The velocity in the Y direction.
Definition SwerveRequest.hpp:1713
PhoenixPIDController HeadingController
The PID controller used to maintain the desired heading.
Definition SwerveRequest.hpp:1782
impl::DriveRequestType DriveRequestType
The type of control request to use for the drive motor.
Definition SwerveRequest.hpp:1751
Translation2d CenterOfRotation
The center of rotation the robot should rotate around.
Definition SwerveRequest.hpp:1746
FieldCentricFacingAngle & WithMaxAbsRotationalRate(wpi::units::radians_per_second_t newMaxAbsRotationalRate)
Modifies the MaxAbsRotationalRate parameter and returns itself.
Definition SwerveRequest.hpp:1950
FieldCentricFacingAngle()
Definition SwerveRequest.hpp:1784
wpi::units::radians_per_second_t TargetRateFeedforward
The rotational rate feedforward to add to the output of the heading controller, in radians per second...
Definition SwerveRequest.hpp:1727
FieldCentricFacingAngle & WithVelocityX(wpi::units::meters_per_second_t newVelocityX)
Modifies the VelocityX parameter and returns itself.
Definition SwerveRequest.hpp:1858
wpi::units::radians_per_second_t RotationalDeadband
The rotational deadband of the request.
Definition SwerveRequest.hpp:1736
FieldCentricFacingAngle & WithVelocityY(wpi::units::meters_per_second_t newVelocityY)
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:1874
FieldCentricFacingAngle & WithDriveRequestType(impl::DriveRequestType newDriveRequestType)
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1979
wpi::units::meters_per_second_t VelocityX
The velocity in the X direction.
Definition SwerveRequest.hpp:1707
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:1789
FieldCentricFacingAngle & WithCenterOfRotation(Translation2d newCenterOfRotation)
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:1965
FieldCentricFacingAngle & WithHeadingPID(double kP, double kI, double kD)
Modifies the PID gains of the HeadingController parameter and returns itself.
Definition SwerveRequest.hpp:1843
ForwardPerspectiveValue ForwardPerspective
The perspective to use when determining which direction is forward.
Definition SwerveRequest.hpp:1765
Drives the swerve drivetrain in a field-centric manner.
Definition SwerveRequest.hpp:189
FieldCentric & WithRotationalRate(wpi::units::radians_per_second_t newRotationalRate) &
Modifies the RotationalRate parameter and returns itself.
Definition SwerveRequest.hpp:352
FieldCentric && WithCenterOfRotation(Translation2d newCenterOfRotation) &&
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:449
wpi::units::meters_per_second_t Deadband
The allowable deadband of the request.
Definition SwerveRequest.hpp:211
FieldCentric & WithCenterOfRotation(Translation2d newCenterOfRotation) &
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:435
wpi::units::meters_per_second_t VelocityY
The velocity in the Y direction.
Definition SwerveRequest.hpp:201
FieldCentric && WithDeadband(wpi::units::meters_per_second_t newDeadband) &&
Modifies the Deadband parameter and returns itself.
Definition SwerveRequest.hpp:393
FieldCentric && WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &&
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:503
bool DesaturateWheelVelocities
Whether to desaturate wheel velocities before applying.
Definition SwerveRequest.hpp:234
FieldCentric & WithForwardPerspective(ForwardPerspectiveValue newForwardPerspective) &
Modifies the ForwardPerspective parameter and returns itself.
Definition SwerveRequest.hpp:546
FieldCentric & WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:518
FieldCentric && WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband) &&
Modifies the RotationalDeadband parameter and returns itself.
Definition SwerveRequest.hpp:420
FieldCentric & WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:490
FieldCentric && WithVelocityY(wpi::units::meters_per_second_t newVelocityY) &&
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:337
FieldCentric && WithForwardPerspective(ForwardPerspectiveValue newForwardPerspective) &&
Modifies the ForwardPerspective parameter and returns itself.
Definition SwerveRequest.hpp:559
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:241
impl::DriveRequestType DriveRequestType
The type of control request to use for the drive motor.
Definition SwerveRequest.hpp:225
FieldCentric & WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband) &
Modifies the RotationalDeadband parameter and returns itself.
Definition SwerveRequest.hpp:407
FieldCentric && WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &&
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:532
Translation2d CenterOfRotation
The center of rotation the robot should rotate around.
Definition SwerveRequest.hpp:220
wpi::units::radians_per_second_t RotationalRate
The angular rate to rotate at.
Definition SwerveRequest.hpp:207
ForwardPerspectiveValue ForwardPerspective
The perspective to use when determining which direction is forward.
Definition SwerveRequest.hpp:239
impl::SteerRequestType SteerRequestType
The type of control request to use for the steer motor.
Definition SwerveRequest.hpp:229
FieldCentric && WithRotationalRate(wpi::units::radians_per_second_t newRotationalRate) &&
Modifies the RotationalRate parameter and returns itself.
Definition SwerveRequest.hpp:366
wpi::units::radians_per_second_t RotationalDeadband
The rotational deadband of the request.
Definition SwerveRequest.hpp:215
FieldCentric & WithDeadband(wpi::units::meters_per_second_t newDeadband) &
Modifies the Deadband parameter and returns itself.
Definition SwerveRequest.hpp:380
FieldCentric && WithVelocityX(wpi::units::meters_per_second_t newVelocityX) &&
Modifies the VelocityX parameter and returns itself.
Definition SwerveRequest.hpp:306
FieldCentric & WithVelocityX(wpi::units::meters_per_second_t newVelocityX) &
Modifies the VelocityX parameter and returns itself.
Definition SwerveRequest.hpp:292
FieldCentric & WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:463
wpi::units::meters_per_second_t VelocityX
The velocity in the X direction.
Definition SwerveRequest.hpp:195
FieldCentric & WithVelocityY(wpi::units::meters_per_second_t newVelocityY) &
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:322
FieldCentric && WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &&
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:476
Does nothing to the swerve module state.
Definition SwerveRequest.hpp:84
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &, std::span< std::unique_ptr< impl::SwerveModuleImpl > const >) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:86
Sets the swerve drive modules to point to a specified direction.
Definition SwerveRequest.hpp:916
impl::DriveRequestType DriveRequestType
The type of control request to use for the drive motor.
Definition SwerveRequest.hpp:926
PointWheelsAt && WithModuleDirection(Rotation2d newModuleDirection) &&
Modifies the ModuleDirection parameter and returns itself.
Definition SwerveRequest.hpp:968
PointWheelsAt && WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &&
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:995
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:932
impl::SteerRequestType SteerRequestType
The type of control request to use for the steer motor.
Definition SwerveRequest.hpp:930
PointWheelsAt && WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &&
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1022
PointWheelsAt & WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:982
PointWheelsAt & WithModuleDirection(Rotation2d newModuleDirection) &
Modifies the ModuleDirection parameter and returns itself.
Definition SwerveRequest.hpp:954
Rotation2d ModuleDirection
The direction to point the modules toward.
Definition SwerveRequest.hpp:922
PointWheelsAt & WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:1009
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:2144
wpi::units::radians_per_second_t RotationalDeadband
The rotational deadband of the request.
Definition SwerveRequest.hpp:2096
wpi::units::meters_per_second_t VelocityY
The velocity in the Y direction.
Definition SwerveRequest.hpp:2073
ForwardPerspectiveValue ForwardPerspective
The perspective to use when determining which direction is forward for the target heading.
Definition SwerveRequest.hpp:2126
Translation2d CenterOfRotation
The center of rotation the robot should rotate around.
Definition SwerveRequest.hpp:2106
RobotCentricFacingAngle & WithMaxAbsRotationalRate(wpi::units::radians_per_second_t newMaxAbsRotationalRate)
Modifies the MaxAbsRotationalRate parameter and returns itself.
Definition SwerveRequest.hpp:2301
impl::SteerRequestType SteerRequestType
The type of control request to use for the steer motor.
Definition SwerveRequest.hpp:2115
RobotCentricFacingAngle & WithTargetRateFeedforward(wpi::units::radians_per_second_t newTargetRateFeedforward)
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:2258
RobotCentricFacingAngle & WithVelocityY(wpi::units::meters_per_second_t newVelocityY)
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:2225
RobotCentricFacingAngle & WithSteerRequestType(impl::SteerRequestType newSteerRequestType)
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:2344
RobotCentricFacingAngle & WithForwardPerspective(ForwardPerspectiveValue newForwardPerspective)
Modifies the ForwardPerspective parameter and returns itself.
Definition SwerveRequest.hpp:2374
bool DesaturateWheelVelocities
Whether to desaturate wheel velocities before applying.
Definition SwerveRequest.hpp:2120
RobotCentricFacingAngle()
Definition SwerveRequest.hpp:2139
RobotCentricFacingAngle & WithHeadingPID(double kP, double kI, double kD)
Modifies the PID gains of the HeadingController parameter and returns itself.
Definition SwerveRequest.hpp:2194
PhoenixPIDController HeadingController
The PID controller used to maintain the desired heading.
Definition SwerveRequest.hpp:2137
RobotCentricFacingAngle & WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband)
Modifies the RotationalDeadband parameter and returns itself.
Definition SwerveRequest.hpp:2286
RobotCentricFacingAngle & WithCenterOfRotation(Translation2d newCenterOfRotation)
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:2316
RobotCentricFacingAngle & WithTargetDirection(Rotation2d newTargetDirection)
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:2241
wpi::units::radians_per_second_t MaxAbsRotationalRate
The maximum absolute rotational rate to allow.
Definition SwerveRequest.hpp:2101
Rotation2d TargetDirection
The desired direction to face.
Definition SwerveRequest.hpp:2080
RobotCentricFacingAngle & WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities)
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:2359
RobotCentricFacingAngle & WithDeadband(wpi::units::meters_per_second_t newDeadband)
Modifies the Deadband parameter and returns itself.
Definition SwerveRequest.hpp:2272
wpi::units::meters_per_second_t VelocityX
The velocity in the X direction.
Definition SwerveRequest.hpp:2067
wpi::units::meters_per_second_t Deadband
The allowable deadband of the request.
Definition SwerveRequest.hpp:2092
RobotCentricFacingAngle & WithVelocityX(wpi::units::meters_per_second_t newVelocityX)
Modifies the VelocityX parameter and returns itself.
Definition SwerveRequest.hpp:2209
impl::DriveRequestType DriveRequestType
The type of control request to use for the drive motor.
Definition SwerveRequest.hpp:2111
wpi::units::radians_per_second_t TargetRateFeedforward
The rotational rate feedforward to add to the output of the heading controller, in radians per second...
Definition SwerveRequest.hpp:2087
RobotCentricFacingAngle & WithDriveRequestType(impl::DriveRequestType newDriveRequestType)
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:2330
Drives the swerve drivetrain in a robot-centric manner.
Definition SwerveRequest.hpp:579
RobotCentric & WithCenterOfRotation(Translation2d newCenterOfRotation) &
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:809
RobotCentric & WithDeadband(wpi::units::meters_per_second_t newDeadband) &
Modifies the Deadband parameter and returns itself.
Definition SwerveRequest.hpp:754
RobotCentric && WithVelocityY(wpi::units::meters_per_second_t newVelocityY) &&
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:711
RobotCentric & WithVelocityX(wpi::units::meters_per_second_t newVelocityX) &
Modifies the VelocityX parameter and returns itself.
Definition SwerveRequest.hpp:666
RobotCentric & WithRotationalRate(wpi::units::radians_per_second_t newRotationalRate) &
Modifies the RotationalRate parameter and returns itself.
Definition SwerveRequest.hpp:726
impl::DriveRequestType DriveRequestType
The type of control request to use for the drive motor.
Definition SwerveRequest.hpp:616
RobotCentric && WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband) &&
Modifies the RotationalDeadband parameter and returns itself.
Definition SwerveRequest.hpp:794
wpi::units::radians_per_second_t RotationalDeadband
The rotational deadband of the request.
Definition SwerveRequest.hpp:606
RobotCentric & WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:892
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:627
wpi::units::meters_per_second_t VelocityX
The velocity in the X direction.
Definition SwerveRequest.hpp:585
RobotCentric && WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &&
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:877
RobotCentric && WithVelocityX(wpi::units::meters_per_second_t newVelocityX) &&
Modifies the VelocityX parameter and returns itself.
Definition SwerveRequest.hpp:680
Translation2d CenterOfRotation
The center of rotation the robot should rotate around.
Definition SwerveRequest.hpp:611
RobotCentric && WithCenterOfRotation(Translation2d newCenterOfRotation) &&
Modifies the CenterOfRotation parameter and returns itself.
Definition SwerveRequest.hpp:823
RobotCentric && WithDeadband(wpi::units::meters_per_second_t newDeadband) &&
Modifies the Deadband parameter and returns itself.
Definition SwerveRequest.hpp:767
RobotCentric && WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &&
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:850
bool DesaturateWheelVelocities
Whether to desaturate wheel velocities before applying.
Definition SwerveRequest.hpp:625
wpi::units::radians_per_second_t RotationalRate
The angular rate to rotate at.
Definition SwerveRequest.hpp:597
RobotCentric & WithVelocityY(wpi::units::meters_per_second_t newVelocityY) &
Modifies the VelocityY parameter and returns itself.
Definition SwerveRequest.hpp:696
wpi::units::meters_per_second_t Deadband
The allowable deadband of the request.
Definition SwerveRequest.hpp:602
impl::SteerRequestType SteerRequestType
The type of control request to use for the steer motor.
Definition SwerveRequest.hpp:620
RobotCentric & WithRotationalDeadband(wpi::units::radians_per_second_t newRotationalDeadband) &
Modifies the RotationalDeadband parameter and returns itself.
Definition SwerveRequest.hpp:781
RobotCentric & WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:837
RobotCentric & WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:864
RobotCentric && WithDesaturateWheelVelocities(bool newDesaturateWheelVelocities) &&
Modifies the DesaturateWheelVelocities parameter and returns itself.
Definition SwerveRequest.hpp:906
RobotCentric && WithRotationalRate(wpi::units::radians_per_second_t newRotationalRate) &&
Modifies the RotationalRate parameter and returns itself.
Definition SwerveRequest.hpp:740
wpi::units::meters_per_second_t VelocityY
The velocity in the Y direction.
Definition SwerveRequest.hpp:591
Sets the swerve drive module states to point inward on the robot in an "X" fashion,...
Definition SwerveRequest.hpp:97
SwerveDriveBrake & WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:129
impl::DriveRequestType DriveRequestType
The type of control request to use for the drive motor.
Definition SwerveRequest.hpp:102
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:108
impl::SteerRequestType SteerRequestType
The type of control request to use for the steer motor.
Definition SwerveRequest.hpp:106
SwerveDriveBrake && WithDriveRequestType(impl::DriveRequestType newDriveRequestType) &&
Modifies the DriveRequestType parameter and returns itself.
Definition SwerveRequest.hpp:142
SwerveDriveBrake && WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &&
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:169
SwerveDriveBrake & WithSteerRequestType(impl::SteerRequestType newSteerRequestType) &
Modifies the SteerRequestType parameter and returns itself.
Definition SwerveRequest.hpp:156
Container for all the Swerve Requests.
Definition SwerveRequest.hpp:63
impl::SwerveDrivetrainImpl::ControlParameters ControlParameters
Definition SwerveRequest.hpp:65
virtual ctre::phoenix::StatusCode Apply(ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply)=0
Applies this swerve request to the given modules.
SysId-specific SwerveRequest to characterize the rotational characteristics of a swerve drivetrain.
Definition SwerveRequest.hpp:2452
SysIdSwerveRotation & WithRotationalRate(wpi::units::radians_per_second_t rotationalRate) &
Update the angular rate to rotate at, in radians per second.
Definition SwerveRequest.hpp:2491
SysIdSwerveRotation && WithRotationalRate(wpi::units::radians_per_second_t rotationalRate) &&
Update the angular rate to rotate at, in radians per second.
Definition SwerveRequest.hpp:2502
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:2459
wpi::units::radians_per_second_t RotationalRate
The angular rate to rotate at, in radians per second.
Definition SwerveRequest.hpp:2457
SysId-specific SwerveRequest to characterize the steer module characteristics of a swerve drivetrain.
Definition SwerveRequest.hpp:2513
wpi::units::volt_t VoltsToApply
Voltage to apply to drive wheels.
Definition SwerveRequest.hpp:2518
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:2520
SysIdSwerveSteerGains & WithVolts(wpi::units::volt_t volts) &
Update the voltage to apply to the drive wheels.
Definition SwerveRequest.hpp:2534
SysIdSwerveSteerGains && WithVolts(wpi::units::volt_t volts) &&
Update the voltage to apply to the drive wheels.
Definition SwerveRequest.hpp:2545
SysId-specific SwerveRequest to characterize the translational characteristics of a swerve drivetrain...
Definition SwerveRequest.hpp:2385
SysIdSwerveTranslation && WithVolts(wpi::units::volt_t volts) &&
Sets the voltage to apply to drive wheels.
Definition SwerveRequest.hpp:2430
wpi::units::volt_t VoltsToApply
Voltage to apply to drive wheels.
Definition SwerveRequest.hpp:2390
ctre::phoenix::StatusCode Apply(SwerveRequest::ControlParameters const &parameters, std::span< std::unique_ptr< impl::SwerveModuleImpl > const > modulesToApply) override
Applies this swerve request to the given modules.
Definition SwerveRequest.hpp:2392
SysIdSwerveTranslation & WithVolts(wpi::units::volt_t volts) &
Sets the voltage to apply to drive wheels.
Definition SwerveRequest.hpp:2419
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
static constexpr int OK
No Error.
Definition StatusCodes.h:35
SteerRequestType
All possible control requests for the module steer motor.
Definition SwerveModuleImpl.hpp:25
@ Position
Control the drive motor using an unprofiled position request.
Definition SwerveModuleImpl.hpp:35
DriveRequestType
All possible control requests for the module drive motor.
Definition SwerveModuleImpl.hpp:41
@ OpenLoopVoltage
Control the drive motor using an open-loop voltage request.
Definition SwerveModuleImpl.hpp:45
Definition SwerveRequest.hpp:15
ForwardPerspectiveValue
In field-centric control, the direction of "forward" is sometimes different depending on perspective.
Definition SwerveRequest.hpp:21
@ BlueAlliance
"Forward" (positive X) is always from the perspective of the blue alliance (i.e.
Definition SwerveRequest.hpp:36
@ OperatorPerspective
"Forward" (positive X) is determined from the operator's perspective.
Definition SwerveRequest.hpp:29
TargetDirectionPerspectiveValue
In field-centric control, the direction of "forward" for the target direction sometimes differs from ...
Definition SwerveRequest.hpp:43
@ UseForwardPerspective
Match the ForwardPerspective parameter for heading control.
Definition SwerveRequest.hpp:47
Definition SwerveModule.hpp:28
@ TorqueCurrentFOC
Requires Pro.
Definition SwerveModuleConstants.hpp:25
@ Voltage
Definition SwerveModuleConstants.hpp:23
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14
Contains everything the control requests need to calculate the module state.
Definition SwerveDrivetrainImpl.hpp:142
wpi::units::second_t updatePeriod
The update period of control apply.
Definition SwerveDrivetrainImpl.hpp:159
wpi::units::meters_per_second_t kMaxSpeed
The max speed of the robot at 12 V output.
Definition SwerveDrivetrainImpl.hpp:148
impl::SwerveDriveKinematics * kinematics
The kinematics object used for control.
Definition SwerveDrivetrainImpl.hpp:144
Pose2d currentPose
The current pose of the robot.
Definition SwerveDrivetrainImpl.hpp:155
Rotation2d operatorForwardDirection
The forward direction from the operator perspective.
Definition SwerveDrivetrainImpl.hpp:151
Translation2d const * moduleLocations
The locations of the swerve modules.
Definition SwerveDrivetrainImpl.hpp:146
wpi::units::second_t timestamp
The timestamp of the current control apply, in the timebase of utils::GetCurrentTime().
Definition SwerveDrivetrainImpl.hpp:157
Contains everything the swerve module needs to apply a request.
Definition SwerveModuleImpl.hpp:66
ModuleRequest & WithSteerRequest(SteerRequestType newSteerRequest)
Modifies the SteerRequest parameter and returns itself.
Definition SwerveModuleImpl.hpp:190
ModuleRequest & WithDriveRequest(DriveRequestType newDriveRequest)
Modifies the DriveRequest parameter and returns itself.
Definition SwerveModuleImpl.hpp:177
ModuleRequest & WithUpdatePeriod(wpi::units::second_t newUpdatePeriod)
Modifies the UpdatePeriod parameter and returns itself.
Definition SwerveModuleImpl.hpp:205