WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
DifferentialDriveFeedforward.hpp
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
10#include "wpi/units/acceleration.hpp"
11#include "wpi/units/angular_acceleration.hpp"
12#include "wpi/units/angular_velocity.hpp"
13#include "wpi/units/length.hpp"
14#include "wpi/units/time.hpp"
15#include "wpi/units/velocity.hpp"
16#include "wpi/units/voltage.hpp"
18
19namespace wpi::math {
20/**
21 * A helper class which computes the feedforward outputs for a differential
22 * drive drivetrain.
23 */
26
27 public:
28 /**
29 * Creates a new DifferentialDriveFeedforward with the specified parameters.
30 *
31 * @param kVLinear The linear velocity gain in volts per (meters per second).
32 * @param kALinear The linear acceleration gain in volts per (meters per
33 * second squared).
34 * @param kVAngular The angular velocity gain in volts per (radians per
35 * second).
36 * @param kAAngular The angular acceleration gain in volts per (radians per
37 * second squared).
38 * @param trackwidth The distance between the differential drive's left and
39 * right wheels, in meters.
40 */
42 decltype(1_V / 1_mps) kVLinear, decltype(1_V / 1_mps_sq) kALinear,
43 decltype(1_V / 1_rad_per_s) kVAngular,
44 decltype(1_V / 1_rad_per_s_sq) kAAngular, wpi::units::meter_t trackwidth)
45 // See Models::DifferentialDriveFromSysId(decltype(1_V / 1_mps),
46 // decltype(1_V / 1_mps_sq), decltype(1_V / 1_rad_per_s), decltype(1_V /
47 // 1_rad_per_s_sq))
48 : DifferentialDriveFeedforward{kVLinear, kALinear,
49 kVAngular * 2.0 / trackwidth * 1_rad,
50 kAAngular * 2.0 / trackwidth * 1_rad} {}
51
52 /**
53 * Creates a new DifferentialDriveFeedforward with the specified parameters.
54 *
55 * @param kVLinear The linear velocity gain in volts per (meters per second).
56 * @param kALinear The linear acceleration gain in volts per (meters per
57 * second squared).
58 * @param kVAngular The angular velocity gain in volts per (meters per
59 * second).
60 * @param kAAngular The angular acceleration gain in volts per (meters per
61 * second squared).
62 */
63 constexpr DifferentialDriveFeedforward(decltype(1_V / 1_mps) kVLinear,
64 decltype(1_V / 1_mps_sq) kALinear,
65 decltype(1_V / 1_mps) kVAngular,
66 decltype(1_V / 1_mps_sq) kAAngular)
67 : m_plant{wpi::math::Models::DifferentialDriveFromSysId(
68 kVLinear, kALinear, kVAngular, kAAngular)},
69 m_kVLinear{kVLinear},
70 m_kALinear{kALinear},
71 m_kVAngular{kVAngular},
72 m_kAAngular{kAAngular} {}
73
74 /**
75 * Calculates the differential drive feedforward inputs given velocity
76 * setpoints.
77 *
78 * @param currentLeftVelocity The current left velocity of the differential
79 * drive in meters/second.
80 * @param nextLeftVelocity The next left velocity of the differential drive in
81 * meters/second.
82 * @param currentRightVelocity The current right velocity of the differential
83 * drive in meters/second.
84 * @param nextRightVelocity The next right velocity of the differential drive
85 * in meters/second.
86 * @param dt Discretization timestep.
87 */
89 wpi::units::meters_per_second_t currentLeftVelocity,
90 wpi::units::meters_per_second_t nextLeftVelocity,
91 wpi::units::meters_per_second_t currentRightVelocity,
92 wpi::units::meters_per_second_t nextRightVelocity,
93 wpi::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 wpi::math
101
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
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.hpp:63
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, wpi::units::meter_t trackwidth)
Creates a new DifferentialDriveFeedforward with the specified parameters.
Definition DifferentialDriveFeedforward.hpp:41
decltype(1_V/1_mps) m_kVAngular
Definition DifferentialDriveFeedforward.hpp:97
decltype(1_V/1_mps_sq) m_kALinear
Definition DifferentialDriveFeedforward.hpp:96
DifferentialDriveWheelVoltages Calculate(wpi::units::meters_per_second_t currentLeftVelocity, wpi::units::meters_per_second_t nextLeftVelocity, wpi::units::meters_per_second_t currentRightVelocity, wpi::units::meters_per_second_t nextRightVelocity, wpi::units::second_t dt)
Calculates the differential drive feedforward inputs given velocity setpoints.
decltype(1_V/1_mps_sq) m_kAAngular
Definition DifferentialDriveFeedforward.hpp:98
decltype(1_V/1_mps) m_kVLinear
Definition DifferentialDriveFeedforward.hpp:95
A plant defined using state-space notation.
Definition LinearSystem.hpp:35
Linear system factories.
Definition Models.hpp:26
Definition LinearSystem.hpp:20
Definition CvSource.hpp:15
Motor voltages for a differential drive.
Definition DifferentialDriveWheelVoltages.hpp:14