CTRE Phoenix Pro C++ 23.0.12
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
11
12#include "wpi/sendable/Sendable.h"
13#include "wpi/sendable/SendableBuilder.h"
14#include "wpi/sendable/SendableHelper.h"
15#include <hal/SimDevice.h>
16
17namespace ctre {
18namespace phoenixpro {
19namespace hardware {
20
21/**
22 * Class for CANcoder, a CAN based magnetic encoder that provides absolute and
23 * relative position along with filtered velocity.
24 */
26 public wpi::Sendable,
27 public wpi::SendableHelper<CANcoder>
28{
29 /**
30 * The StatusSignalValue getters are copies so that calls
31 * to the WPI interface do not update any references
32 *
33 * These are also mutable so the const getter methods are
34 * properly managed.
35 */
36 mutable StatusSignalValue<units::angle::turn_t> m_positionGetter = GetPosition();
37
38 static constexpr phoenix::platform::DeviceType kSimDeviceType = phoenix::platform::DeviceType::PRO_CANcoderType;
39
40 hal::SimDevice m_simCANcoder;
41 hal::SimDouble m_simSupplyVoltage;
42 hal::SimDouble m_simPosition;
43 hal::SimDouble m_simRawPosition;
44 hal::SimDouble m_simVelocity;
45
46 int32_t m_simPeriodicUid{-1};
47 std::vector<int32_t> m_simValueChangedUids;
48
49 static void OnValueChanged(const char *name, void *param, HAL_SimValueHandle handle,
50 HAL_Bool readonly, const struct HAL_Value *value);
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 Name of the CAN bus this device is on. Possible CAN bus strings are:
59 * - "rio" for the native roboRIO CAN bus
60 * - CANivore name or serial number
61 * - SocketCAN interface (non-FRC Linux only)
62 * - "*" for any CANivore seen by the program
63 * - empty string (default) to select the default for the system:
64 * - "rio" on roboRIO
65 * - "can0" on Linux
66 * - "*" on Windows
67 */
68 CANcoder(int deviceId, std::string canbus = "");
70
71 void InitSendable(wpi::SendableBuilder &builder) override;
72};
73
74}
75}
76}
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition: CANcoder.hpp:28
void InitSendable(wpi::SendableBuilder &builder) override
CANcoder(int deviceId, std::string canbus="")
Constructs a new CANcoder object.
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition: CoreCANcoder.hpp:331
StatusSignalValue< units::angle::turn_t > & GetPosition()
Position of device.
DeviceType
Enumeration of all supported device types.
Definition: DeviceType.hpp:26
Definition: string_util.hpp:14