CTRE Phoenix 6 C++ 25.0.0-beta-4
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/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/**
21 * Class for CANrange, a CAN based Time of Flight (ToF) sensor that measures the
22 * distance to the front of the device.
23 */
25 public wpi::Sendable,
26 public wpi::SendableHelper<CANrange>
27{
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<units::length::meter_t> m_distanceGetter = GetDistance(false);
36 mutable StatusSignal<bool> m_isDetectedGetter = GetIsDetected(false);
37
38 hal::SimDevice m_simCANrange;
39 hal::SimDouble m_simSupplyVoltage;
40 hal::SimDouble m_simDistance;
41 hal::SimBoolean m_simIsDetected;
42
43 int32_t m_simPeriodicUid{-1};
44 std::vector<int32_t> m_simValueChangedUids;
45
46 static void OnValueChanged(const char *name, void *param, HAL_SimValueHandle handle,
47 HAL_Bool readonly, const struct HAL_Value *value);
48 static void OnPeriodic(void *param);
49
50public:
51 /**
52 * Constructs a new CANrange object.
53 *
54 * \param deviceId ID of the device, as configured in Phoenix Tuner.
55 * \param canbus Name of the CAN bus this device is on. Possible CAN bus strings are:
56 * - "rio" for the native roboRIO CAN bus
57 * - CANivore name or serial number
58 * - SocketCAN interface (non-FRC Linux only)
59 * - "*" for any CANivore seen by the program
60 * - empty string (default) to select the default for the system:
61 * - "rio" on roboRIO
62 * - "can0" on Linux
63 * - "*" on Windows
64 */
65 CANrange(int deviceId, std::string canbus = "");
66 /**
67 * Constructs a new CANrange object.
68 *
69 * \param deviceId ID of the device, as configured in Phoenix Tuner.
70 * \param canbus The CAN bus this device is on.
71 */
75
77
78 void InitSendable(wpi::SendableBuilder &builder) override;
79};
80
81}
82}
83}
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:657
Class for CANrange, a CAN based Time of Flight (ToF) sensor that measures the distance to the front o...
Definition CANrange.hpp:27
CANrange(int deviceId, CANBus canbus)
Constructs a new CANrange object.
Definition CANrange.hpp:72
CANrange(int deviceId, std::string canbus="")
Constructs a new CANrange object.
void InitSendable(wpi::SendableBuilder &builder) override
StatusSignal< T > & LookupStatusSignal(uint16_t spn, std::string signalName, bool reportOnConstruction, bool refresh)
Definition ParentDevice.hpp:553
Class for CANrange, a CAN based Time of Flight (ToF) sensor that measures the distance to the front o...
Definition CoreCANrange.hpp:728
StatusSignal< bool > & GetIsDetected(bool refresh=true)
Whether the CANrange detects an object using the configured proximity parameters.
StatusSignal< units::length::meter_t > & GetDistance(bool refresh=true)
Distance to the nearest object in the configured field of view of the CANrange.
Definition StatusCodes.h:18
Definition span.hpp:401