RIT VEXU Core API
Loading...
Searching...
No Matches
flywheel.h
1#pragma once
2
3#include "vex/vex.h"
4
5#include "core/screen/screen_book.h"
6#include "core/competition/command_structure/auto_command.h"
7#include "core/math/controls/feedforward.h"
8#include "core/math/moving_average.h"
9
10#include <atomic>
11
20class Flywheel {
21 public:
22 // CONSTRUCTORS, GETTERS, AND SETTERS
34 vex::motor_group& motors, Feedback& feedback, FeedForward& helper, const double ratio,
35 Filter& filt
36 );
37
42 double get_target() const;
43
45 double getRPM() const;
46
48 vex::motor_group& get_motors() const;
49
57 void spin_manual(double speed, vex::directionType dir = vex::fwd);
58
64 void spin_rpm(double rpm);
65
68 void stop();
69
74 bool is_on_target() { return fb.is_on_target(); }
75
80 ScreenPage* Page() const;
81
87 AutoCommand* SpinRpmCmd(int rpm) {
88 return new FunctionCommand([this, rpm]() {
89 spin_rpm(rpm);
90 return true;
91 });
92 }
93
99 AutoCommand* WaitUntilUpToSpeedCmd() {
100 return new WaitUntilCondition(new FunctionCondition([this]() { return is_on_target(); }));
101 }
102
103 private:
104 friend class FlywheelPage;
105 friend int spinRPMTask(void* wheelPointer);
106
107 vex::motor_group& motors;
108 bool task_running = false;
109 Feedback& fb;
110 FeedForward& ff;
111 vex::mutex fb_mut;
112 double ratio;
113 std::atomic<double> target_rpm;
114 vex::task rpm_task;
115 Filter& avger;
116
117 // Functions for internal use only
122 void set_target(double value);
123
126 double measure_RPM();
127
134 void spin_raw(double speed, vex::directionType dir = vex::fwd);
135};
Definition feedforward.h:29
Definition feedback_base.h:10
Definition moving_average.h:8
AutoCommand * WaitUntilUpToSpeedCmd()
Creates a new auto command that will hold until the flywheel has its target as defined by its feedbac...
Definition flywheel.h:99
vex::motor_group & get_motors() const
Returns the motors.
Definition flywheel.cpp:20
Flywheel(vex::motor_group &motors, Feedback &feedback, FeedForward &helper, const double ratio, Filter &filt)
Definition flywheel.cpp:13
bool is_on_target()
check if the feedback controller thinks the flywheel is on target
Definition flywheel.h:74
void spin_manual(double speed, vex::directionType dir=vex::fwd)
Definition flywheel.cpp:77
void stop()
stop the RPM thread and the wheel
Definition flywheel.cpp:109
void spin_rpm(double rpm)
Definition flywheel.cpp:88
double getRPM() const
return the velocity of the flywheel
Definition flywheel.cpp:32
double get_target() const
Return the current value that the target_rpm should be set to.
Definition flywheel.cpp:17
AutoCommand * SpinRpmCmd(int rpm)
Creates a page displaying info about the flywheel.
Definition flywheel.h:87
Definition auto_command.h:91
FunctionCondition is a quick and dirty Condition to wrap some expression that should be evaluated at ...
Definition auto_command.h:120
Page describes one part of the screen slideshow.
Definition screen_pages.h:147
Waits until the condition is true.
Definition auto_command.h:145