2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
lifter_subsystem.h
Go to the documentation of this file.
1
4
5#pragma once
6
8#include <ctre/Phoenix.h>
9#include <frc/geometry/Translation2d.h>
10#include <frc2/command/SubsystemBase.h>
11
12#include <string>
13
19
20/* —————————————————————————— SUBSYSTEM CLASS —————————————————————————— */
21
23
24std::string ToString(WristPosition position);
25
26class LifterSubsystem : public frc2::SubsystemBase {
27 public:
29 units::degree_t wristAngle;
31 };
33
36 void SetShoulderSpeed(double speed);
37
40 void SetArmExtensionSpeed(double speed);
41
44 void SetArmExtension(units::inch_t extension);
45
49 bool IsExtensionAt(units::inch_t extension);
50
53 void SetWristSpeed(double speed);
54
56 void StopShoulder();
57
59 void StopArmExtension();
60
62 void StopWrist();
63
67
69 void SetShoulderManualOverride(bool overrideState);
70
74
76 void SetExtensionManualOverride(bool overrideState);
77
81
83 void SetWristManualOverride(bool overrideState);
84
87
90 void SetWristAngle(units::degree_t wristAngle);
91
92 units::degree_t GetWristAbsoluteAngle();
93 double GetLastWristTimestamp();
94
96 void UpdateWristHome();
97
101 void Periodic() override;
102
104 void Disable();
105
109
112 bool IsShoulderMoving();
113
117
120
123
126
128 void UpdateShoulderHome();
129
132 void SetShoulderAngle(units::degree_t angle);
133
137 bool IsShoulderAt(units::degree_t angle);
138
141 frc::Translation2d GetEffectorPose(const WristPosition wristPosition);
142
143 frc::Translation2d GetArmPose();
144
149 LifterPosition SetEffectorPose(const frc::Translation2d& desPose, WristPosition effectorPosition);
150
151 LifterPosition SetLifterPose(const frc::Translation2d& desPose);
152
155 bool IsArmExtensionHomed();
156
159 units::degree_t GetWristAngle();
160
162
165 units::inch_t GetArmExtension();
166
169 units::degree_t GetShoulderAngle();
170
171 units::degree_t GetShoulderBoomAngle();
172
176
181 ArmState ConvertEffectorPose(const frc::Translation2d& pose, WristPosition effectorPosition) const;
182
183 ArmState ConvertLifterPose(const frc::Translation2d& pose) const;
184
185 frc::Translation2d ConvertStateToEffectorPose(const ArmState& state, WristPosition effectorPosition) const;
186 frc::Translation2d ConvertStateToLifterPose(const ArmState& state) const;
187
188 units::inch_t ConvertShoulderAngle(units::degree_t angle) const;
189 units::inches_per_second_t ConvertShoulderVelocity(units::degree_t angle,
190 units::degrees_per_second_t angularVelocity) const;
191
194 bool IsWristMPComplete();
195
196 ctre::phoenix::motion::BufferedTrajectoryPointStream& GetShoulderMPStream();
197 ctre::phoenix::motion::BufferedTrajectoryPointStream& GetExtensionMPStream();
198 ctre::phoenix::motion::BufferedTrajectoryPointStream& GetWristMPStream();
199
200 void StopMotionProfile();
201 void StartMotionProfile(size_t shoulderStreamSize, size_t extensionStreamSize, size_t wristStreamSize);
202
203 void ResetPathFaults();
204 bool IsFatalPathFault();
205
208
211
212 private:
213 // Components (e.g. motor controllers and sensors) should generally be
214 // declared private and exposed only through public methods.
215
216 // Shoulder motors are attached in parallel mechanically to operate shoulder, back motor follows front motor
217 WPI_TalonFX m_shoulderDrive;
219 WPI_TalonFX m_wrist;
221 CANCoder m_wristEncoder;
237
238 ctre::phoenix::motion::BufferedTrajectoryPointStream m_shoulderStream;
239 ctre::phoenix::motion::BufferedTrajectoryPointStream m_extensionStream;
240 ctre::phoenix::motion::BufferedTrajectoryPointStream m_wristStream;
241
244
247
250
253};
Definition lifter_kinematics.h:19
Definition lifter_subsystem.h:26
frc::Translation2d ConvertStateToLifterPose(const ArmState &state) const
Definition lifter_subsystem.cpp:588
bool IsExtensionManualOverride()
Checks if manual extension override member is true.
Definition lifter_subsystem.cpp:210
bool IsFatalPathFault()
Definition lifter_subsystem.cpp:724
void Disable()
Handle robot disabling.
Definition lifter_subsystem.cpp:292
void StopShoulder()
Sets the shoulder motor to zero.
Definition lifter_subsystem.cpp:153
void StopArmExtension()
Sets the arm extension motor to zero.
Definition lifter_subsystem.cpp:184
void InitializeArmExtensionHome()
Initializes the arm extension home from file system.
Definition lifter_subsystem.cpp:327
bool m_shoulderManualOverride
True if manual control is currently in use, do not execute any closed loop.
Definition lifter_subsystem.h:234
argos_lib::NTMotorPIDTuner m_shoulderTuner
TEMP network tables PID tuner for tuning shoulder.
Definition lifter_subsystem.h:230
void SetWristManualOverride(bool overrideState)
Sets the override state of the wrist.
Definition lifter_subsystem.cpp:226
ctre::phoenix::motion::BufferedTrajectoryPointStream m_shoulderStream
Definition lifter_subsystem.h:238
ArmState ConvertEffectorPose(const frc::Translation2d &pose, WristPosition effectorPosition) const
Converts from a point in 2d space to an arm state.
Definition lifter_subsystem.cpp:576
WPI_TalonFX m_wrist
Motor that controls wrist movement.
Definition lifter_subsystem.h:219
void InitializeShoulderHome()
Initializes the homed shoulder value from FS.
Definition lifter_subsystem.cpp:406
void InitializeWristHomes()
Initializes wrist homes from file system.
Definition lifter_subsystem.cpp:359
void DisableShoulderSoftLimits()
Turn off soft limits for arm shoulder.
Definition lifter_subsystem.cpp:704
bool m_extensionHomed
True if extension is homed successfully.
Definition lifter_subsystem.h:232
units::degree_t GetWristAngle()
Gets the wrist angle (right handle rule with axis towards front of robot)
Definition lifter_subsystem.cpp:538
bool IsExtensionMPComplete()
Definition lifter_subsystem.cpp:604
void SetWristSpeed(double speed)
Sets the wrist speed.
Definition lifter_subsystem.cpp:189
void EnableShoulderSoftLimits()
Turn on soft limits for arm shoulder.
Definition lifter_subsystem.cpp:691
argos_lib::ArgosLogger m_logger
Handles logging errors & info.
Definition lifter_subsystem.h:224
bool IsWristMPComplete()
Definition lifter_subsystem.cpp:607
void EnableWristSoftLimits()
Turn on soft limits for wrist.
Definition lifter_subsystem.cpp:651
bool IsShoulderMPComplete()
Definition lifter_subsystem.cpp:601
bool m_wristManualOverride
True if manual control is currently in use, do not execute any closed loop.
Definition lifter_subsystem.h:236
argos_lib::NTMotorPIDTuner m_wristTuner
TEMP network tables PID tuner for tuning wrist.
Definition lifter_subsystem.h:229
bool ArmExtensionHomeFileExists()
Checks if home file for arm extension exists.
Definition lifter_subsystem.cpp:304
void UpdateWristHome()
updating wrist homes for encoder
Definition lifter_subsystem.cpp:391
void SetExtensionManualOverride(bool overrideState)
Sets the override state of the extension.
Definition lifter_subsystem.cpp:214
LifterPosition SetLifterPose(const frc::Translation2d &desPose)
Definition lifter_subsystem.cpp:515
bool IsArmExtensionMoving()
Detect if arm is in motion.
Definition lifter_subsystem.cpp:296
bool m_shoulderHomed
True if the shoulder is homed successfully from file system.
Definition lifter_subsystem.h:231
bool IsWristManualOverride()
Checks if manual wrist override member is true.
Definition lifter_subsystem.cpp:218
LifterPosition GetLifterPosition()
Gets the lifter's current shoulder position represented as a collection of joint states.
Definition lifter_subsystem.cpp:572
argos_lib::NTMotorPIDTuner m_extensionTuner
TEMP network tables PID tuner for tuning extension.
Definition lifter_subsystem.h:228
void UpdateArmExtensionHome()
Update arm home position.
Definition lifter_subsystem.cpp:309
void StartMotionProfile(size_t shoulderStreamSize, size_t extensionStreamSize, size_t wristStreamSize)
Definition lifter_subsystem.cpp:639
WPI_TalonFX m_armExtensionMotor
Motor that controls extension of arm.
Definition lifter_subsystem.h:218
CANCoder m_shoulderEncoder
Encoder that measures shoulder position.
Definition lifter_subsystem.h:220
frc::Translation2d ConvertStateToEffectorPose(const ArmState &state, WristPosition effectorPosition) const
Definition lifter_subsystem.cpp:583
void DisableWristSoftLimits()
Turn off soft limits for wrist.
Definition lifter_subsystem.cpp:666
units::inch_t ConvertShoulderAngle(units::degree_t angle) const
Definition lifter_subsystem.cpp:592
LifterPosition SetEffectorPose(const frc::Translation2d &desPose, WristPosition effectorPosition)
Uses the kinematics object to calculate joint positions for a given pose, then sets the system to tha...
Definition lifter_subsystem.cpp:490
double GetLastWristTimestamp()
Definition lifter_subsystem.cpp:258
CANCoder m_wristEncoder
Encoder for measuring wrist position.
Definition lifter_subsystem.h:221
units::inch_t GetArmExtension()
Gets the arm extension (positive is extend out)
Definition lifter_subsystem.cpp:562
argos_lib::FSHomingStorage< units::degree_t > m_shoulderHomeStorage
File system homing for shoulder.
Definition lifter_subsystem.h:225
void SetShoulderSpeed(double speed)
Sets the arm speed.
Definition lifter_subsystem.cpp:149
bool m_extensionManualOverride
True if manual control is currently in use, do not execute any closed loop.
Definition lifter_subsystem.h:235
units::inches_per_second_t ConvertShoulderVelocity(units::degree_t angle, units::degrees_per_second_t angularVelocity) const
Definition lifter_subsystem.cpp:596
units::degree_t GetShoulderAngle()
Gets the shoulder's angle with positive being rotating down into the robot, and 0 being strait out be...
Definition lifter_subsystem.cpp:565
WPI_TalonFX m_shoulderDrive
Shoulder motor closest to front of robot.
Definition lifter_subsystem.h:217
ArmState ConvertLifterPose(const frc::Translation2d &pose) const
Definition lifter_subsystem.cpp:579
void StopWrist()
Sets the wrist speed to zero.
Definition lifter_subsystem.cpp:195
bool IsShoulderManualOverride()
Checks if manual shoulder override member is true.
Definition lifter_subsystem.cpp:202
frc::Translation2d GetEffectorPose(const WristPosition wristPosition)
Uses the kinematics object to calculate robot pose.
Definition lifter_subsystem.cpp:481
bool m_wristHomed
True if wrist was homed successfully from file system.
Definition lifter_subsystem.h:233
void EnableArmExtensionSoftLimits()
Turn on soft limits for arm extension.
Definition lifter_subsystem.cpp:673
ctre::phoenix::motion::BufferedTrajectoryPointStream & GetExtensionMPStream()
Definition lifter_subsystem.cpp:618
void SetShoulderAngle(units::degree_t angle)
Sets the shoulder joint's angle (see GetShoulderAngle or docs for convention)
Definition lifter_subsystem.cpp:447
bool IsArmExtensionHomed()
Is the arm extension homed?
Definition lifter_subsystem.cpp:534
bool IsExtensionAt(units::inch_t extension)
Checks if the arm extension is within an error of extension.
Definition lifter_subsystem.cpp:162
CANCoder m_extensionEncoder
Encoder for measuring extension of arm.
Definition lifter_subsystem.h:222
argos_lib::FSHomingStorage< units::degree_t > m_extensionHomingStorage
File system homing for wrist.
Definition lifter_subsystem.h:227
void StopMotionProfile()
Definition lifter_subsystem.cpp:625
bool IsShoulderMoving()
Detect if shoulder is in motion.
Definition lifter_subsystem.cpp:300
void SetWristAngle(units::degree_t wristAngle)
Sets the wrist angle from min and max angles defined in measure_up. Positive is CW looking down the a...
Definition lifter_subsystem.cpp:232
void DisableArmExtensionSoftLimits()
Turn off soft limits for arm extension.
Definition lifter_subsystem.cpp:686
units::degree_t GetWristAbsoluteAngle()
Definition lifter_subsystem.cpp:250
argos_lib::FSHomingStorage< units::degree_t > m_wristHomingStorage
File system homing for wrist.
Definition lifter_subsystem.h:226
void ResetPathFaults()
Definition lifter_subsystem.cpp:709
ctre::phoenix::motion::BufferedTrajectoryPointStream & GetWristMPStream()
Definition lifter_subsystem.cpp:621
LifterKinematics m_kinematics
Kinematic model for solving arm joints & position.
Definition lifter_subsystem.h:223
frc::Translation2d GetArmPose()
Definition lifter_subsystem.cpp:486
WristPosition GetWristPosition()
Definition lifter_subsystem.cpp:546
void SetArmExtensionSpeed(double speed)
Sets the arm extension motor speed.
Definition lifter_subsystem.cpp:158
void UpdateShoulderHome()
Updates shoulder home in FS, resets relative position on sensor.
Definition lifter_subsystem.cpp:431
ctre::phoenix::motion::BufferedTrajectoryPointStream m_wristStream
Definition lifter_subsystem.h:240
void SetShoulderManualOverride(bool overrideState)
Sets the override state of the shoulder.
Definition lifter_subsystem.cpp:206
ctre::phoenix::motion::BufferedTrajectoryPointStream & GetShoulderMPStream()
Definition lifter_subsystem.cpp:615
ctre::phoenix::motion::BufferedTrajectoryPointStream m_extensionStream
Definition lifter_subsystem.h:239
bool IsShoulderAt(units::degree_t angle)
Checks if the shoulder is within an error of extension.
Definition lifter_subsystem.cpp:477
void SetArmExtension(units::inch_t extension)
Sets the extension of the arm to "extension" inches.
Definition lifter_subsystem.cpp:166
units::degree_t GetShoulderBoomAngle()
Definition lifter_subsystem.cpp:568
void Periodic() override
Definition lifter_subsystem.cpp:263
Log to the console in a clean, repeatable manner.
Definition log.h:22
Saves and loads home positions from filesystem.
Definition fs_homing.h:55
Allows user to set PID parameters from network tables and update the motor configurations on updates....
Definition nt_motor_pid_tuner.h:48
std::string ToString(WristPosition position)
Definition lifter_subsystem.cpp:25
WristPosition
Definition lifter_subsystem.h:22
RobotInstance
Differentiates between practice robot and competition robot.
Definition config_types.h:13
Definition lifter_kinematics.h:14
Definition lifter_subsystem.h:28
units::degree_t wristAngle
Definition lifter_subsystem.h:29
ArmState state
Definition lifter_subsystem.h:30