FRC Paradigm Shift #1259
Documentation for the 2021 Robot
VisionSubsystem Class Reference
Inheritance diagram for VisionSubsystem:

Public Member Functions

 VisionSubsystem ()
 
void Periodic () override
 Will be called periodically whenever the CommandScheduler runs. More...
 
bool GetValidTarget ()
 
double GetDistance ()
 Retrieves the distance calculation from the target via the limelight. More...
 
double GetAngle ()
 
void SetLED (bool on)
 

Protected Member Functions

double DegreesToRadians (double degrees)
 

Private Attributes

shared_ptr< NetworkTable > m_dashboard
 
shared_ptr< NetworkTable > m_networktable
 
bool m_led
 
double m_tx
 
double m_ty
 
bool m_validTarget
 
vector< double > m_averageDistance
 
vector< double > m_averageAngle
 

Detailed Description

Definition at line 19 of file VisionSubsystem.h.

Constructor & Destructor Documentation

VisionSubsystem::VisionSubsystem ( )

Definition at line 5 of file VisionSubsystem.cpp.

References m_averageAngle, m_averageDistance, and SetLED().

6  : m_dashboard (nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard"))
7  , m_networktable(nt::NetworkTableInstance::GetDefault().GetTable("limelight"))
8  , m_led(true)
9  , m_tx(0)
10  , m_ty(0)
11  , m_validTarget(false)
12 {
13  SetLED(true);
14  m_averageDistance.reserve(3);
15  m_averageAngle.reserve(3);
16 }
vector< double > m_averageAngle
void SetLED(bool on)
shared_ptr< NetworkTable > m_networktable
shared_ptr< NetworkTable > m_dashboard
vector< double > m_averageDistance

Member Function Documentation

void VisionSubsystem::Periodic ( )
override

Will be called periodically whenever the CommandScheduler runs.

Definition at line 18 of file VisionSubsystem.cpp.

References Util::DegreesToRadians(), GetAngle(), GetDistance(), VisionConstants::kMaxTargetDistance, VisionConstants::kMinTargetDistance, VisionConstants::kMountingAngle, VisionConstants::kMountingHeight, VisionConstants::kTargetHeight, m_averageAngle, m_averageDistance, m_led, m_networktable, m_tx, m_ty, and m_validTarget.

19 {
20  m_validTarget = m_networktable->GetNumber("tv", 0);
21 
22  if (!m_led)
23  m_validTarget = false;
24 
25  m_tx = m_networktable->GetNumber("tx", 0.0);
26  m_ty = m_networktable->GetNumber("ty", 0.0);
27 
28  double verticalAngle = kMountingAngle + m_ty;
29  double horizontalAngle = m_tx; // in degrees
30 
31  double distance = (kTargetHeight - kMountingHeight) / tanf(Util::DegreesToRadians(verticalAngle));
32 
33  if ((distance < kMinTargetDistance) || (distance > kMaxTargetDistance))
34  m_validTarget = false;
35 
36  if (!m_validTarget)
37  {
38  m_averageDistance.clear();
39  m_averageAngle.clear();
40  return;
41  }
42 
43  m_averageDistance.push_back(distance);
44  m_averageAngle.push_back(horizontalAngle);
45 
46  if (m_averageDistance.size() > 3)
47  m_averageDistance.erase(m_averageDistance.begin());
48 
49  if (m_averageAngle.size() > 3)
50  m_averageAngle.erase(m_averageAngle.begin());
51 
52  SmartDashboard::PutNumber("D_V_Active", m_validTarget);
53  SmartDashboard::PutNumber("D_V_Distance", distance);
54  // SmartDashboard::PutNumber("D_V_Angle", m_horizontalangle);
55  SmartDashboard::PutNumber("D_V_Average Distance", GetDistance());
56  SmartDashboard::PutNumber("D_V_Average Angle", GetAngle());
57 }
double GetDistance()
Retrieves the distance calculation from the target via the limelight.
constexpr double kMinTargetDistance
Definition: Constants.h:208
constexpr double kMountingAngle
Definition: Constants.h:200
vector< double > m_averageAngle
constexpr double kMaxTargetDistance
Definition: Constants.h:209
shared_ptr< NetworkTable > m_networktable
static double DegreesToRadians(double theta)
Convert any angle theta in degrees to radians.
Definition: Util.cpp:4
constexpr double kTargetHeight
Definition: Constants.h:206
constexpr double kMountingHeight
Definition: Constants.h:203
vector< double > m_averageDistance
bool VisionSubsystem::GetValidTarget ( )

Determine valid vision based on returned distance values

Returns
Whether or not the Vision Subsystem is giving accurate values

Definition at line 59 of file VisionSubsystem.cpp.

References m_validTarget.

60 {
61  return m_validTarget;
62 }
double VisionSubsystem::GetDistance ( )

Retrieves the distance calculation from the target via the limelight.

Definition at line 64 of file VisionSubsystem.cpp.

References Util::GetAverage(), and m_averageDistance.

65 {
67 }
static double GetAverage(vector< double > numbers)
Definition: Util.cpp:46
vector< double > m_averageDistance
double VisionSubsystem::GetAngle ( )
Returns
The angle calculation from the target via the limelight

Definition at line 70 of file VisionSubsystem.cpp.

References Util::GetAverage(), and m_averageAngle.

71 {
73 }
vector< double > m_averageAngle
static double GetAverage(vector< double > numbers)
Definition: Util.cpp:46
void VisionSubsystem::SetLED ( bool  on)

Turns the limelight LED on or off

Parameters
onBoolean where true = LED on

3 forces limelight led on

1 forces limelight led off

Definition at line 75 of file VisionSubsystem.cpp.

References m_led, and m_networktable.

76 {
77  m_led = on;
78  if (m_led)
79  {
81  m_networktable->PutNumber("ledMode", 3);
82  }
83  else
84  {
86  m_networktable->PutNumber("ledMode", 1);
87  }
88 }
shared_ptr< NetworkTable > m_networktable
double VisionSubsystem::DegreesToRadians ( double  degrees)
protected

Converts degrees to radians

Parameters
degreesDegrees to convert

Member Data Documentation

shared_ptr<NetworkTable> VisionSubsystem::m_dashboard
private

Definition at line 44 of file VisionSubsystem.h.

shared_ptr<NetworkTable> VisionSubsystem::m_networktable
private

Definition at line 45 of file VisionSubsystem.h.

bool VisionSubsystem::m_led
private

Definition at line 46 of file VisionSubsystem.h.

double VisionSubsystem::m_tx
private

Definition at line 48 of file VisionSubsystem.h.

double VisionSubsystem::m_ty
private

Definition at line 49 of file VisionSubsystem.h.

bool VisionSubsystem::m_validTarget
private

Definition at line 50 of file VisionSubsystem.h.

vector<double> VisionSubsystem::m_averageDistance
private

Definition at line 51 of file VisionSubsystem.h.

vector<double> VisionSubsystem::m_averageAngle
private

Definition at line 52 of file VisionSubsystem.h.


The documentation for this class was generated from the following files: