CTRE Phoenix 6 C++ 26.50.0-alpha-1
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
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 CANrange, a CAN based Time of Flight (ToF) sensor that measures the
24 * distance to the front of the device.
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::meter_t> m_distanceGetter = GetDistance(false);
35 mutable StatusSignal<bool> m_isDetectedGetter = GetIsDetected(false);
36
37 wpi::hal::SimDevice m_simCANrange;
38 wpi::hal::SimDouble m_simSupplyVoltage;
39 wpi::hal::SimDouble m_simDistance;
40 wpi::hal::SimBoolean m_simIsDetected;
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 CANrange 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 CANrange(int deviceId, CANBus canbus);
59
61
62 /**
63 * \brief Constructs a stubbed-out CANrange, 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 CANrange
68 */
69 static CANrange None()
70 {
71 return CANrange{-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
CANrange(int deviceId, CANBus canbus)
Constructs a new CANrange object.
static CANrange None()
Constructs a stubbed-out CANrange, where all status signals, controls, configs, etc.
Definition CANrange.hpp:69
Class for CANrange, a CAN based Time of Flight (ToF) sensor that measures the distance to the front o...
Definition CoreCANrange.hpp:734
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