WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
DifferentialDriveFeedforward.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <wpi/SymbolExports.h>
8
12#include "units/acceleration.h"
15#include "units/length.h"
16#include "units/time.h"
17#include "units/velocity.h"
18#include "units/voltage.h"
19
20namespace frc {
21/**
22 * A helper class which computes the feedforward outputs for a differential
23 * drive drivetrain.
24 */
27
28 public:
29 /**
30 * Creates a new DifferentialDriveFeedforward with the specified parameters.
31 *
32 * @param kVLinear The linear velocity gain in volts per (meters per second).
33 * @param kALinear The linear acceleration gain in volts per (meters per
34 * second squared).
35 * @param kVAngular The angular velocity gain in volts per (radians per
36 * second).
37 * @param kAAngular The angular acceleration gain in volts per (radians per
38 * second squared).
39 * @param trackwidth The distance between the differential drive's left and
40 * right wheels, in meters.
41 */
43 decltype(1_V / 1_mps) kVLinear, decltype(1_V / 1_mps_sq) kALinear,
44 decltype(1_V / 1_rad_per_s) kVAngular,
45 decltype(1_V / 1_rad_per_s_sq) kAAngular, units::meter_t trackwidth)
46 // See LinearSystemId::IdentifyDrivetrainSystem(decltype(1_V / 1_mps),
47 // decltype(1_V / 1_mps_sq), decltype(1_V / 1_rad_per_s), decltype(1_V /
48 // 1_rad_per_s_sq))
49 : DifferentialDriveFeedforward{kVLinear, kALinear,
50 kVAngular * 2.0 / trackwidth * 1_rad,
51 kAAngular * 2.0 / trackwidth * 1_rad} {}
52
53 /**
54 * Creates a new DifferentialDriveFeedforward with the specified parameters.
55 *
56 * @param kVLinear The linear velocity gain in volts per (meters per second).
57 * @param kALinear The linear acceleration gain in volts per (meters per
58 * second squared).
59 * @param kVAngular The angular velocity gain in volts per (meters per
60 * second).
61 * @param kAAngular The angular acceleration gain in volts per (meters per
62 * second squared).
63 */
64 constexpr DifferentialDriveFeedforward(decltype(1_V / 1_mps) kVLinear,
65 decltype(1_V / 1_mps_sq) kALinear,
66 decltype(1_V / 1_mps) kVAngular,
67 decltype(1_V / 1_mps_sq) kAAngular)
68 : m_plant{frc::LinearSystemId::IdentifyDrivetrainSystem(
69 kVLinear, kALinear, kVAngular, kAAngular)},
70 m_kVLinear{kVLinear},
71 m_kALinear{kALinear},
72 m_kVAngular{kVAngular},
73 m_kAAngular{kAAngular} {}
74
75 /**
76 * Calculates the differential drive feedforward inputs given velocity
77 * setpoints.
78 *
79 * @param currentLeftVelocity The current left velocity of the differential
80 * drive in meters/second.
81 * @param nextLeftVelocity The next left velocity of the differential drive in
82 * meters/second.
83 * @param currentRightVelocity The current right velocity of the differential
84 * drive in meters/second.
85 * @param nextRightVelocity The next right velocity of the differential drive
86 * in meters/second.
87 * @param dt Discretization timestep.
88 */
90 units::meters_per_second_t currentLeftVelocity,
91 units::meters_per_second_t nextLeftVelocity,
92 units::meters_per_second_t currentRightVelocity,
93 units::meters_per_second_t nextRightVelocity, units::second_t dt);
94
95 decltype(1_V / 1_mps) m_kVLinear;
96 decltype(1_V / 1_mps_sq) m_kALinear;
97 decltype(1_V / 1_mps) m_kVAngular;
98 decltype(1_V / 1_mps_sq) m_kAAngular;
99};
100} // namespace frc
101
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
A helper class which computes the feedforward outputs for a differential drive drivetrain.
Definition DifferentialDriveFeedforward.h:25
constexpr DifferentialDriveFeedforward(decltype(1_V/1_mps) kVLinear, decltype(1_V/1_mps_sq) kALinear, decltype(1_V/1_rad_per_s) kVAngular, decltype(1_V/1_rad_per_s_sq) kAAngular, units::meter_t trackwidth)
Creates a new DifferentialDriveFeedforward with the specified parameters.
Definition DifferentialDriveFeedforward.h:42
constexpr DifferentialDriveFeedforward(decltype(1_V/1_mps) kVLinear, decltype(1_V/1_mps_sq) kALinear, decltype(1_V/1_mps) kVAngular, decltype(1_V/1_mps_sq) kAAngular)
Creates a new DifferentialDriveFeedforward with the specified parameters.
Definition DifferentialDriveFeedforward.h:64
DifferentialDriveWheelVoltages Calculate(units::meters_per_second_t currentLeftVelocity, units::meters_per_second_t nextLeftVelocity, units::meters_per_second_t currentRightVelocity, units::meters_per_second_t nextRightVelocity, units::second_t dt)
Calculates the differential drive feedforward inputs given velocity setpoints.
A plant defined using state-space notation.
Definition LinearSystem.h:35
Linear system ID utility functions.
Definition LinearSystemId.h:27
Definition CAN.h:11
Motor voltages for a differential drive.
Definition DifferentialDriveWheelVoltages.h:14