WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
Kinematics.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
11
12namespace wpi::math {
13/**
14 * Helper class that converts a chassis velocity (dx, dy, and dtheta components)
15 * into individual wheel velocities. Robot code should not use this directly-
16 * Instead, use the particular type for your drivetrain (e.g.,
17 * DifferentialDriveKinematics).
18 *
19 * Inverse kinematics converts a desired chassis velocity into wheel velocities
20 * whereas forward kinematics converts wheel velocities into chassis velocity.
21 */
22template <typename WheelPositions, typename WheelVelocities,
23 typename WheelAccelerations>
24 requires std::copy_constructible<WheelPositions> &&
25 std::assignable_from<WheelPositions&, const WheelPositions&>
27 public:
28 virtual ~Kinematics() noexcept = default;
29
30 /**
31 * Performs forward kinematics to return the resulting chassis velocity from
32 * the wheel velocities. This method is often used for odometry -- determining
33 * the robot's position on the field using data from the real-world velocity
34 * of each wheel on the robot.
35 *
36 * @param wheelVelocities The velocities of the wheels.
37 * @return The chassis velocity.
38 */
40 const WheelVelocities& wheelVelocities) const = 0;
41
42 /**
43 * Performs inverse kinematics to return the wheel velocities from a desired
44 * chassis velocity. This method is often used to convert joystick values into
45 * wheel velocities.
46 *
47 * @param chassisVelocities The desired chassis velocity.
48 * @return The wheel velocities.
49 */
50 virtual WheelVelocities ToWheelVelocities(
51 const ChassisVelocities& chassisVelocities) const = 0;
52
53 /**
54 * Performs forward kinematics to return the resulting Twist2d from the given
55 * change in wheel positions. This method is often used for odometry --
56 * determining the robot's position on the field using changes in the distance
57 * driven by each wheel on the robot.
58 *
59 * @param start The starting distances driven by the wheels.
60 * @param end The ending distances driven by the wheels.
61 *
62 * @return The resulting Twist2d in the robot's movement.
63 */
64 virtual Twist2d ToTwist2d(const WheelPositions& start,
65 const WheelPositions& end) const = 0;
66
67 /**
68 * Performs interpolation between two values.
69 *
70 * @param start The value to start at.
71 * @param end The value to end at.
72 * @param t How far between the two values to interpolate. This should be
73 * bounded to [0, 1].
74 * @return The interpolated value.
75 */
76 virtual WheelPositions Interpolate(const WheelPositions& start,
77 const WheelPositions& end,
78 double t) const = 0;
79
80 /**
81 * Performs forward kinematics to return the resulting chassis accelerations
82 * from the wheel accelerations. This method is often used for dynamics
83 * calculations -- determining the robot's acceleration on the field using
84 * data from the real-world acceleration of each wheel on the robot.
85 *
86 * @param wheelAccelerations The accelerations of the wheels.
87 * @return The chassis accelerations.
88 */
90 const WheelAccelerations& wheelAccelerations) const = 0;
91
92 /**
93 * Performs inverse kinematics to return the wheel accelerations from a
94 * desired chassis acceleration. This method is often used for dynamics
95 * calculations -- converting desired robot accelerations into individual
96 * wheel accelerations.
97 *
98 * @param chassisAccelerations The desired chassis accelerations.
99 * @return The wheel accelerations.
100 */
101 virtual WheelAccelerations ToWheelAccelerations(
102 const ChassisAccelerations& chassisAccelerations) const = 0;
103};
104} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Helper class that converts a chassis velocity (dx, dy, and dtheta components) into individual wheel v...
Definition Kinematics.hpp:26
virtual Twist2d ToTwist2d(const WheelPositions &start, const WheelPositions &end) const =0
Performs forward kinematics to return the resulting Twist2d from the given change in wheel positions.
virtual ChassisAccelerations ToChassisAccelerations(const WheelAccelerations &wheelAccelerations) const =0
Performs forward kinematics to return the resulting chassis accelerations from the wheel acceleration...
virtual WheelVelocities ToWheelVelocities(const ChassisVelocities &chassisVelocities) const =0
Performs inverse kinematics to return the wheel velocities from a desired chassis velocity.
virtual ~Kinematics() noexcept=default
virtual WheelAccelerations ToWheelAccelerations(const ChassisAccelerations &chassisAccelerations) const =0
Performs inverse kinematics to return the wheel accelerations from a desired chassis acceleration.
virtual WheelPositions Interpolate(const WheelPositions &start, const WheelPositions &end, double t) const =0
Performs interpolation between two values.
virtual ChassisVelocities ToChassisVelocities(const WheelVelocities &wheelVelocities) const =0
Performs forward kinematics to return the resulting chassis velocity from the wheel velocities.
Definition LinearSystem.hpp:20
Represents robot chassis accelerations.
Definition ChassisAccelerations.hpp:21
Represents robot chassis velocities.
Definition ChassisVelocities.hpp:26
A change in distance along a 2D arc since the last pose update.
Definition Twist2d.hpp:23