CTRE Phoenix 6 C++ 26.70.0-alpha-2
Loading...
Searching...
No Matches
CANrange.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
10
11#include <wpi/hal/SimDevice.hpp>
12#include <wpi/telemetry/TelemetryLoggable.hpp>
13
14namespace ctre {
15namespace phoenix6 {
16namespace hardware {
17
18#if defined(_WIN32) || defined(_WIN64)
19#pragma warning(push)
20#pragma warning(disable : 4250)
21#endif
22
23/**
24 * Class for CANrange, a CAN based Time of Flight (ToF) sensor that measures the
25 * distance to the front of the device.
26 */
27class CANrange : public core::CoreCANrange, public wpi::telemetry::TelemetryLoggable {
28 /*
29 * The StatusSignal getters are copies so that calls
30 * to the WPI interface do not update any references
31 *
32 * These are also mutable so the const getter methods are
33 * properly managed.
34 */
35 mutable StatusSignal<wpi::units::meter_t> m_distance = GetDistance(false);
36 mutable StatusSignal<bool> m_isDetected = GetIsDetected(false);
37
38 wpi::hal::SimDevice m_simCANrange;
39 wpi::hal::SimDouble m_simSupplyVoltage;
40 wpi::hal::SimDouble m_simDistance;
41 wpi::hal::SimBoolean m_simIsDetected;
42
43 int32_t m_simPeriodicUid{-1};
44 std::vector<int32_t> m_simValueChangedUids;
45
46 static void OnValueChanged(
47 const char *name, void *param, HAL_SimValueHandle handle,
48 HAL_Bool readonly, const struct HAL_Value *value
49 );
50 static void OnPeriodic(void *param);
51
52public:
53 /**
54 * Constructs a new CANrange object.
55 *
56 * \param deviceId ID of the device, as configured in Phoenix Tuner
57 * \param canbus The CAN bus this device is on
58 */
59 CANrange(int deviceId, CANBus canbus);
60
62
63 /**
64 * \brief Constructs a stubbed-out CANrange, where all status signals, controls,
65 * configs, etc. perform no action and immediately return OK. This can be used to
66 * silence error messages for devices that have been completely removed from the robot.
67 *
68 * \returns Stubbed-out CANrange
69 */
70 static CANrange None()
71 {
72 return CANrange{-1, CANBus{}};
73 }
74
75 /**
76 * \brief Logs the object to a wpi::telemetry::TelemetryTable.
77 *
78 * \param table Telemetry table
79 */
80 void LogTo(wpi::telemetry::TelemetryTable &table) const override;
81
82 /**
83 * \brief Gets the telemetry table type.
84 *
85 * \returns Table type
86 */
87 std::string_view GetTelemetryType() const override { return "CANrange"; }
88};
89
90#if defined(_WIN32) || defined(_WIN64)
91#pragma warning(pop)
92#endif
93
94}
95}
96}
Class for getting information about an available CAN bus.
Definition CANBus.hpp:142
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:523
std::string_view GetTelemetryType() const override
Gets the telemetry table type.
Definition CANrange.hpp:87
CANrange(int deviceId, CANBus canbus)
Constructs a new CANrange object.
void LogTo(wpi::telemetry::TelemetryTable &table) const override
Logs the object to a wpi::telemetry::TelemetryTable.
static CANrange None()
Constructs a stubbed-out CANrange, where all status signals, controls, configs, etc.
Definition CANrange.hpp:70
Class for CANrange, a CAN based Time of Flight (ToF) sensor that measures the distance to the front o...
Definition CoreCANrange.hpp:728
StatusSignal< wpi::units::meter_t > & GetDistance(bool refresh=true)
Distance to the nearest object in the configured field of view of the CANrange.
StatusSignal< bool > & GetIsDetected(bool refresh=true)
Whether the CANrange detects an object using the configured proximity parameters.
Definition ExternalFeedbackConfigs.hpp:17
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14