CTRE Phoenix 6 C++ 26.50.0-alpha-1
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
13namespace ctre {
14namespace phoenix6 {
15namespace hardware {
16
17#if defined(_WIN32) || defined(_WIN64)
18#pragma warning(push)
19#pragma warning(disable : 4250)
20#endif
21
22/**
23 * Class for CANcoder, a CAN based magnetic encoder that provides absolute and
24 * relative position along with filtered velocity.
25 */
27 /*
28 * The StatusSignal getters are copies so that calls
29 * to the WPI interface do not update any references
30 *
31 * These are also mutable so the const getter methods are
32 * properly managed.
33 */
34 mutable StatusSignal<wpi::units::turn_t> m_positionGetter = GetPosition(false);
35
36 wpi::hal::SimDevice m_simCANcoder;
37 wpi::hal::SimDouble m_simSupplyVoltage;
38 wpi::hal::SimDouble m_simPosition;
39 wpi::hal::SimDouble m_simRawPosition;
40 wpi::hal::SimDouble m_simVelocity;
41
42 int32_t m_simPeriodicUid{-1};
43 std::vector<int32_t> m_simValueChangedUids;
44
45 static void OnValueChanged(
46 const char *name, void *param, HAL_SimValueHandle handle,
47 HAL_Bool readonly, const struct HAL_Value *value
48 );
49 static void OnPeriodic(void *param);
50
51public:
52 /**
53 * Constructs a new CANcoder object.
54 *
55 * \param deviceId ID of the device, as configured in Phoenix Tuner
56 * \param canbus The CAN bus this device is on
57 */
58 CANcoder(int deviceId, CANBus canbus);
59
61
62 /**
63 * \brief Constructs a stubbed-out CANcoder, where all status signals, controls,
64 * configs, etc. perform no action and immediately return OK. This can be used to
65 * silence error messages for devices that have been completely removed from the robot.
66 *
67 * \returns Stubbed-out CANcoder
68 */
69 static CANcoder None()
70 {
71 return CANcoder{-1, CANBus{}};
72 }
73};
74
75#if defined(_WIN32) || defined(_WIN64)
76#pragma warning(pop)
77#endif
78
79}
80}
81}
Class for getting information about an available CAN bus.
Definition CANBus.hpp:19
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:563
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:69
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CoreCANcoder.hpp:601
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