2024-Robot
Robot code for 2024 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
nt_motor_pid_tuner.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <condition_variable>
8#include <initializer_list>
9#include <memory>
10#include <mutex>
11#include <string>
12#include <thread>
13#include <vector>
14
15#include <ctre/phoenix6/core/CoreTalonFX.hpp>
16
18
19namespace argos_lib {
20
28 template <class Callable>
29 constexpr double GetPositionConversionFactor(Callable toPhysicalUnitsFunction) {
30 return toPhysicalUnitsFunction(units::angle::turn_t{1}).template to<double>();
31 }
32
40 template <class Callable>
41 constexpr double GetVelocityConversionFactor(Callable toPhysicalUnitsFunction) {
42 return toPhysicalUnitsFunction(units::angle::turn_t{1.0} / units::time::second_t{1.0}).template to<double>();
43 }
44
49 double position{1.0};
50 double velocity{1.0};
51 double setpoint{
52 1.0};
53 };
54
62 using BaseTalon = ctre::phoenix6::hardware::core::CoreTalonFX;
63
64 public:
73 NTMotorPIDTuner(const std::string& tableName,
74 std::initializer_list<BaseTalon*> motors,
75 unsigned pidSlot,
76 ClosedLoopSensorConversions sensorConversions = {});
77
82
83 private:
86 const std::vector<BaseTalon*> m_pMotors;
87 const unsigned m_pidSlot;
88 std::shared_ptr<nt::NetworkTable> m_pntTable;
91
92 std::mutex m_threadMutex;
93 std::condition_variable m_threadStopCv;
95
96 ctre::phoenix6::configs::SlotConfigs m_activeConfigs;
97
102 };
103
104} // namespace argos_lib
Allows user to set PID parameters from network tables and update the motor configurations on updates....
Definition nt_motor_pid_tuner.h:61
ClosedLoopSensorConversions m_sensorConversions
Sensor conversion factors used to translate raw sensor readings.
Definition nt_motor_pid_tuner.h:90
ctre::phoenix6::hardware::core::CoreTalonFX BaseTalon
Definition nt_motor_pid_tuner.h:62
argos_lib::NTSubscriber m_updateSubscriber
Subscriber to manage all updates from user inputs through network tables.
Definition nt_motor_pid_tuner.h:85
std::mutex m_threadMutex
Lock to aid notifying thread of stop.
Definition nt_motor_pid_tuner.h:92
const unsigned m_pidSlot
PID slot index actively used on motors.
Definition nt_motor_pid_tuner.h:87
std::thread m_statusUpdateThread
Thread monitoring motors.
Definition nt_motor_pid_tuner.h:94
std::shared_ptr< nt::NetworkTable > m_pntTable
Network table containing status and tuning keys.
Definition nt_motor_pid_tuner.h:88
std::condition_variable m_threadStopCv
Used to notify thread to stop at shutdown.
Definition nt_motor_pid_tuner.h:93
~NTMotorPIDTuner()
Destroy the NTMotorPIDTuner object.
Definition nt_motor_pid_tuner.cpp:109
void UpdateClosedLoopMonitoringThread()
Update statuses from all motors.
Definition nt_motor_pid_tuner.cpp:114
ctre::phoenix6::configs::SlotConfigs m_activeConfigs
Current PID configurations.
Definition nt_motor_pid_tuner.h:96
const std::vector< BaseTalon * > m_pMotors
Motors being configured and monitored.
Definition nt_motor_pid_tuner.h:86
Subscribes to Network Tables entry updates and calls a specified callback to use the new value.
Definition nt_subscriber.h:17
Definition swap_controllers_command.h:12
constexpr double GetVelocityConversionFactor(Callable toPhysicalUnitsFunction)
Generates a double value to convert sensor velocity values to physical units represented as a double.
Definition nt_motor_pid_tuner.h:41
constexpr double GetPositionConversionFactor(Callable toPhysicalUnitsFunction)
Generates a double value to convert sensor position values to physical units represented as a double.
Definition nt_motor_pid_tuner.h:29
Conversion factors to aid displaying sensor values as meaningful numbers.
Definition nt_motor_pid_tuner.h:48
double velocity
Multiply by this to convert sensor velocity units to physical units.
Definition nt_motor_pid_tuner.h:50
double setpoint
Multiply by this to convert sensor setpoint units to physical units (should be the same as either pos...
Definition nt_motor_pid_tuner.h:51
double position
Multiply by this to convert sensor position units to physical units.
Definition nt_motor_pid_tuner.h:49