2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
swerve_utils.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <frc/kinematics/SwerveModuleState.h>
8#include <units/angle.h>
9#include <units/angular_velocity.h>
10#include <units/velocity.h>
11
12#include <optional>
13
14#include "interpolation.h"
15
16namespace argos_lib {
17 namespace swerve {
18
29 frc::SwerveModuleState Optimize(frc::SwerveModuleState desiredState,
30 units::degree_t currentModuleAngle,
31 units::degrees_per_second_t currentModuleAngularRate,
32 units::feet_per_second_t currentModuleDriveVel,
33 units::feet_per_second_t maxVelocity);
34
39 units::degree_t FrontLeft;
40 units::degree_t FrontRight;
41 units::degree_t RearRight;
42 units::degree_t RearLeft;
43 };
44
52
64 template <class T, int size, class V>
65 [[nodiscard]] constexpr TranslationSpeeds CircularInterpolate(
66 const TranslationSpeeds rawSpeeds, const argos_lib::InterpolationMap<T, size, V> interpMap) {
67 const double magnitude = std::sqrt(std::pow(rawSpeeds.forwardSpeedPct, 2) + std::pow(rawSpeeds.leftSpeedPct, 2));
68 const double angle = std::atan2(rawSpeeds.leftSpeedPct, rawSpeeds.forwardSpeedPct);
69 const double mappedMagnitude = interpMap(magnitude);
70 return TranslationSpeeds{mappedMagnitude * std::cos(angle), mappedMagnitude * std::sin(angle)};
71 }
72
73 } // namespace swerve
74} // namespace argos_lib
Performs linear interpolation of a value based on a set of input->output mapping points.
Definition interpolation.h:46
constexpr TranslationSpeeds CircularInterpolate(const TranslationSpeeds rawSpeeds, const argos_lib::InterpolationMap< T, size, V > interpMap)
Use argos_lib::InterpolationMap to apply mapping according to joystick vector magnitude.
Definition swerve_utils.h:65
frc::SwerveModuleState Optimize(frc::SwerveModuleState desiredState, units::degree_t currentModuleAngle, units::degrees_per_second_t currentModuleAngularRate, units::feet_per_second_t currentModuleDriveVel, units::feet_per_second_t maxVelocity)
Optimize swerve module to minimize rotations and drive direction changes.
Definition swerve_utils.cpp:16
Definition swap_controllers_command.h:12
Representation of the absolute encoder position of each module at home position.
Definition swerve_utils.h:38
units::degree_t FrontRight
Definition swerve_utils.h:40
units::degree_t RearRight
Definition swerve_utils.h:41
units::degree_t FrontLeft
Definition swerve_utils.h:39
units::degree_t RearLeft
Definition swerve_utils.h:42
Translation speeds as percent max output.
Definition swerve_utils.h:48
double leftSpeedPct
Speed with positive left in range [-1, 1].
Definition swerve_utils.h:50
double forwardSpeedPct
Speed with positive forward in range [-1, 1].
Definition swerve_utils.h:49