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 <valkyrie/Loggable.h>
11#include <wpi/struct/Struct.h>
154 units::degrees_per_second_squared_t
accelX;
156 units::degrees_per_second_squared_t
accelY;
158 units::degrees_per_second_squared_t
accelZ;
160 constexpr IMUData(LimelightHelpers::IMUData data)
176 struct RawTarget : LimelightHelpers::RawTarget {
182 constexpr RawTarget(LimelightHelpers::RawTarget data) : LimelightHelpers::RawTarget{data},
txnc{data.
txnc},
tync{data.
tync} {}
188 struct RawFiducial : LimelightHelpers::RawFiducial {
198 constexpr RawFiducial(LimelightHelpers::RawFiducial data)
199 : LimelightHelpers::RawFiducial{data},
209 struct RawDetection : LimelightHelpers::RawDetection {
215 constexpr RawDetection(LimelightHelpers::RawDetection data)
222 struct PoseEstimate : LimelightHelpers::PoseEstimate {
234 constexpr PoseEstimate(LimelightHelpers::PoseEstimate data)
235 : LimelightHelpers::PoseEstimate{data},
242 constexpr bool IsValid()
const {
return !
rawFiducials.empty(); }
245 using LimelightHelpers::PoseEstimate::timestampSeconds;
253 inline explicit Limelight(std::string_view name) : name{name} {}
260 inline bool GetTV()
const {
return LimelightHelpers::getTV(name); }
267 inline units::degree_t
GetTX()
const {
return units::degree_t{LimelightHelpers::getTX(name)}; }
274 inline units::degree_t
GetTY()
const {
return units::degree_t{LimelightHelpers::getTY(name)}; }
282 inline units::degree_t
GetTXNC()
const {
return units::degree_t{LimelightHelpers::getTXNC(name)}; }
290 inline units::degree_t
GetTYNC()
const {
return units::degree_t{LimelightHelpers::getTYNC(name)}; }
297 inline double GetTA()
const {
return LimelightHelpers::getTA(name); }
312 inline int GetTargetCount()
const {
return LimelightHelpers::getTargetCount(name); };
340 inline std::string
GetDetectorClass()
const {
return LimelightHelpers::getDetectorClass(name); }
347 inline units::millisecond_t
GetLatencyPipeline()
const {
return units::millisecond_t{LimelightHelpers::getLatency_Pipeline(name)}; }
354 inline units::millisecond_t
GetLatencyCapture()
const {
return units::millisecond_t{LimelightHelpers::getLatency_Capture(name)}; }
375 inline std::string
GetJSONDump()
const {
return LimelightHelpers::getJSONDump(name); }
382 inline frc::Pose3d
GetBotPose()
const {
return LimelightHelpers::getBotPose3d(name); }
389 inline frc::Pose3d
GetBotPoseWpiRed()
const {
return LimelightHelpers::getBotPose3d_wpiRed(name); }
396 inline frc::Pose3d
GetBotPoseWpiBlue()
const {
return LimelightHelpers::getBotPose3d_wpiBlue(name); }
452 inline std::string
GetNeuralClassID()
const {
return LimelightHelpers::getNeuralClassID(name); }
459 inline std::vector<std::string>
GetRawBarcodeData()
const {
return LimelightHelpers::getRawBarcodeData(name); }
467 inline int GetHeartbeat()
const {
return LimelightHelpers::getHeartbeat(name); }
483 inline void SetPipelineIndex(
int index) { LimelightHelpers::setPipelineIndex(name, index); }
529 units::degrees_per_second_t pitchRate, units::degree_t roll, units::degrees_per_second_t rollRate,
538 inline void SetKeystone(
double horizontal,
double vertical) { LimelightHelpers::setKeystone(name, horizontal, vertical); }
547 inline void SetIMUMode(
IMUMode mode) { LimelightHelpers::SetIMUMode(name,
static_cast<int>(mode)); }
555 inline void SetIMUAssistAlpha(
double alpha) { LimelightHelpers::SetIMUAssistAlpha(name, alpha); }
562 inline void SetThrottle(
int throttle) { LimelightHelpers::SetThrottle(name, throttle); }
604 inline void SetPythonScriptData(
const std::vector<double>& outgoingData) { LimelightHelpers::setPythonScriptData(name, outgoingData); }
611 inline std::vector<double>
GetPythonScriptData()
const {
return LimelightHelpers::getPythonScriptData(name); }
624 inline void SetRewindEnabled(
bool enabled) { LimelightHelpers::setRewindEnabled(name, enabled); }
632 inline void TriggerRewindCapture(units::second_t duration) { LimelightHelpers::triggerRewindCapture(name, duration.value()); }
729 static constexpr std::pair<units::degree_t, units::degree_t>
GetFOV(
Model model) {
732 return {54_deg, 41_deg};
735 return {62.5_deg, 48.9_deg};
737 return {62.5_deg, 48.9_deg};
739 return {54.5_deg, 42_deg};
741 return {82_deg, 56.2_deg};
743 return {82_deg, 56.2_deg};
756struct wpi::Struct<valor::cameras::Limelight::TargetMetrics> {
757 static constexpr std::string_view GetTypeName() {
return "LimelightTargetMetrics"; }
759 static constexpr size_t GetSize() {
return 97; }
761 static constexpr std::string_view GetSchema() {
762 return "bool targetValid; int32 targetCount; double targetLatency; double captureLatency; double tx; double ty; double txnc; "
763 "double tync; double ta; int32 tid; int32 targetClassIndexDetector; int32 targetClassIndexClassifier; int32 "
764 "targetLongSidePixels; int32 targetShortSidePixels; int32 targetHorizontalExtentPixels; int32 targetVerticalExtentPixels; "
773struct wpi::Struct<valor::cameras::Limelight::CornerCoordinates> {
774 static constexpr std::string_view GetTypeName() {
return "LimelightCornerCoordinates"; }
778 static constexpr std::string_view GetSchema() {
return "double x0; double y0; double x1; double y1"; }
785struct wpi::Struct<valor::cameras::Limelight::IMUData> {
786 static constexpr std::string_view GetTypeName() {
return "LimelightIMUData"; }
788 static constexpr size_t GetSize() {
return sizeof(double) * 10; }
790 static constexpr std::string_view GetSchema() {
791 return "double robotYaw; double roll; double pitch; double yaw; double gyroX; double gyroY; double gyroZ; double accelX; double "
792 "accelY; double accelZ";
800struct wpi::Struct<valor::cameras::Limelight::RawTarget> {
801 static constexpr std::string_view GetTypeName() {
return "LimelightRawTarget"; }
803 static constexpr size_t GetSize() {
return sizeof(double) * 3; }
805 static constexpr std::string_view GetSchema() {
return "double txnc; double tync; double ta"; }
812struct wpi::Struct<valor::cameras::Limelight::RawFiducial> {
813 static constexpr std::string_view GetTypeName() {
return "LimelightRawFiducial"; }
815 static constexpr size_t GetSize() {
return sizeof(int) +
sizeof(
double) * 6; }
817 static constexpr std::string_view GetSchema() {
818 return "int32 id; double txnc; double tync; double ta; double distToCamera; double distToRobot; double ambiguity";
826struct wpi::Struct<valor::cameras::Limelight::RawDetection> {
827 static constexpr std::string_view GetTypeName() {
return "LimelightRawDetection"; }
829 static constexpr size_t GetSize() {
return sizeof(int) +
sizeof(
double) * 11; }
831 static constexpr std::string_view GetSchema() {
832 return "int32 classId; double txnc; double tync; double ta; double corner0_X; double corner0_Y; double corner1_X; double "
833 "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:361
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:624
void SetKeystone(double horizontal, double vertical)
Definition Limelight.h:538
frc::Pose3d GetCameraPoseRobotSpace() const
Definition Limelight.h:417
units::millisecond_t GetLatencyCapture() const
Definition Limelight.h:354
std::vector< RawDetection > GetRawDetections() const
TargetMetrics GetTargetMetrics() const
void SetIMUMode(IMUMode mode)
Definition Limelight.h:547
std::string GetJSONDump() const
Definition Limelight.h:375
frc::Pose3d GetCameraPoseTargetSpace() const
Definition Limelight.h:410
frc::Pose3d GetBotPoseWpiBlue() const
Definition Limelight.h:396
PoseEstimate GetBotPoseEstimateWpiBlue(bool mt2) const
int GetClassifierClassIndex() const
Definition Limelight.h:319
std::vector< RawFiducial > GetRawFiducials() const
std::vector< std::string > GetRawBarcodeData() const
Definition Limelight.h:459
units::degree_t GetTY() const
Definition Limelight.h:274
std::string GetNeuralClassID() const
Definition Limelight.h:452
void SetLEDMode(LEDMode mode)
frc::Color GetTargetColor() const
void SetPythonScriptData(const std::vector< double > &outgoingData)
Definition Limelight.h:604
static constexpr std::pair< units::degree_t, units::degree_t > GetFOV(Model model)
Definition Limelight.h:729
PoseEstimate GetBotPoseEstimateWpiRed(bool mt2) const
Limelight(std::string_view name)
Definition Limelight.h:253
int GetTargetCount() const
Definition Limelight.h:312
frc::Pose3d GetBotPose() const
Definition Limelight.h:382
std::optional< int > GetFiducialID() const
units::degree_t GetTYNC() const
Definition Limelight.h:290
void LoggablePeriodic() override
Periodic callback for logging updates.
frc::Pose3d GetTargetPoseRobotSpace() const
Definition Limelight.h:431
units::degree_t GetTX() const
Definition Limelight.h:267
std::string GetClassifierClass() const
Definition Limelight.h:333
Model
Model of the physical Limelight.
Definition Limelight.h:20
@ One
Limelight 1.
Definition Limelight.h:22
@ Four
Limelight 4.
Definition Limelight.h:34
@ Two
Limelight 2.
Definition Limelight.h:24
@ Three
Limelight 3.
Definition Limelight.h:28
@ ThreeA
Limelight 3A.
Definition Limelight.h:30
@ ThreeG
Limelight 3G.
Definition Limelight.h:32
@ TwoPlus
Limelight 2+.
Definition Limelight.h:26
bool GetTV() const
Definition Limelight.h:260
std::string GetDetectorClass() const
Definition Limelight.h:340
IMUData GetIMUData() const
Definition Limelight.h:684
void TriggerRewindCapture(units::second_t duration)
Definition Limelight.h:632
std::vector< CornerCoordinates > GetCornerCoordinates() const
void SetThrottle(int throttle)
Definition Limelight.h:562
void SetFiducial3DOffset(const frc::Translation3d &offset)
void SetPipelineIndex(int index)
Definition Limelight.h:483
void SetCameraPoseRobotSpace(const frc::Pose3d &pose)
StreamMode
Limelight streaming mode.
Definition Limelight.h:78
@ PiPSecondary
The primary camera stream is placed in the lower-right corner of the secondary camera stream.
Definition Limelight.h:84
@ PiPMain
The secondary camera stream is placed in the lower-right corner of the primary camera stream.
Definition Limelight.h:82
@ Standard
Side-by-side streams if a webcam is attached to the Limelight.
Definition Limelight.h:80
LEDMode
LED mode of the Limelight.
Definition Limelight.h:56
@ ForceOnRight
Force on (right LEDs only).
Definition Limelight.h:68
@ ForceOff
Force off the LEDs.
Definition Limelight.h:60
@ ForceBlinkRight
Force blink (right LEDs only).
Definition Limelight.h:74
@ ForceBlink
Force blink the LEDs.
Definition Limelight.h:62
@ ForceOn
Force on the LEDs.
Definition Limelight.h:64
@ ForceOnLeft
Force on (left LEDs only).
Definition Limelight.h:66
@ ForceBlinkLeft
Force blink (left LEDs only).
Definition Limelight.h:72
@ BounceHalves
Bounce the halves of the LEDs.
Definition Limelight.h:70
@ PipelineControl
Use the LED mode set in the current pipeline.
Definition Limelight.h:58
std::string GetCurrentPipelineType() const
Definition Limelight.h:368
frc::Pose3d GetBotPoseTargetSpace() const
Definition Limelight.h:403
frc::Pose3d GetTargetPoseCameraSpace() const
Definition Limelight.h:424
double GetTA() const
Definition Limelight.h:297
void SetPriorityTagID(int ID)
Definition Limelight.h:490
void SetStreamMode(StreamMode mode)
int GetHeartbeat() const
Definition Limelight.h:467
void SetCropWindow(double xMin, double xMax, double yMin, double yMax)
units::millisecond_t GetLatencyPipeline() const
Definition Limelight.h:347
units::degree_t GetTXNC() const
Definition Limelight.h:282
void TriggerSnapshot()
Definition Limelight.h:617
std::vector< double > GetPythonScriptData() const
Definition Limelight.h:611
void SetIMUAssistAlpha(double alpha)
Definition Limelight.h:555
void SetFiducialIDFiltersOverride(std::vector< int > validIDs)
Definition Limelight.h:580
std::vector< RawTarget > GetRawTargets() const
LimelightHelpers::LimelightResultsClass GetLatestResults(bool profile=false) const
int GetDetectorClassIndex() const
Definition Limelight.h:326
frc::Pose3d GetBotPoseWpiRed() const
Definition Limelight.h:389
IMUMode
Definition Limelight.h:42
@ InternalMT1Assist
Use the internal IMU with MT1 assisted convergence.
Definition Limelight.h:50
@ ExternalOnly
Use the external IMU (robot yaw) only.
Definition Limelight.h:44
@ ExternalSeed
Use the external IMU (robot yaw) and seed the internal IMU.
Definition Limelight.h:46
@ InternalExternalAssist
Use the internal IMU with external IMU assisted convergence.
Definition Limelight.h:52
@ InternalOnly
Use the internal IMU only.
Definition Limelight.h:48
static void SetupPortForwardingUSB(int usbIndex)
Definition Limelight.h:720
void SetFiducialDownscalingOverride(float downscale)
Definition Limelight.h:589
void SetupPortForwarding()
Definition Limelight.h:691
Structure representing coordinates of a target.
Definition Limelight.h:126
double y0
Top left corner Y in pixels.
Definition Limelight.h:130
double x1
Bottom right corner X in pixels.
Definition Limelight.h:132
double y1
Bottom right corner Y in pixels.
Definition Limelight.h:134
double x0
Top left corner X in pixels.
Definition Limelight.h:128
IMU data of the Limelight.
Definition Limelight.h:138
units::degree_t robotYaw
Robot yaw.
Definition Limelight.h:140
units::degrees_per_second_squared_t accelX
Roll acceleration of the IMU.
Definition Limelight.h:154
units::degrees_per_second_t gyroX
Roll velocity of the IMU.
Definition Limelight.h:148
units::degrees_per_second_squared_t accelY
Pitch acceleration of the IMU.
Definition Limelight.h:156
units::degree_t pitch
Pitch of the IMU.
Definition Limelight.h:144
units::degree_t roll
Roll of the IMU.
Definition Limelight.h:142
units::degrees_per_second_t gyroZ
Yaw velocity of the IMU.
Definition Limelight.h:152
units::degrees_per_second_squared_t accelZ
Yaw acceleration of the IMU.
Definition Limelight.h:158
units::degree_t yaw
Yaw of the IMU.
Definition Limelight.h:146
units::degrees_per_second_t gyroY
Pitch velocity of the IMU.
Definition Limelight.h:150
Pose Estimate of the Limelight.
Definition Limelight.h:222
std::vector< RawFiducial > rawFiducials
Array of the raw fiducials.
Definition Limelight.h:232
units::second_t timestamp
Timestamp of the measurement (NT time base).
Definition Limelight.h:224
units::millisecond_t latency
Latency of the measurement.
Definition Limelight.h:226
units::meter_t avgTagDist
Average tag distance from camera.
Definition Limelight.h:230
units::meter_t tagSpan
Average tag width.
Definition Limelight.h:228
Raw detection result of the Limelight.
Definition Limelight.h:209
units::degree_t tync
Vertical offset from principal pixel to target.
Definition Limelight.h:213
units::degree_t txnc
Horizontal offset from principal pixel to target.
Definition Limelight.h:211
Raw fiducial result of the Limelight.
Definition Limelight.h:188
units::degree_t tync
Vertical offset from principal pixel to target.
Definition Limelight.h:192
units::meter_t distToRobot
Distance from target to robot.
Definition Limelight.h:196
units::meter_t distToCamera
Distance from target to camera.
Definition Limelight.h:194
units::degree_t txnc
Horizontal offset principal pixel to target.
Definition Limelight.h:190
Raw target result of the Limelight.
Definition Limelight.h:176
units::degree_t txnc
Horizontal offset from principal pixel to target.
Definition Limelight.h:178
units::degree_t tync
Vertical offset from principal pixel to target.
Definition Limelight.h:180
Targeting metrics of the Limelight.
Definition Limelight.h:88
int targetHorizontalExtentPixels
Number of pixels horizontally of the target.
Definition Limelight.h:118
int targetCount
How many targets are being detected.
Definition Limelight.h:92
int targetVerticalExtentPixels
Number of pixels vertically of the tagret.
Definition Limelight.h:120
units::degree_t tx
Horizontal offset from crosshair to target.
Definition Limelight.h:98
double ta
Target area of image (0% to 100%).
Definition Limelight.h:106
units::degree_t tync
Vertical offset from principle pixel to target.
Definition Limelight.h:104
int targetLongSidePixels
Number of pixels on the target long side.
Definition Limelight.h:114
units::degree_t ty
Vertical offset from crosshair to target.
Definition Limelight.h:100
int targetClassIndexClassifier
Target class index classifier.
Definition Limelight.h:112
int targetShortSidePixels
Number of pixels on the target short side.
Definition Limelight.h:116
units::millisecond_t targetLatency
The pipeline latency.
Definition Limelight.h:94
bool targetValid
Whether the target is valid or not.
Definition Limelight.h:90
int targetClassIndexDetector
Target class index detector.
Definition Limelight.h:110
int tid
ID of the primary in-view AprilTag.
Definition Limelight.h:108
units::degree_t txnc
Horizontal offset from principle pixel to target.
Definition Limelight.h:102
units::degree_t targetSkew
Skew of the target.
Definition Limelight.h:122
units::millisecond_t captureLatency
The capture latency.
Definition Limelight.h:96