2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
cancoder_config.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <units/time.h>
8
10#include "ctre/Phoenix.h"
11
12namespace argos_lib {
13 namespace cancoder_config {
14
15 HAS_MEMBER(direction)
16 HAS_MEMBER(initMode)
17 HAS_MEMBER(magOffset)
19
34 template <typename T>
35 bool CanCoderConfig(CANCoder& encoder, units::millisecond_t configTimeout) {
36 ctre::phoenix::sensors::CANCoderConfiguration config;
37 auto timeout = configTimeout.to<int>();
38
39 if constexpr (has_direction<T>{}) {
40 config.sensorDirection = T::direction;
41 }
42 if constexpr (has_initMode<T>{}) {
43 config.initializationStrategy = T::initMode;
44 }
45 if constexpr (has_range<T>{}) {
46 config.absoluteSensorRange = T::range;
47 }
48 if constexpr (has_magOffset<T>{}) {
49 config.magnetOffsetDegrees = T::magOffset;
50 }
51
52 encoder.ConfigFactoryDefault(timeout);
53 return ErrorCode::OKAY == encoder.ConfigAllSettings(config, timeout);
54 }
55
67 template <typename CompetitionConfig, typename PracticeConfig>
68 bool CanCoderConfig(CANCoder& encoder, units::millisecond_t configTimeout, argos_lib::RobotInstance instance) {
69 switch (instance) {
72 break;
75 break;
76 }
77 return false;
78 }
79
80 } // namespace cancoder_config
81} // namespace argos_lib
#define HAS_MEMBER(X)
Helper function generator to detect if a namespace has a member defined.
Definition compile_time_member_check.h:14
bool CanCoderConfig(CANCoder &encoder, units::millisecond_t configTimeout)
Configures a CTRE CanCoder with only the fields provided. All other fields are given the factory defa...
Definition cancoder_config.h:35
Definition swap_controllers_command.h:12
RobotInstance
Differentiates between practice robot and competition robot.
Definition config_types.h:13
@ Competition
Competition robot.
@ Practice
Practice robot.
Definition custom_units.h:11
Definition cancoder_config.h:15
Definition cancoder_config.h:16
Definition cancoder_config.h:17
Definition cancoder_config.h:18