7#include <frc2/command/SubsystemBase.h>
14#include "ctre/Phoenix.h"
15#include "networktables/NetworkTable.h"
16#include "networktables/NetworkTableEntry.h"
17#include "networktables/NetworkTableInstance.h"
18#include "networktables/NetworkTableValue.h"
19#include "photonlib/PhotonCamera.h"
21#include "units/angle.h"
22#include "units/angular_velocity.h"
23#include "units/length.h"
79 void adjustPerspective(units::degree_t& currentPitch,
const units::degree_t& currentYaw);
128 units::degree_t cx, units::degree_t cy,
int bboxHorizontalPixels,
int bboxVerticalPixels, units::degree_t skew);
202 bool AutoAim(
bool drivingAdjustment =
false);
209 void Shoot(
double ballfiringspeed);
217 void ManualAim(
double turnSpeed,
double hoodSpeed);
224 void CloseLoopShoot(units::revolutions_per_minute_t ShooterWheelSpeed);
439 units::degree_t hubTurretAngle);
442 units::foot_t hubDistance,
443 units::degree_t hubAngle,
444 units::second_t targetStaleness);
Provides methods for interacting with the camera on a high level.
Definition: shooter_subsystem.h:95
void SetDriverMode(bool mode)
Turns the camera's driver mode on and off.
Definition: shooter_subsystem.cpp:628
units::angle::degree_t GetNewPitch(units::degree_t cx, units::degree_t cy, int bboxHorizontalPixels, int bboxVerticalPixels, units::degree_t skew)
Gets the new pitch for the top of the target.
Definition: shooter_subsystem.cpp:644
CameraInterface()
Definition: shooter_subsystem.cpp:626
units::angle::degree_t HorizontalPixelToAngle(int pixels)
Converts horizontal pixels to degrees.
Definition: shooter_subsystem.cpp:636
units::angle::degree_t VerticalPixelToAngle(int pixels)
Converts vertical pixels to degrees.
Definition: shooter_subsystem.cpp:640
std::optional< LimelightTarget > GetHighestTarget()
Get the highest target the camera can see CAN RETURN NONE.
LimelightTarget m_target
object that holds the current target seen by the camera
Definition: shooter_subsystem.h:99
Saves and loads home positions from filesystem.
Definition: homing_storage_interface.h:45
Wraps a limelight target in a usable object.
Definition: shooter_subsystem.h:30
bool HasTarget()
Does the camera see a target?
Definition: shooter_subsystem.cpp:688
units::degree_t m_pitch
Pitch of target relative to camera -20.5 to 20.5 degrees.
Definition: shooter_subsystem.h:32
LimelightTarget()=default
double m_bboxVer
Shortest edge of bounding box (vertical in our case) in px.
Definition: shooter_subsystem.h:35
units::degree_t m_skew
The skew or rotation -90 to 0 degrees.
Definition: shooter_subsystem.h:36
void adjustPerspective(units::degree_t ¤tPitch, const units::degree_t ¤tYaw)
Adjusts pitch based on the current yaw to correct the camera perspective. Perspective distortion poly...
Definition: shooter_subsystem.cpp:692
units::degree_t m_yaw
Yaw of target relative to camera -27 to 27 degrees.
Definition: shooter_subsystem.h:33
bool m_hasTargets
True if the camera has a target it can read.
Definition: shooter_subsystem.h:37
units::millisecond_t m_pipelineLatency
Pipeline latency contribution.
Definition: shooter_subsystem.h:38
double m_bboxHor
Longest edge of bounding box (horizontal in our case) in px.
Definition: shooter_subsystem.h:34
static constexpr units::millisecond_t m_miscLatency
Any extra latency to account for.
Definition: shooter_subsystem.h:39
tValues GetTarget()
Get the values of the camera's current target.
Definition: shooter_subsystem.cpp:673
Definition: shooter_subsystem.h:138
const argos_lib::CANAddress m_hoodMotorAddr
Definition: shooter_subsystem.h:448
void StopFeedback() const
Stop vibration feedback.
Definition: shooter_subsystem.cpp:518
void HoodSetPosition(units::degree_t angle)
Closed loop go to position.
Definition: shooter_subsystem.cpp:278
bool AutoAim(bool drivingAdjustment=false)
Auto aims shooter to hub using vision.
Definition: shooter_subsystem.cpp:108
units::degree_t GetHoodPosition()
Get the hood position in physical units.
Definition: shooter_subsystem.cpp:286
argos_lib::InterpolationMap< decltype(shooterRange::lateralSpeed.front().inVal), shooterRange::lateralSpeed.size(), decltype(shooterRange::lateralSpeed.front().outVal)> m_lateralSpeedMap
Definition: shooter_subsystem.h:478
ShooterDistanceSetpoints GetShooterDistanceSetpoints(units::inch_t distanceToTarget) const
Get the shooter setpoints for a target distance.
Definition: shooter_subsystem.cpp:432
HubRelativeVelocities ChassisVelocitiesToHubVelocities(const frc::ChassisSpeeds robotChassisSpeed, units::degree_t hubTurretAngle)
Generate hub-relative velocities for driving shot.
Definition: shooter_subsystem.cpp:532
void UpdateTurretHome()
Update turret home position.
Definition: shooter_subsystem.cpp:314
LimelightTarget::tValues GetCameraTargetValues()
Get the pitch and yaw of target.
Definition: shooter_subsystem.cpp:477
bool m_useCalculatedPitch
True if we want to use the calculated pitch to the top of the hood.
Definition: shooter_subsystem.h:465
units::angular_velocity::revolutions_per_minute_t GetShooterSpeed()
Get the shooter speed in physical units.
Definition: shooter_subsystem.cpp:241
argos_lib::NTMotorPIDTuner m_hoodPIDTuner
Assists hood PID tuning.
Definition: shooter_subsystem.h:480
void ManualAim(double turnSpeed, double hoodSpeed)
manually aiming the turret
Definition: shooter_subsystem.cpp:259
void UpdateHoodHome()
Update hood home position.
Definition: shooter_subsystem.cpp:290
std::optional< units::degree_t > TurretGetPosition()
Get current angle of turret with 0 degrees at intake side and positive counterclockwise.
Definition: shooter_subsystem.cpp:357
bool IsHoodHomed()
Detect if hood homing is complete.
Definition: shooter_subsystem.cpp:302
bool IsTurretHomed()
Detect if turret homing is complete.
Definition: shooter_subsystem.cpp:344
void SetTurretSoftLimits()
Sets and enables soft angle limits for turret.
Definition: shooter_subsystem.cpp:371
WPI_TalonFX m_shooterWheelRight
Right shooter wheel drive motor.
Definition: shooter_subsystem.h:454
void AimedFeedback() const
Activate vibration feedback to indicate aimed.
Definition: shooter_subsystem.cpp:525
void MoveHood(double hoodSpeed)
Move hood at specified percent speed.
Definition: shooter_subsystem.cpp:270
CameraInterface m_cameraInterface
Interface to limelight camera.
Definition: shooter_subsystem.h:458
std::optional< units::degree_t > GetTurretTargetAngle(LimelightTarget::tValues target)
Get the angle to aim at a specified target. 0 Degrees is toward intake, positive CCW.
Definition: shooter_subsystem.cpp:445
FSHomingStorage< units::degree_t > m_turretHomingStorage
Filesystem storage for turret rotation.
Definition: shooter_subsystem.h:460
void Disable()
Runs on robot disable to reset manual control.
Definition: shooter_subsystem.cpp:411
argos_lib::InterpolationMap< decltype(shooterRange::hoodAngle.front().inVal), shooterRange::hoodAngle.size(), decltype(shooterRange::hoodAngle.front().outVal)> m_hoodAngleMap
Maps a distance to a hood angle.
Definition: shooter_subsystem.h:474
SwerveDriveSubsystem * m_pDriveSubsystem
Pointer to drivetrain for reading some odometry.
Definition: shooter_subsystem.h:486
units::inch_t GetPolynomialOffset(units::inch_t actualDistance)
Gets the offset for the distance of targets above 7.416667 ft (89 in)
Definition: shooter_subsystem.cpp:202
void TurretSetPosition(units::degree_t angle)
Closed-loop go to turret position.
Definition: shooter_subsystem.cpp:348
const argos_lib::CANAddress m_turretMotorAddr
Definition: shooter_subsystem.h:449
units::inch_t GetTargetDistance(units::degree_t targetVerticalAngle)
Gets from the target to the camera.
Definition: shooter_subsystem.cpp:420
const argos_lib::CANAddress m_shooterWheelLeftAddr
Definition: shooter_subsystem.h:446
ShooterDistanceSetpoints SetShooterDistance(units::inch_t distanceToTarget)
Setting the shooter speed and hood angle depeneding on how far away the target is.
Definition: shooter_subsystem.cpp:438
bool m_turretHomed
True when turret has known closed loop position.
Definition: shooter_subsystem.h:463
bool m_manualOverride
Definition: shooter_subsystem.h:464
const argos_lib::CANAddress m_shooterWheelRightAddr
Definition: shooter_subsystem.h:447
bool IsManualOverride()
Detect if manual control has been enabled.
Definition: shooter_subsystem.cpp:310
void ManualOverride()
Override automatic control.
Definition: shooter_subsystem.cpp:246
FixedPosState
Cardinal directions used for aiming without vision.
Definition: shooter_subsystem.h:169
@ Back
Opposite intake side.
@ Right
90 degrees CW from intake side
@ Left
90 degrees CCW from intake side
static bool InAcceptableRanges(const AimValues targets, const AimValues real)
Checks if all shooter values are close enough to target values.
Definition: shooter_subsystem.cpp:488
void CloseLoopShoot(units::revolutions_per_minute_t ShooterWheelSpeed)
Run shooter at desired speed.
Definition: shooter_subsystem.cpp:254
WPI_TalonFX m_shooterWheelLeft
Left shooter wheel drive motor.
Definition: shooter_subsystem.h:453
AimOffsets DrivingAimOffsets(const HubRelativeVelocities robotVelocity, units::foot_t hubDistance, units::degree_t hubAngle, units::second_t targetStaleness)
Definition: shooter_subsystem.cpp:562
void MoveTurret(double turnSpeed)
Move turret at specified percent speed.
Definition: shooter_subsystem.cpp:274
void DisableTurretSoftLimits()
Disables soft angle limits for turret.
Definition: shooter_subsystem.cpp:385
argos_lib::NTMotorPIDTuner m_shooterPIDTuner
Assists shooter PID tuning.
Definition: shooter_subsystem.h:481
argos_lib::InterpolationMap< decltype(shooterRange::shooterSpeed.front().inVal), shooterRange::shooterSpeed.size(), decltype(shooterRange::shooterSpeed.front().outVal)> m_shooterSpeedMap
Maps distance to a shooter wheel speed.
Definition: shooter_subsystem.h:470
argos_lib::SwappableControllersSubsystem * m_pControllers
Pointer to controller subsystem for vibration feedback.
Definition: shooter_subsystem.h:487
argos_lib::NTMotorPIDTuner m_turretPIDTuner
Assists turret PID tuning.
Definition: shooter_subsystem.h:482
void SetHoodSoftLimits()
Sets and enables soft angle limits for hood.
Definition: shooter_subsystem.cpp:390
void Periodic() override
Definition: shooter_subsystem.cpp:90
bool m_hoodHomed
True when hood has known closed loop position.
Definition: shooter_subsystem.h:462
void Shoot(double ballfiringspeed)
pressing a button to fire a ball
Definition: shooter_subsystem.cpp:250
units::revolutions_per_minute_t GetShooterWheelSpeed()
Get the speed of the shooter wheel in RPM.
void InitializeTurretHome()
Initialize turret position based on saved home.
Definition: shooter_subsystem.cpp:326
bool IsHoodMoving()
Detect if hood is moving.
Definition: shooter_subsystem.cpp:298
void DisableHoodSoftLimits()
Disables soft angle limits for hood.
Definition: shooter_subsystem.cpp:403
WPI_TalonSRX m_turretMotor
Turret rotation motor.
Definition: shooter_subsystem.h:456
argos_lib::RobotInstance m_instance
Contains either the competition bot or practice bot. Differentiates between the two.
Definition: shooter_subsystem.h:485
void ClearHoodHome()
Reset hood home status.
Definition: shooter_subsystem.cpp:306
void SetCameraDriverMode(bool driverMode)
Set camera mode to driver mode without LEDs or targetting mode with LEDs.
Definition: shooter_subsystem.cpp:481
void FixedShooterPosition(FixedPosState)
Handles fixed close shot shooting positions around hub.
Definition: shooter_subsystem.cpp:220
WPI_TalonSRX m_hoodMotor
Hood articulation drive motor.
Definition: shooter_subsystem.h:455
Subsystem for controlling the swerve drivetrain of the robot.
Definition: swerve_drive_subsystem.h:50
Performs linear interpolation of a value based on a set of input->output mapping points.
Definition: interpolation.h:46
Allows user to set PID parameters from network tables and update the motor configurations on updates....
Definition: nt_motor_pid_tuner.h:48
Allows two controllers to swap between "Driver" and "Operator" control schemes on the fly by swapping...
Definition: swappable_controllers_subsystem.h:18
RobotInstance
Differentiates between practice robot and competition robot.
Definition: config_types.h:13
constexpr std::array shooterSpeed
Definition: interpolation_maps.h:17
constexpr std::array hoodAngle
Definition: interpolation_maps.h:25
constexpr std::array lateralSpeed
Definition: interpolation_maps.h:33
Shooter aiming parameters.
Definition: shooter_subsystem.h:85
units::degree_t hoodTarget
Hood and target.
Definition: shooter_subsystem.h:87
units::angular_velocity::revolutions_per_minute_t shooterTarget
Shooter wheel velocity target.
Definition: shooter_subsystem.h:88
units::degree_t turretTarget
Shooter turret angle target.
Definition: shooter_subsystem.h:86
Wraps members of LimelightTarget for use elsewhere.
Definition: shooter_subsystem.h:48
units::degree_t yaw
See LimelightTarget::m_yaw.
Definition: shooter_subsystem.h:50
units::millisecond_t totalLatency
See LimelightTarget::m_pipelineLatency.
Definition: shooter_subsystem.h:54
units::degree_t skew
See LimelightTarget::m_skew.
Definition: shooter_subsystem.h:53
units::degree_t pitch
See LimelightTarget::m_pitch.
Definition: shooter_subsystem.h:49
double bboxHor
See LimelightTarget::m_bboxHor.
Definition: shooter_subsystem.h:51
double bboxVer
See LimelightTarget::m_m_bboxVer.
Definition: shooter_subsystem.h:52
Offsets useful for aiming while driving.
Definition: shooter_subsystem.h:157
units::degree_t yawOffset
Positive indicates aim left of hub to compensate for robot lateral motion.
Definition: shooter_subsystem.h:159
units::foot_t distanceOffset
Positive indicates aim farther to compensate for motion away from hub.
Definition: shooter_subsystem.h:158
Definition: shooter_subsystem.h:148
units::degrees_per_second_t chassisYawRate
Positive is robot rotating counterclockwise.
Definition: shooter_subsystem.h:151
units::feet_per_second_t tangentialVelocity
Positive is velocity clockwise around hub.
Definition: shooter_subsystem.h:150
units::feet_per_second_t radialVelocity
Positive is velocity toward center of hub.
Definition: shooter_subsystem.h:149
Hood and shooter setpoints for shooting at a known distance.
Definition: shooter_subsystem.h:143
units::degree_t hoodAngle
Definition: shooter_subsystem.h:145
units::revolutions_per_minute_t shooterSpeed
Definition: shooter_subsystem.h:144
Definition: config_types.h:25