YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
SwerveModule.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Yet Another Software Suite
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <functional>
7#include <optional>
8#include <string>
9#include <wpi/math/kinematics/SwerveModulePosition.hpp>
10#include <wpi/math/kinematics/SwerveModuleVelocity.hpp>
11#include <wpi/units/angle.hpp>
12#include <wpi/units/force.hpp>
13
19
21
82 public:
90
99 void SetupTelemetry(const std::string& mechName);
100
105
107 std::string GetName() const;
108
110 wpi::units::degree_t GetRawAbsoluteEncoderAngle() const;
111
114
123 wpi::math::SwerveModuleVelocity SetSwerveModuleState(wpi::math::SwerveModuleVelocity state);
124
134 wpi::math::SwerveModuleVelocity SetSwerveModuleState(wpi::math::SwerveModuleVelocity state,
135 wpi::units::newton_t feedforwardForce);
136
139
148 wpi::math::SwerveModuleVelocity SetAzimuthAngle(wpi::math::Rotation2d angle);
149
150
153
155 wpi::math::SwerveModulePosition GetPosition() const;
156
159
162
165
168
169 private:
170 config::SwerveModuleConfig* m_config{nullptr};
174 std::optional<telemetry::SwerveModuleTelemetry> m_swerveModuleTelemetry;
175 std::function<wpi::units::degree_t()> m_azimuthEncoderWithoutOffsets;
176 // Azimuth travel, unwrapped, for taking the coupled wheel travel out of the drive position.
177 mutable std::optional<wpi::math::Rotation2d> m_lastAzimuthAngle;
178 mutable wpi::units::turn_t m_azimuthTravel{0};
179
181 wpi::units::meter_t GetCouplingDistance(wpi::units::turn_t azimuthAngle) const;
183 double GetDriveRotorToMechanismRatio() const;
184 public:
186 wpi::units::meters_per_second_t GetCouplingVelocity() const;
187
188 // Public so SwerveDrive can access them directly (mirrors Java protected fields).
191};
192
193} // namespace yams::mechanisms::swerve
Definition SwerveModuleConfig.hpp:30
Definition SwerveModule.hpp:81
wpi::math::SwerveModuleVelocity SetSwerveModuleState(wpi::math::SwerveModuleVelocity state)
motorcontrollers::SmartMotorController * m_azimuthMotorController
Definition SwerveModule.hpp:190
motorcontrollers::SmartMotorController * m_driveMotorController
Definition SwerveModule.hpp:189
void SetupTelemetry(const std::string &mechName)
wpi::math::SwerveModulePosition GetPosition() const
motorcontrollers::SmartMotorController * GetAzimuthMotorController() const
SwerveModule(config::SwerveModuleConfig *config)
SwerveModuleVelocityWithAzimuth GetState() const
wpi::math::SwerveModuleVelocity SetAzimuthAngle(wpi::math::Rotation2d angle)
wpi::units::meters_per_second_t GetCouplingVelocity() const
wpi::math::SwerveModuleVelocity SetSwerveModuleState(wpi::math::SwerveModuleVelocity state, wpi::units::newton_t feedforwardForce)
const config::SwerveModuleConfig & GetConfig() const
config::SwerveModuleConfig & GetMutableConfig()
wpi::units::degree_t GetRawAbsoluteEncoderAngle() const
motorcontrollers::SmartMotorController * GetDriveMotorController() const
Definition SmartMotorController.hpp:48
Definition MechanismTelemetry.hpp:34
Definition SwerveDrive.hpp:49
Definition SwerveModuleVelocityWithAzimuth.hpp:19