CTRE Phoenix 6 C++ 26.70.0-alpha-2
Loading...
Searching...
No Matches
CANcoder.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 CANcoder, a CAN based magnetic encoder that provides absolute and
25 * relative position along with filtered velocity.
26 */
27class CANcoder : public core::CoreCANcoder, 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::turn_t> m_position = GetPosition(false);
37
38 wpi::hal::SimDevice m_simCANcoder;
39 wpi::hal::SimDouble m_simSupplyVoltage;
40 wpi::hal::SimDouble m_simPosition;
41 wpi::hal::SimDouble m_simRawPosition;
42 wpi::hal::SimDouble m_simVelocity;
43
44 int32_t m_simPeriodicUid{-1};
45 std::vector<int32_t> m_simValueChangedUids;
46
47 static void OnValueChanged(
48 const char *name, void *param, HAL_SimValueHandle handle,
49 HAL_Bool readonly, const struct HAL_Value *value
50 );
51 static void OnPeriodic(void *param);
52
53public:
54 /**
55 * Constructs a new CANcoder object.
56 *
57 * \param deviceId ID of the device, as configured in Phoenix Tuner
58 * \param canbus The CAN bus this device is on
59 */
60 CANcoder(int deviceId, CANBus canbus);
61
63
64 /**
65 * \brief Constructs a stubbed-out CANcoder, where all status signals, controls,
66 * configs, etc. perform no action and immediately return OK. This can be used to
67 * silence error messages for devices that have been completely removed from the robot.
68 *
69 * \returns Stubbed-out CANcoder
70 */
71 static CANcoder None()
72 {
73 return CANcoder{-1, CANBus{}};
74 }
75
76 /**
77 * \brief Logs the object to a wpi::telemetry::TelemetryTable.
78 *
79 * \param table Telemetry table
80 */
81 void LogTo(wpi::telemetry::TelemetryTable &table) const override;
82
83 /**
84 * \brief Gets the telemetry table type.
85 *
86 * \returns Table type
87 */
88 std::string_view GetTelemetryType() const override { return "CANcoder"; }
89};
90
91#if defined(_WIN32) || defined(_WIN64)
92#pragma warning(pop)
93#endif
94
95}
96}
97}
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
void LogTo(wpi::telemetry::TelemetryTable &table) const override
Logs the object to a wpi::telemetry::TelemetryTable.
std::string_view GetTelemetryType() const override
Gets the telemetry table type.
Definition CANcoder.hpp:88
CANcoder(int deviceId, CANBus canbus)
Constructs a new CANcoder object.
static CANcoder None()
Constructs a stubbed-out CANcoder, where all status signals, controls, configs, etc.
Definition CANcoder.hpp:71
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CoreCANcoder.hpp:595
StatusSignal< wpi::units::turns_per_second_t > & GetVelocity(bool refresh=true)
Velocity of the device.
StatusSignal< wpi::units::turn_t > & GetPosition(bool refresh=true)
Position of the device.
Definition ExternalFeedbackConfigs.hpp:17
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14