2023-Robot
Robot code for 2023 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
16#include "ctre/Phoenix.h"
17
18namespace argos_lib {
19
27 template <class Callable>
28 constexpr double GetSensorConversionFactor(Callable toPhysicalUnitsFunction) {
29 return toPhysicalUnitsFunction(1.0).template to<double>();
30 }
31
36 double position{1.0};
37 double velocity{1.0};
38 double setpoint{
39 1.0};
40 };
41
49 public:
58 NTMotorPIDTuner(const std::string& tableName,
59 std::initializer_list<ctre::phoenix::motorcontrol::can::BaseTalon*> motors,
60 unsigned pidSlot,
61 ClosedLoopSensorConversions sensorConversions = {});
62
67
68 private:
71 const std::vector<ctre::phoenix::motorcontrol::can::BaseTalon*>
73 const unsigned m_pidSlot;
74 std::shared_ptr<nt::NetworkTable> m_pntTable;
77
78 std::mutex m_threadMutex;
79 std::condition_variable m_threadStopCv;
81
86 };
87
88} // 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:48
ClosedLoopSensorConversions m_sensorConversions
Sensor conversion factors used to translate raw sensor readings.
Definition nt_motor_pid_tuner.h:76
argos_lib::NTSubscriber m_updateSubscriber
Subscriber to manage all updates from user inputs through network tables.
Definition nt_motor_pid_tuner.h:70
const std::vector< ctre::phoenix::motorcontrol::can::BaseTalon * > m_pMotors
Motors being configured and monitored.
Definition nt_motor_pid_tuner.h:72
std::mutex m_threadMutex
Lock to aid notifying thread of stop.
Definition nt_motor_pid_tuner.h:78
const unsigned m_pidSlot
PID slot index actively used on motors.
Definition nt_motor_pid_tuner.h:73
std::thread m_statusUpdateThread
Thread monitoring motors.
Definition nt_motor_pid_tuner.h:80
std::shared_ptr< nt::NetworkTable > m_pntTable
Network table containing status and tuning keys.
Definition nt_motor_pid_tuner.h:74
std::condition_variable m_threadStopCv
Used to notify thread to stop at shutdown.
Definition nt_motor_pid_tuner.h:79
~NTMotorPIDTuner()
Destroy the NTMotorPIDTuner object.
Definition nt_motor_pid_tuner.cpp:79
void UpdateClosedLoopMonitoringThread()
Update statuses from all motors.
Definition nt_motor_pid_tuner.cpp:84
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 GetSensorConversionFactor(Callable toPhysicalUnitsFunction)
Generates a double value to convert raw sensor values to physical units represented as a double.
Definition nt_motor_pid_tuner.h:28
Conversion factors to aid displaying sensor values as meaningful numbers.
Definition nt_motor_pid_tuner.h:35
double velocity
Multiply by this to convert sensor velocity units to physical units.
Definition nt_motor_pid_tuner.h:37
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:38
double position
Multiply by this to convert sensor position units to physical units.
Definition nt_motor_pid_tuner.h:36