2#include <LimelightHelpers.h>
4#include <frc/geometry/Pose3d.h>
5#include <frc/util/Color.h>
6#include <units/angle.h>
7#include <units/angular_acceleration.h>
8#include <units/angular_velocity.h>
10#include <wpi/struct/Struct.h>
12#include "valkyrie/Loggable.h"
155 units::degrees_per_second_squared_t
accelX;
157 units::degrees_per_second_squared_t
accelY;
159 units::degrees_per_second_squared_t
accelZ;
161 constexpr IMUData(LimelightHelpers::IMUData data)
177 struct RawTarget : LimelightHelpers::RawTarget {
183 constexpr RawTarget(LimelightHelpers::RawTarget data) : LimelightHelpers::RawTarget{data},
txnc{data.
txnc},
tync{data.
tync} {}
189 struct RawFiducial : LimelightHelpers::RawFiducial {
199 constexpr RawFiducial(LimelightHelpers::RawFiducial data)
200 : LimelightHelpers::RawFiducial{data},
210 struct RawDetection : LimelightHelpers::RawDetection {
216 constexpr RawDetection(LimelightHelpers::RawDetection data)
223 struct PoseEstimate : LimelightHelpers::PoseEstimate {
235 constexpr PoseEstimate(LimelightHelpers::PoseEstimate data)
236 : LimelightHelpers::PoseEstimate{data},
243 constexpr bool IsValid()
const {
return !
rawFiducials.empty(); }
246 using LimelightHelpers::PoseEstimate::timestampSeconds;
254 inline explicit Limelight(std::string_view name) : name{name} {}
261 inline bool GetTV()
const {
return LimelightHelpers::getTV(name); }
268 inline units::degree_t
GetTX()
const {
return units::degree_t{LimelightHelpers::getTX(name)}; }
275 inline units::degree_t
GetTY()
const {
return units::degree_t{LimelightHelpers::getTY(name)}; }
283 inline units::degree_t
GetTXNC()
const {
return units::degree_t{LimelightHelpers::getTXNC(name)}; }
291 inline units::degree_t
GetTYNC()
const {
return units::degree_t{LimelightHelpers::getTYNC(name)}; }
298 inline double GetTA()
const {
return LimelightHelpers::getTA(name); }
313 inline int GetTargetCount()
const {
return LimelightHelpers::getTargetCount(name); };
341 inline std::string
GetDetectorClass()
const {
return LimelightHelpers::getDetectorClass(name); }
348 inline units::millisecond_t
GetLatencyPipeline()
const {
return units::millisecond_t{LimelightHelpers::getLatency_Pipeline(name)}; }
355 inline units::millisecond_t
GetLatencyCapture()
const {
return units::millisecond_t{LimelightHelpers::getLatency_Capture(name)}; }
376 inline std::string
GetJSONDump()
const {
return LimelightHelpers::getJSONDump(name); }
383 inline frc::Pose3d
GetBotPose()
const {
return LimelightHelpers::getBotPose3d(name); }
390 inline frc::Pose3d
GetBotPoseWpiRed()
const {
return LimelightHelpers::getBotPose3d_wpiRed(name); }
397 inline frc::Pose3d
GetBotPoseWpiBlue()
const {
return LimelightHelpers::getBotPose3d_wpiBlue(name); }
453 inline std::string
GetNeuralClassID()
const {
return LimelightHelpers::getNeuralClassID(name); }
460 inline std::vector<std::string>
GetRawBarcodeData()
const {
return LimelightHelpers::getRawBarcodeData(name); }
468 inline int GetHeartbeat()
const {
return LimelightHelpers::getHeartbeat(name); }
484 inline void SetPipelineIndex(
int index) { LimelightHelpers::setPipelineIndex(name, index); }
530 units::degrees_per_second_t pitchRate, units::degree_t roll, units::degrees_per_second_t rollRate,
539 inline void SetKeystone(
double horizontal,
double vertical) { LimelightHelpers::setKeystone(name, horizontal, vertical); }
548 inline void SetIMUMode(
IMUMode mode) { LimelightHelpers::SetIMUMode(name,
static_cast<int>(mode)); }
556 inline void SetIMUAssistAlpha(
double alpha) { LimelightHelpers::SetIMUAssistAlpha(name, alpha); }
563 inline void SetThrottle(
int throttle) { LimelightHelpers::SetThrottle(name, throttle); }
605 inline void SetPythonScriptData(
const std::vector<double>& outgoingData) { LimelightHelpers::setPythonScriptData(name, outgoingData); }
612 inline std::vector<double>
GetPythonScriptData()
const {
return LimelightHelpers::getPythonScriptData(name); }
625 inline void SetRewindEnabled(
bool enabled) { LimelightHelpers::setRewindEnabled(name, enabled); }
633 inline void TriggerRewindCapture(units::second_t duration) { LimelightHelpers::triggerRewindCapture(name, duration.value()); }
730 static constexpr std::pair<units::degree_t, units::degree_t>
GetFOV(
Model model) {
733 return {54_deg, 41_deg};
736 return {62.5_deg, 48.9_deg};
738 return {62.5_deg, 48.9_deg};
740 return {54.5_deg, 42_deg};
742 return {82_deg, 56.2_deg};
744 return {82_deg, 56.2_deg};
757struct wpi::Struct<valor::cameras::Limelight::TargetMetrics> {
758 static constexpr std::string_view GetTypeName() {
return "LimelightTargetMetrics"; }
760 static constexpr size_t GetSize() {
return 97; }
762 static constexpr std::string_view GetSchema() {
763 return "bool targetValid; int32 targetCount; double targetLatency; double captureLatency; double tx; double ty; double txnc; "
764 "double tync; double ta; int32 tid; int32 targetClassIndexDetector; int32 targetClassIndexClassifier; int32 "
765 "targetLongSidePixels; int32 targetShortSidePixels; int32 targetHorizontalExtentPixels; int32 targetVerticalExtentPixels; "
774struct wpi::Struct<valor::cameras::Limelight::CornerCoordinates> {
775 static constexpr std::string_view GetTypeName() {
return "LimelightCornerCoordinates"; }
779 static constexpr std::string_view GetSchema() {
return "double x0; double y0; double x1; double y1"; }
786struct wpi::Struct<valor::cameras::Limelight::IMUData> {
787 static constexpr std::string_view GetTypeName() {
return "LimelightIMUData"; }
789 static constexpr size_t GetSize() {
return sizeof(double) * 10; }
791 static constexpr std::string_view GetSchema() {
792 return "double robotYaw; double roll; double pitch; double yaw; double gyroX; double gyroY; double gyroZ; double accelX; double "
793 "accelY; double accelZ";
801struct wpi::Struct<valor::cameras::Limelight::RawTarget> {
802 static constexpr std::string_view GetTypeName() {
return "LimelightRawTarget"; }
804 static constexpr size_t GetSize() {
return sizeof(double) * 3; }
806 static constexpr std::string_view GetSchema() {
return "double txnc; double tync; double ta"; }
813struct wpi::Struct<valor::cameras::Limelight::RawFiducial> {
814 static constexpr std::string_view GetTypeName() {
return "LimelightRawFiducial"; }
816 static constexpr size_t GetSize() {
return sizeof(int) +
sizeof(
double) * 6; }
818 static constexpr std::string_view GetSchema() {
819 return "int32 id; double txnc; double tync; double ta; double distToCamera; double distToRobot; double ambiguity";
827struct wpi::Struct<valor::cameras::Limelight::RawDetection> {
828 static constexpr std::string_view GetTypeName() {
return "LimelightRawDetection"; }
830 static constexpr size_t GetSize() {
return sizeof(int) +
sizeof(
double) * 11; }
832 static constexpr std::string_view GetSchema() {
833 return "int32 classId; double txnc; double tync; double ta; double corner0_X; double corner0_Y; double corner1_X; double "
834 "corner1_Y; double corner2_X; double corner2_Y; double corner3_X; double corner3_Y";
Loggable(std::string_view name)
Construct a Loggable that registers a top-level table name.
int GetCurrentPipelineIndex() const
Definition Limelight.h:362
void SetRobotOrientation(units::degree_t yaw, units::degrees_per_second_t yawRate, units::degree_t pitch, units::degrees_per_second_t pitchRate, units::degree_t roll, units::degrees_per_second_t rollRate, bool flush=true)
void SetRewindEnabled(bool enabled)
Definition Limelight.h:625
void SetKeystone(double horizontal, double vertical)
Definition Limelight.h:539
frc::Pose3d GetCameraPoseRobotSpace() const
Definition Limelight.h:418
units::millisecond_t GetLatencyCapture() const
Definition Limelight.h:355
std::vector< RawDetection > GetRawDetections() const
TargetMetrics GetTargetMetrics() const
void SetIMUMode(IMUMode mode)
Definition Limelight.h:548
std::string GetJSONDump() const
Definition Limelight.h:376
frc::Pose3d GetCameraPoseTargetSpace() const
Definition Limelight.h:411
frc::Pose3d GetBotPoseWpiBlue() const
Definition Limelight.h:397
PoseEstimate GetBotPoseEstimateWpiBlue(bool mt2) const
int GetClassifierClassIndex() const
Definition Limelight.h:320
std::vector< RawFiducial > GetRawFiducials() const
std::vector< std::string > GetRawBarcodeData() const
Definition Limelight.h:460
units::degree_t GetTY() const
Definition Limelight.h:275
std::string GetNeuralClassID() const
Definition Limelight.h:453
void SetLEDMode(LEDMode mode)
frc::Color GetTargetColor() const
void SetPythonScriptData(const std::vector< double > &outgoingData)
Definition Limelight.h:605
static constexpr std::pair< units::degree_t, units::degree_t > GetFOV(Model model)
Definition Limelight.h:730
PoseEstimate GetBotPoseEstimateWpiRed(bool mt2) const
Limelight(std::string_view name)
Definition Limelight.h:254
int GetTargetCount() const
Definition Limelight.h:313
frc::Pose3d GetBotPose() const
Definition Limelight.h:383
std::optional< int > GetFiducialID() const
units::degree_t GetTYNC() const
Definition Limelight.h:291
void LoggablePeriodic() override
Periodic callback for logging updates.
frc::Pose3d GetTargetPoseRobotSpace() const
Definition Limelight.h:432
units::degree_t GetTX() const
Definition Limelight.h:268
std::string GetClassifierClass() const
Definition Limelight.h:334
Model
Model of the physical Limelight.
Definition Limelight.h:21
@ One
Limelight 1.
Definition Limelight.h:23
@ Four
Limelight 4.
Definition Limelight.h:35
@ Two
Limelight 2.
Definition Limelight.h:25
@ Three
Limelight 3.
Definition Limelight.h:29
@ ThreeA
Limelight 3A.
Definition Limelight.h:31
@ ThreeG
Limelight 3G.
Definition Limelight.h:33
@ TwoPlus
Limelight 2+.
Definition Limelight.h:27
bool GetTV() const
Definition Limelight.h:261
std::string GetDetectorClass() const
Definition Limelight.h:341
IMUData GetIMUData() const
Definition Limelight.h:685
void TriggerRewindCapture(units::second_t duration)
Definition Limelight.h:633
std::vector< CornerCoordinates > GetCornerCoordinates() const
void SetThrottle(int throttle)
Definition Limelight.h:563
void SetFiducial3DOffset(const frc::Translation3d &offset)
void SetPipelineIndex(int index)
Definition Limelight.h:484
void SetCameraPoseRobotSpace(const frc::Pose3d &pose)
StreamMode
Limelight streaming mode.
Definition Limelight.h:79
@ PiPSecondary
The primary camera stream is placed in the lower-right corner of the secondary camera stream.
Definition Limelight.h:85
@ PiPMain
The secondary camera stream is placed in the lower-right corner of the primary camera stream.
Definition Limelight.h:83
@ Standard
Side-by-side streams if a webcam is attached to the Limelight.
Definition Limelight.h:81
LEDMode
LED mode of the Limelight.
Definition Limelight.h:57
@ ForceOnRight
Force on (right LEDs only).
Definition Limelight.h:69
@ ForceOff
Force off the LEDs.
Definition Limelight.h:61
@ ForceBlinkRight
Force blink (right LEDs only).
Definition Limelight.h:75
@ ForceBlink
Force blink the LEDs.
Definition Limelight.h:63
@ ForceOn
Force on the LEDs.
Definition Limelight.h:65
@ ForceOnLeft
Force on (left LEDs only).
Definition Limelight.h:67
@ ForceBlinkLeft
Force blink (left LEDs only).
Definition Limelight.h:73
@ BounceHalves
Bounce the halves of the LEDs.
Definition Limelight.h:71
@ PipelineControl
Use the LED mode set in the current pipeline.
Definition Limelight.h:59
std::string GetCurrentPipelineType() const
Definition Limelight.h:369
frc::Pose3d GetBotPoseTargetSpace() const
Definition Limelight.h:404
frc::Pose3d GetTargetPoseCameraSpace() const
Definition Limelight.h:425
double GetTA() const
Definition Limelight.h:298
void SetPriorityTagID(int ID)
Definition Limelight.h:491
void SetStreamMode(StreamMode mode)
int GetHeartbeat() const
Definition Limelight.h:468
void SetCropWindow(double xMin, double xMax, double yMin, double yMax)
units::millisecond_t GetLatencyPipeline() const
Definition Limelight.h:348
units::degree_t GetTXNC() const
Definition Limelight.h:283
void TriggerSnapshot()
Definition Limelight.h:618
std::vector< double > GetPythonScriptData() const
Definition Limelight.h:612
void SetIMUAssistAlpha(double alpha)
Definition Limelight.h:556
void SetFiducialIDFiltersOverride(std::vector< int > validIDs)
Definition Limelight.h:581
std::vector< RawTarget > GetRawTargets() const
LimelightHelpers::LimelightResultsClass GetLatestResults(bool profile=false) const
int GetDetectorClassIndex() const
Definition Limelight.h:327
frc::Pose3d GetBotPoseWpiRed() const
Definition Limelight.h:390
IMUMode
Definition Limelight.h:43
@ InternalMT1Assist
Use the internal IMU with MT1 assisted convergence.
Definition Limelight.h:51
@ ExternalOnly
Use the external IMU (robot yaw) only.
Definition Limelight.h:45
@ ExternalSeed
Use the external IMU (robot yaw) and seed the internal IMU.
Definition Limelight.h:47
@ InternalExternalAssist
Use the internal IMU with external IMU assisted convergence.
Definition Limelight.h:53
@ InternalOnly
Use the internal IMU only.
Definition Limelight.h:49
static void SetupPortForwardingUSB(int usbIndex)
Definition Limelight.h:721
void SetFiducialDownscalingOverride(float downscale)
Definition Limelight.h:590
void SetupPortForwarding()
Definition Limelight.h:692
Structure representing coordinates of a target.
Definition Limelight.h:127
double y0
Top left corner Y in pixels.
Definition Limelight.h:131
double x1
Bottom right corner X in pixels.
Definition Limelight.h:133
double y1
Bottom right corner Y in pixels.
Definition Limelight.h:135
double x0
Top left corner X in pixels.
Definition Limelight.h:129
IMU data of the Limelight.
Definition Limelight.h:139
units::degree_t robotYaw
Robot yaw.
Definition Limelight.h:141
units::degrees_per_second_squared_t accelX
Roll acceleration of the IMU.
Definition Limelight.h:155
units::degrees_per_second_t gyroX
Roll velocity of the IMU.
Definition Limelight.h:149
units::degrees_per_second_squared_t accelY
Pitch acceleration of the IMU.
Definition Limelight.h:157
units::degree_t pitch
Pitch of the IMU.
Definition Limelight.h:145
units::degree_t roll
Roll of the IMU.
Definition Limelight.h:143
units::degrees_per_second_t gyroZ
Yaw velocity of the IMU.
Definition Limelight.h:153
units::degrees_per_second_squared_t accelZ
Yaw acceleration of the IMU.
Definition Limelight.h:159
units::degree_t yaw
Yaw of the IMU.
Definition Limelight.h:147
units::degrees_per_second_t gyroY
Pitch velocity of the IMU.
Definition Limelight.h:151
Pose Estimate of the Limelight.
Definition Limelight.h:223
std::vector< RawFiducial > rawFiducials
Array of the raw fiducials.
Definition Limelight.h:233
units::second_t timestamp
Timestamp of the measurement (NT time base).
Definition Limelight.h:225
units::millisecond_t latency
Latency of the measurement.
Definition Limelight.h:227
units::meter_t avgTagDist
Average tag distance from camera.
Definition Limelight.h:231
units::meter_t tagSpan
Average tag width.
Definition Limelight.h:229
Raw detection result of the Limelight.
Definition Limelight.h:210
units::degree_t tync
Vertical offset from principal pixel to target.
Definition Limelight.h:214
units::degree_t txnc
Horizontal offset from principal pixel to target.
Definition Limelight.h:212
Raw fiducial result of the Limelight.
Definition Limelight.h:189
units::degree_t tync
Vertical offset from principal pixel to target.
Definition Limelight.h:193
units::meter_t distToRobot
Distance from target to robot.
Definition Limelight.h:197
units::meter_t distToCamera
Distance from target to camera.
Definition Limelight.h:195
units::degree_t txnc
Horizontal offset principal pixel to target.
Definition Limelight.h:191
Raw target result of the Limelight.
Definition Limelight.h:177
units::degree_t txnc
Horizontal offset from principal pixel to target.
Definition Limelight.h:179
units::degree_t tync
Vertical offset from principal pixel to target.
Definition Limelight.h:181
Targeting metrics of the Limelight.
Definition Limelight.h:89
int targetHorizontalExtentPixels
Number of pixels horizontally of the target.
Definition Limelight.h:119
int targetCount
How many targets are being detected.
Definition Limelight.h:93
int targetVerticalExtentPixels
Number of pixels vertically of the tagret.
Definition Limelight.h:121
units::degree_t tx
Horizontal offset from crosshair to target.
Definition Limelight.h:99
double ta
Target area of image (0% to 100%).
Definition Limelight.h:107
units::degree_t tync
Vertical offset from principle pixel to target.
Definition Limelight.h:105
int targetLongSidePixels
Number of pixels on the target long side.
Definition Limelight.h:115
units::degree_t ty
Vertical offset from crosshair to target.
Definition Limelight.h:101
int targetClassIndexClassifier
Target class index classifier.
Definition Limelight.h:113
int targetShortSidePixels
Number of pixels on the target short side.
Definition Limelight.h:117
units::millisecond_t targetLatency
The pipeline latency.
Definition Limelight.h:95
bool targetValid
Whether the target is valid or not.
Definition Limelight.h:91
int targetClassIndexDetector
Target class index detector.
Definition Limelight.h:111
int tid
ID of the primary in-view AprilTag.
Definition Limelight.h:109
units::degree_t txnc
Horizontal offset from principle pixel to target.
Definition Limelight.h:103
units::degree_t targetSkew
Skew of the target.
Definition Limelight.h:123
units::millisecond_t captureLatency
The capture latency.
Definition Limelight.h:97