CTRE Phoenix 6 C++ 26.0.0-beta-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/sendable/Sendable.h"
12#include "wpi/sendable/SendableBuilder.h"
13#include "wpi/sendable/SendableHelper.h"
14#include <hal/SimDevice.h>
15
16namespace ctre {
17namespace phoenix6 {
18namespace hardware {
19
20#if defined(_WIN32) || defined(_WIN64)
21#pragma warning(push)
22#pragma warning(disable : 4250)
23#endif
24
25/**
26 * Class for CANcoder, a CAN based magnetic encoder that provides absolute and
27 * relative position along with filtered velocity.
28 */
30 public wpi::Sendable,
31 public wpi::SendableHelper<CANcoder>
32{
33 /*
34 * The StatusSignal getters are copies so that calls
35 * to the WPI interface do not update any references
36 *
37 * These are also mutable so the const getter methods are
38 * properly managed.
39 */
40 mutable StatusSignal<units::angle::turn_t> m_positionGetter = GetPosition(false);
41
42 hal::SimDevice m_simCANcoder;
43 hal::SimDouble m_simSupplyVoltage;
44 hal::SimDouble m_simPosition;
45 hal::SimDouble m_simRawPosition;
46 hal::SimDouble m_simVelocity;
47
48 int32_t m_simPeriodicUid{-1};
49 std::vector<int32_t> m_simValueChangedUids;
50
51 static void OnValueChanged(
52 const char *name, void *param, HAL_SimValueHandle handle,
53 HAL_Bool readonly, const struct HAL_Value *value
54 );
55 static void OnPeriodic(void *param);
56
57public:
58 /**
59 * Constructs a new CANcoder object.
60 *
61 * \param deviceId ID of the device, as configured in Phoenix Tuner
62 * \param canbus The CAN bus this device is on
63 */
64 CANcoder(int deviceId, CANBus canbus = {});
65 /**
66 * Constructs a new CANcoder object.
67 *
68 * \param deviceId ID of the device, as configured in Phoenix Tuner
69 * \param canbus Name of the CAN bus this device is on. Possible CAN bus strings are:
70 * - "rio" for the native roboRIO CAN bus
71 * - CANivore name or serial number
72 * - SocketCAN interface (non-FRC Linux only)
73 * - "*" for any CANivore seen by the program
74 * - empty string (default) to select the default for the system:
75 * - "rio" on roboRIO
76 * - "can0" on Linux
77 * - "*" on Windows
78 *
79 * \deprecated Constructing devices with a CAN bus string is deprecated for removal
80 * in the 2027 season. Construct devices using a CANBus instance instead.
81 */
82 [[deprecated(
83 "Constructing devices with a CAN bus string is deprecated for removal "
84 "in the 2027 season. Construct devices using a CANBus instance instead."
85 )]]
86 CANcoder(int deviceId, std::string canbus);
87
89
90 void InitSendable(wpi::SendableBuilder &builder) override;
91};
92
93#if defined(_WIN32) || defined(_WIN64)
94#pragma warning(pop)
95#endif
96
97}
98}
99}
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:474
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CANcoder.hpp:32
CANcoder(int deviceId, CANBus canbus={})
Constructs a new CANcoder object.
CANcoder(int deviceId, std::string canbus)
Constructs a new CANcoder object.
void InitSendable(wpi::SendableBuilder &builder) override
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CoreCANcoder.hpp:602
StatusSignal< units::angle::turn_t > & GetPosition(bool refresh=true)
Position of the device.
Definition motor_constants.h:14