CTRE Phoenix C++ 5.33.1
RCRadio3Ch.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
4#include <vector>
7
8namespace ctre{
9namespace phoenix {
10
11/**
12 * Class to convert RC PWM signals into CAN signals using CANifier
13 */
15public:
16 /**
17 * CANifier PWM Channel
18 */
19 enum Channel{
20 /**
21 * PWM Channel 1
22 */
24 /**
25 * PWM Channel 2
26 */
28 /**
29 * PWM Channel 3
30 */
32 };
33 /**
34 * Status of CANiifer
35 */
36 enum Status{
37 /**
38 * CANifier is not communicating over CAN
39 */
41 /**
42 * CANifier does not detect PWM input
43 */
45 /**
46 * CANifier is OK
47 */
49 };
50
51 /**
52 * Current status of CANifier
53 */
54 Status CurrentStatus = Status::Okay;
55
56 /**
57 * Constructor for RCRadio3Ch
58 * @param canifier reference to CANifier to use
59 */
61 /**
62 * Gets the microsecond duty cycle of specified channel
63 * @param channel channel to read
64 * @return duty cycle in micro seconds
65 */
66 double GetDutyCycleUs(Channel channel);
67 /**
68 * Gets the percent duty cycle of specified channel
69 * @param channel channel to read
70 * @return duty cycle in percent [0,1]
71 */
72 double GetDutyCyclePerc(Channel channel);
73 /**
74 * Gets whether a switch is on or off for a channel
75 * @param channel channel to read
76 * @return true if switch is on
77 */
78 bool GetSwitchValue(Channel channel);
79 /**
80 * Gets the period of the pwm signal of a channel
81 * @param channel channel to read
82 * @return period of pwm signal in microseconds
83 */
84 double GetPeriodUs(Channel channel);
85
86 //ILoopable
87 /**
88 * Call this once every loop, it processes the incoming CANifier signals
89 */
90 void Process();
91
92private:
93 int _errorCodes[4];
94 ctre::phoenix::CANifier *_canifier;
95
96
97 //This is only a 2d array??
98 double _pulseWidthAndPeriods[4][2] =
99 {
100 { 0, 0 },
101 { 0, 0 },
102 { 0, 0 },
103 { 0, 0 },
104 };
105 double Interpolate(std::vector<double> &xData, std::vector<double> &yData, double x, bool extrapolate);
106};
107
108}}
CTRE CANifier.
Definition: CANifier.h:108
Class to convert RC PWM signals into CAN signals using CANifier.
Definition: RCRadio3Ch.h:14
RCRadio3Ch(ctre::phoenix::CANifier *canifier)
Constructor for RCRadio3Ch.
double GetPeriodUs(Channel channel)
Gets the period of the pwm signal of a channel.
void Process()
Call this once every loop, it processes the incoming CANifier signals.
Status CurrentStatus
Current status of CANifier.
Definition: RCRadio3Ch.h:54
double GetDutyCycleUs(Channel channel)
Gets the microsecond duty cycle of specified channel.
bool GetSwitchValue(Channel channel)
Gets whether a switch is on or off for a channel.
double GetDutyCyclePerc(Channel channel)
Gets the percent duty cycle of specified channel.
Channel
CANifier PWM Channel.
Definition: RCRadio3Ch.h:19
@ Channel1
PWM Channel 1.
Definition: RCRadio3Ch.h:23
@ Channel3
PWM Channel 3.
Definition: RCRadio3Ch.h:31
@ Channel2
PWM Channel 2.
Definition: RCRadio3Ch.h:27
Status
Status of CANiifer.
Definition: RCRadio3Ch.h:36
@ LossOfCAN
CANifier is not communicating over CAN.
Definition: RCRadio3Ch.h:40
@ LossOfPwm
CANifier does not detect PWM input.
Definition: RCRadio3Ch.h:44
@ Okay
CANifier is OK.
Definition: RCRadio3Ch.h:48
Interface for processable objects.
Definition: IProcessable.h:8
namespace ctre
Definition: paramEnum.h:5