RIT VEXU Core API
Loading...
Searching...
No Matches
flywheel.h
1#pragma once
2
3#include "../core/include/robot_specs.h"
4#include "../core/include/subsystems/screen.h"
5#include "../core/include/utils/command_structure/auto_command.h"
6#include "../core/include/utils/controls/feedforward.h"
7#include "../core/include/utils/controls/pid.h"
8#include "vex.h"
9#include <atomic>
10
18class Flywheel {
19
20public:
21 // CONSTRUCTORS, GETTERS, AND SETTERS
30 Flywheel(vex::motor_group &motors, Feedback &feedback, FeedForward &helper, const double ratio, Filter &filt);
31
36 double get_target() const;
37
41 double getRPM() const;
42
46 vex::motor_group &get_motors() const;
47
54 void spin_manual(double speed, directionType dir = fwd);
55
61 void spin_rpm(double rpm);
62
66 void stop();
67
72 bool is_on_target() { return fb.is_on_target(); }
73
78 screen::Page *Page() const;
79
85 AutoCommand *SpinRpmCmd(int rpm) {
86
87 return new FunctionCommand([this, rpm]() {
88 spin_rpm(rpm);
89 return true;
90 });
91 }
92
98 AutoCommand *WaitUntilUpToSpeedCmd() {
99 return new WaitUntilCondition(new FunctionCondition([this]() { return is_on_target(); }));
100 }
101
102private:
103 friend class FlywheelPage;
104 friend int spinRPMTask(void *wheelPointer);
105
106 vex::motor_group &motors;
107 bool task_running = false;
108 Feedback &fb;
109 FeedForward &ff;
110 vex::mutex fb_mut;
111 double ratio;
112 std::atomic<double> target_rpm;
113 task rpm_task;
114 Filter &avger;
115
116 // Functions for internal use only
121 void set_target(double value);
125 double measure_RPM();
126
133 void spin_raw(double speed, directionType dir = fwd);
134};
Definition feedforward.h:29
Definition feedback_base.h:10
virtual bool is_on_target()=0
Definition moving_average.h:8
Definition flywheel.h:18
AutoCommand * WaitUntilUpToSpeedCmd()
Creates a new auto command that will hold until the flywheel has its target as defined by its feedbac...
Definition flywheel.h:98
vex::motor_group & get_motors() const
Definition flywheel.cpp:26
void spin_manual(double speed, directionType dir=fwd)
Definition flywheel.cpp:85
screen::Page * Page() const
Creates a page displaying info about the flywheel.
Definition flywheel.cpp:165
Flywheel(vex::motor_group &motors, Feedback &feedback, FeedForward &helper, const double ratio, Filter &filt)
Definition flywheel.cpp:15
bool is_on_target()
check if the feedback controller thinks the flywheel is on target
Definition flywheel.h:72
void stop()
Definition flywheel.cpp:119
void spin_rpm(double rpm)
Definition flywheel.cpp:96
double getRPM() const
Definition flywheel.cpp:38
double get_target() const
Definition flywheel.cpp:21
friend int spinRPMTask(void *wheelPointer)
Definition flywheel.cpp:43
AutoCommand * SpinRpmCmd(int rpm)
Creates a new auto command to spin the flywheel at the desired velocity.
Definition flywheel.h:85
Definition auto_command.h:73
FunctionCondition is a quick and dirty Condition to wrap some expression that should be evaluated at ...
Definition auto_command.h:105
Waits until the condition is true.
Definition auto_command.h:130
Page describes one part of the screen slideshow.
Definition screen.h:125