LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
pid_tuner.hpp
Go to the documentation of this file.
1#pragma once
2#include <array>
3
4#include "LightLib/lib.hpp"
5#include "light/lvgl.h"
6
15namespace light {
16
18enum PidType { PID_DRIVE = 0,
24
31
34 double val[CONST_COUNT] = {0, 0, 0, 0};
35};
36
45class PidTuner {
46 public:
48 void set_drive(light::Drive* drive);
49
51 void start_task();
52
54 void open();
55
57 void close();
58
60 bool is_open() const { return screen_ != nullptr && lv_scr_act() == screen_; }
61
63 light::Drive* get_drive() const { return drive_; }
64
65 private:
66 light::Drive* drive_ = nullptr;
67 lv_obj_t* screen_ = nullptr;
68 lv_obj_t* chart_ = nullptr;
69 lv_chart_series_t* ser_left_ = nullptr;
70 lv_chart_series_t* ser_right_ = nullptr;
71 lv_chart_series_t* ser_err_ = nullptr;
72 lv_obj_t* tab_btns_[PID_COUNT] = {};
73 lv_obj_t* val_labels_[CONST_COUNT] = {};
74 lv_obj_t* name_labels_[CONST_COUNT] = {};
75 PidType active_pid_ = PID_DRIVE;
76 PidConstants constants_[PID_COUNT];
77 bool recording_ = false;
78 pros::Task* sample_task_ = nullptr;
79 double chart_y_max_ = 1.0;
80 double chart_y_min_ = -1.0;
81 // Last bounds we actually pushed to LVGL — guards against per-sample
82 // lv_chart_set_range when nothing changed.
83 double last_chart_y_max_ = 0.0;
84 double last_chart_y_min_ = 0.0;
85
86 void build_ui();
87 void select_pid(PidType t);
88 void refresh_value_labels();
89 void apply_constants();
90 void push_sample();
91
92 static void sample_task_fn(void* param);
93 static void tab_cb(lv_event_t* e);
94 static void inc_cb(lv_event_t* e);
95 static void dec_cb(lv_event_t* e);
96 static void apply_cb(lv_event_t* e);
97 static void back_cb(lv_event_t* e);
98 static void record_cb(lv_event_t* e);
99};
100
102extern PidTuner pid_tuner;
103
104} // namespace light
Tank-drive chassis class.
Definition drive.hpp:72
Live PID tuner UI driven by LVGL.
Definition pid_tuner.hpp:45
void open()
Render and activate the tuner screen.
void start_task()
Spawn the background sampling task that feeds the chart.
void set_drive(light::Drive *drive)
Bind the Drive whose PIDs this tuner will edit.
bool is_open() const
Definition pid_tuner.hpp:60
void close()
Close the tuner screen and restore the previous LVGL screen.
light::Drive * get_drive() const
Definition pid_tuner.hpp:63
Umbrella header for LightLib's own classes.
Public LightLib odometry / pose-estimation API.
Definition pid.hpp:22
PidTuner pid_tuner
Process-wide singleton tuner instance.
PidType
PID controller categories selectable in the tuner.
Definition pid_tuner.hpp:18
@ PID_EKF
EKF heading-fusion PID.
Definition pid_tuner.hpp:22
@ PID_TURN
Heading/turn-in-place PID.
Definition pid_tuner.hpp:19
@ PID_COUNT
Definition pid_tuner.hpp:23
@ PID_HEADING
Heading correction during drive moves.
Definition pid_tuner.hpp:21
@ PID_SWING
Single-side swing PID.
Definition pid_tuner.hpp:20
@ PID_DRIVE
Linear drive PID.
Definition pid_tuner.hpp:18
ConstSlot
Index into a PidConstants slot.
Definition pid_tuner.hpp:26
@ KP
Proportional gain.
Definition pid_tuner.hpp:26
@ CONST_COUNT
Definition pid_tuner.hpp:30
@ START_I
Integral activation threshold.
Definition pid_tuner.hpp:29
@ KD
Derivative gain.
Definition pid_tuner.hpp:28
@ KI
Integral gain.
Definition pid_tuner.hpp:27
Container for one PID's four editable gain values.
Definition pid_tuner.hpp:33
double val[CONST_COUNT]
Definition pid_tuner.hpp:34