Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Add CTRE CANivore and Phoenix Pro support #455

Merged
merged 31 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dab0378
Brought CTR vendordep back in, and added Phoenix Pro TalonFX for FOC …
TytanRock Dec 18, 2022
1e9cb85
Add support for generic CANivore on TalonFX devices
TytanRock Dec 19, 2022
06b3645
SysID runs on a 2023 beta RIO
TytanRock Dec 21, 2022
8342c66
Added CANivore to more CTR devices
TytanRock Dec 21, 2022
0b52704
Created constant for CANivore name length
TytanRock Dec 21, 2022
404be08
Merge branch 'main' into main
TytanRock Dec 21, 2022
cb7437f
Merge branch 'main' into main
calcmogul Jan 1, 2023
fb4363b
Run wpiformat
calcmogul Jan 1, 2023
f30602b
Add Pigeon2 Pro support
TytanRock Jan 1, 2023
11b4def
Run wpiformat and fix CTRE header order
calcmogul Jan 1, 2023
12cbe16
Add Param doc for SetupGyro
TytanRock Jan 2, 2023
cec0590
Address comments on PR
TytanRock Jan 3, 2023
74f68f4
Merge remote-tracking branch 'base/main'
TytanRock Jan 3, 2023
7c5bc61
Merge remote-tracking branch 'base/main'
TytanRock Jan 10, 2023
0863f3e
Updated Phoenix and WPILib to release version
TytanRock Jan 10, 2023
9b7d5f8
Build for Windows
TytanRock Jan 10, 2023
11b047b
Formatting
TytanRock Jan 10, 2023
fc13d80
Undo wpi version update
TytanRock Jan 10, 2023
c120f88
Reformat with clang-format version 14
TytanRock Jan 10, 2023
49d0559
Merge remote-tracking branch 'base/main'
TytanRock Jan 21, 2023
0bc1da7
Updated vendordep for Phoenix
TytanRock Jan 21, 2023
e93727f
Formatted Phoenix Vendordep
TytanRock Jan 22, 2023
f45d8cf
Add CANcoder Pro
TytanRock Jan 22, 2023
04f1f20
Fix bug in CANcoder Pro setup
TytanRock Jan 22, 2023
78cba74
Merge branch 'main' into ctre-canivore-support
calcmogul Feb 1, 2023
6a034f7
Clean up the diff
calcmogul Feb 1, 2023
72731c8
Fix TalonFX pro voltage recording
calcmogul Feb 1, 2023
abb6092
Fix up layout for CANivore input boxes
calcmogul Feb 1, 2023
4b9534a
Revert header move
calcmogul Feb 1, 2023
b8dd7ae
Use supply voltage instead of flat 12 for Pro voltage measurement
TytanRock Feb 2, 2023
7591907
Format code
TytanRock Feb 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .styleguide
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ includeOtherLibs {
^glass
^GLFW
^cscore
^ctre
^Eigen
^fmt/
^frc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ wpi::StringMap<wpi::SmallVector<sysid::HardwareType, 2>>
{std::string{sysid::motorcontroller::kVictorSPX.name}, kGeneralEncs},
{std::string{sysid::motorcontroller::kTalonSRX.name}, kTalonEncs},
{std::string{sysid::motorcontroller::kTalonFX.name}, kBuiltInEncs},
{std::string{sysid::motorcontroller::kTalonFXPro.name}, kBuiltInEncs},
{std::string{sysid::motorcontroller::kSPARKMAXBrushless.name},
kSMaxEncs},
{std::string{sysid::motorcontroller::kSPARKMAXBrushed.name}, kSMaxEncs},
Expand All @@ -66,6 +67,7 @@ wpi::StringMap<wpi::SmallVector<std::string_view, 4>> gyroCtorMap = {
{std::string{sysid::gyro::kAnalogGyro.name}, kAnalogCtors},
{std::string{sysid::gyro::kPigeon.name}, kPigeonCtors},
{std::string{sysid::gyro::kPigeon2.name}, kAnalogCtors},
{std::string{sysid::gyro::kPigeon2Pro.name}, kAnalogCtors},
{std::string{sysid::gyro::kADXRS450.name}, kADXRS450Ctors},
{std::string{sysid::gyro::kNavX.name}, kNavXCtors},
{std::string{sysid::gyro::kADIS16448.name}, kADIS16448Ctors},
Expand Down Expand Up @@ -140,6 +142,8 @@ class GenerationTest : public ::testing::Test {
motorController == sysid::motorcontroller::kVictorSPX.name ||
motorController == sysid::motorcontroller::kTalonFX.name) {
voltageAccessor = "CTRE";
} else if (motorController == sysid::motorcontroller::kTalonFXPro.name) {
voltageAccessor = "CTRE (Pro)";
} else if (motorController == sysid::motorcontroller::kVenom.name) {
voltageAccessor = "Venom";
} else {
Expand Down Expand Up @@ -176,6 +180,8 @@ class GenerationTest : public ::testing::Test {
FindInLog(fmt::format("Pigeon, {}", pigeonPortStr));
} else if (gyro == sysid::gyro::kPigeon2.name) {
FindInLog(fmt::format("Pigeon2, {} (CAN)", gyroCtor));
} else if (gyro == sysid::gyro::kPigeon2Pro.name) {
FindInLog(fmt::format("Pigeon2, {} (CAN) (Pro)", gyroCtor));
} else if (gyro == sysid::gyro::kADXRS450.name ||
gyro == sysid::gyro::kADIS16448.name ||
gyro == sysid::gyro::kADIS16470.name) {
Expand Down
13 changes: 13 additions & 0 deletions sysid-application/src/main/native/cpp/generation/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ wpi::json ConfigManager::Generate(size_t occupied) {
// Create the JSON to return.
wpi::json json;

// Keep a CANivore name vector around that we can push our names into
std::vector<std::string> canivoreNames;

// Add motor ports.
json["primary motor ports"] =
SliceVector(m_config.primaryMotorPorts, occupied);
Expand All @@ -38,6 +41,13 @@ wpi::json ConfigManager::Generate(size_t occupied) {
}
json["motor controllers"] = motorControllers;

// Add CANivore busses
canivoreNames.clear();
for (size_t i = 0; i < occupied; i++) {
canivoreNames.push_back(std::string(m_config.canivoreNames[i].data()));
}
json["canivore names"] = canivoreNames;

calcmogul marked this conversation as resolved.
Show resolved Hide resolved
// Add motor inversions.
json["primary motors inverted"] =
SliceVector(m_config.primaryMotorsInverted, occupied);
Expand All @@ -47,6 +57,8 @@ wpi::json ConfigManager::Generate(size_t occupied) {
// Add encoder ports.
json["primary encoder ports"] = m_config.primaryEncoderPorts;
json["secondary encoder ports"] = m_config.secondaryEncoderPorts;
json["encoder canivore name"] =
std::string(m_config.encoderCANivoreName.data());

// Add encoder type.
json["encoder type"] = m_config.encoderType.name;
Expand All @@ -63,6 +75,7 @@ wpi::json ConfigManager::Generate(size_t occupied) {
// Add gyro type and constructor.
json["gyro"] = m_config.gyro.name;
json["gyro ctor"] = m_config.gyroCtor;
json["gyro canivore name"] = std::string(m_config.gyroCANivoreName.data());

// Add advanced encoder settings.
json["encoding"] = m_config.encoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ HardwareType sysid::motorcontroller::FromMotorControllerName(
if (name == "TalonFX") {
return sysid::motorcontroller::kTalonFX;
}
if (name == "TalonFX (Pro)") {
return sysid::motorcontroller::kTalonFXPro;
}
if (name == "SPARK MAX (Brushless)") {
return sysid::motorcontroller::kSPARKMAXBrushless;
}
Expand Down
43 changes: 36 additions & 7 deletions sysid-application/src/main/native/cpp/view/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void Generator::CANCoderSetup(bool drive) {
ImGui::SameLine();
ImGui::Checkbox(drive ? "Left Encoder Inverted" : "Encoder Inverted",
&m_settings.primaryEncoderInverted);
ImGui::SameLine();
ImGui::SetNextItemWidth(80);
if (drive) {
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 2);
ImGui::InputInt("R CANCoder Port", &m_settings.secondaryEncoderPorts[1], 0,
Expand All @@ -142,6 +144,10 @@ void Generator::CANCoderSetup(bool drive) {
ImGui::Checkbox("Right Encoder Inverted",
&m_settings.secondaryEncoderInverted);
}
ImGui::SetNextItemWidth(80);
ImGui::InputText("CANcoder CANivore Name",
m_settings.encoderCANivoreName.data(),
m_settings.encoderCANivoreName.size());
}

void Generator::RegularEncoderSetup(bool drive) {
Expand All @@ -167,8 +173,10 @@ void Generator::UpdateFromConfig() {

// Setting right Idxs for the GUI
if (mainMotorController == sysid::motorcontroller::kTalonSRX ||
mainMotorController == sysid::motorcontroller::kTalonFX) {
if (mainMotorController == sysid::motorcontroller::kTalonFX) {
mainMotorController == sysid::motorcontroller::kTalonFX ||
mainMotorController == sysid::motorcontroller::kTalonFXPro) {
if (mainMotorController == sysid::motorcontroller::kTalonFX ||
mainMotorController == sysid::motorcontroller::kTalonFXPro) {
m_encoderIdx = GetNewIdx(ArrayConcat(kBuiltInEncoders, kGeneralEncoders),
encoderTypeName);
} else {
Expand Down Expand Up @@ -292,6 +300,7 @@ void Generator::Display() {
auto& mc = m_settings.motorControllers;
auto& pi = m_settings.primaryMotorsInverted;
auto& si = m_settings.secondaryMotorsInverted;
auto& cn = m_settings.canivoreNames;

// Ensure that our vector contains i+1 elements.
if (pm.size() == i) {
Expand All @@ -300,6 +309,7 @@ void Generator::Display() {
mc.emplace_back(motorControllerNames[0]);
pi.emplace_back(false);
si.emplace_back(false);
cn.emplace_back(std::array<char, 32>{'r', 'i', 'o', '\0'});
}

// Make sure elements have unique IDs.
Expand Down Expand Up @@ -346,6 +356,15 @@ void Generator::Display() {
ImGui::SameLine();
ImGui::Checkbox(drive ? "L Inverted" : "Inverted", &pi[i]);

if (m_settings.motorControllers[i] == sysid::motorcontroller::kTalonFX ||
m_settings.motorControllers[i] == sysid::motorcontroller::kTalonFXPro) {
// Add CANivore name if we are using a CTRE motor controller
ImGui::SameLine();
ImGui::SetNextItemWidth(80);
ImGui::InputText("MC CANivore Name", m_settings.canivoreNames[i].data(),
m_settings.canivoreNames[i].size());
calcmogul marked this conversation as resolved.
Show resolved Hide resolved
}

// Add right side drivetrain ports (if the analysis type is drivetrain).
if (drive) {
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 2);
Expand Down Expand Up @@ -383,8 +402,10 @@ void Generator::Display() {
// Add encoder selection.
ImGui::SetNextItemWidth(ImGui::GetFontSize() * kTextBoxWidthMultiple);
if (mainMotorController == sysid::motorcontroller::kTalonSRX ||
mainMotorController == sysid::motorcontroller::kTalonFX) {
if (mainMotorController == sysid::motorcontroller::kTalonFX) {
mainMotorController == sysid::motorcontroller::kTalonFX ||
mainMotorController == sysid::motorcontroller::kTalonFXPro) {
if (mainMotorController == sysid::motorcontroller::kTalonFX ||
mainMotorController == sysid::motorcontroller::kTalonFXPro) {
GetEncoder(ArrayConcat(kBuiltInEncoders, kGeneralEncoders));
if (m_encoderIdx < 1) {
RegularEncoderSetup(drive);
Expand Down Expand Up @@ -489,9 +510,16 @@ void Generator::Display() {
if (m_isTalon) {
m_settings.gyroCtor = "WPI_TalonSRX-" + m_settings.gyroCtor;
}
} else if (gyroType == sysid::gyro::kPigeon2) {
} else if (gyroType == sysid::gyro::kPigeon2 ||
gyroType == sysid::gyro::kPigeon2Pro) {
ImGui::InputInt("CAN ID", &m_gyroPort, 0, 0);
m_settings.gyroCtor = std::to_string(m_gyroPort);
ImGui::SameLine();
ImGui::SetNextItemWidth(80);
ImGui::InputText("Gyro CANivore Name", m_settings.gyroCANivoreName.data(),
m_settings.gyroCANivoreName.size());
m_settings.gyroCtor = std::to_string(m_gyroPort) + ", " +
std::string{m_settings.gyroCANivoreName.begin(),
m_settings.gyroCANivoreName.end()};
} else if (gyroType == sysid::gyro::kADXRS450) {
ImGui::Combo("SPI Port", &m_gyroParam, kADXRS450Ctors,
IM_ARRAYSIZE(kADXRS450Ctors));
Expand Down Expand Up @@ -536,7 +564,8 @@ void Generator::Display() {
sysid::CreateTooltip(
"This is the number of encoder counts per revolution for your encoder.\n"
"Common values for this are here:\nCTRE Magnetic Encoder: 4096\nFalcon "
"500 Integrated: 2048\nREV Throughbore: 8192\nNEO (and NEO 550) "
"500 Integrated: 2048\nFalcon 500 running Phoenix Pro (Pro already "
"handles this value): 1\nREV Throughbore: 8192\nNEO (and NEO 550) "
"Integrated "
"Encoders (REV already handles this value): 1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace sysid {
* inversions, etc. It also includes numerical data such as EPR.
*/
struct ConfigSettings {
/**
* Maximum length of a CANivore name is 32 characters
*/
static constexpr int kMaxCANivoreNameLength = 32;
/**
* Ports for the primary motor controllers. For general mechanisms this is the
* motor ports that will be used. For drivetrains these are the left-side
Expand All @@ -42,6 +46,12 @@ struct ConfigSettings {
wpi::SmallVector<HardwareType, 3> motorControllers = {
sysid::motorcontroller::kPWM, sysid::motorcontroller::kPWM};

/**
* The CANivore name if it's on a Non-RIO bus
*/
wpi::SmallVector<std::array<char, kMaxCANivoreNameLength>, 3> canivoreNames =
{{'r', 'i', 'o', '\0'}, {'r', 'i', 'o', '\0'}};

/**
* If the primary motor controllers (general mechanism motors / left
* drivetrain motors) should be inverted or not.
Expand Down Expand Up @@ -73,6 +83,12 @@ struct ConfigSettings {
*/
std::array<int, 2> secondaryEncoderPorts = {2, 3};

/**
* CANivore names for the CANcoder sensors if they're not on the RIO bus.
*/
std::array<char, kMaxCANivoreNameLength> encoderCANivoreName = {'r', 'i', 'o',
'\0'};

/**
* If the primary encoder (general mechanism motors / left drivetrain encoder)
* should be inverted or not.
Expand Down Expand Up @@ -110,6 +126,12 @@ struct ConfigSettings {
*/
std::string gyroCtor = "0";

/**
* The CANivore name of a Pigeon2 if it's on a Non-RIO bus
*/
std::array<char, kMaxCANivoreNameLength> gyroCANivoreName = {'r', 'i', 'o',
'\0'};

/**
* If the encoder is plugged into the roboRIO, there's the option to set it's
* encoding setting to reduce noise.
Expand All @@ -136,18 +158,21 @@ struct ConfigSettings {
const ConfigSettings kRomiConfig{{0},
{1},
{sysid::motorcontroller::kPWM},
{{'r', 'i', 'o', '\0'}},
{true},
{false},
sysid::encoder::kRoboRIO,
{4, 5},
{6, 7},
{{'r', 'i', 'o', '\0'}},
false,
false,
1440.0,
1.0,
1.0,
sysid::gyro::kRomiGyro,
""};
"",
{'r', 'i', 'o', '\0'}};

/**
* This class manages generating the JSON configuration from a reference to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ constexpr HardwareType kPWM{"PWM"};
constexpr HardwareType kTalonSRX{"TalonSRX"};
constexpr HardwareType kVictorSPX{"VictorSPX"};
constexpr HardwareType kTalonFX{"TalonFX"};
constexpr HardwareType kTalonFXPro{"TalonFX (Pro)"};
constexpr HardwareType kSPARKMAXBrushless{"SPARK MAX (Brushless)"};
constexpr HardwareType kSPARKMAXBrushed{"SPARK MAX (Brushed)"};
constexpr HardwareType kVenom{"Venom"};

constexpr std::array<HardwareType, 7> kMotorControllers = {
kPWM, kTalonSRX, kVictorSPX,
kTalonFX, kSPARKMAXBrushless, kSPARKMAXBrushed,
kVenom};
constexpr std::array<HardwareType, 8> kMotorControllers = {
kPWM, kTalonSRX, kVictorSPX, kTalonFX,
kTalonFXPro, kSPARKMAXBrushless, kSPARKMAXBrushed, kVenom};

/**
* Returns an existing motor controller HardwareType from a string_view. Throws
Expand Down Expand Up @@ -107,6 +107,7 @@ constexpr HardwareType kADIS16470{"ADIS16470"};
constexpr HardwareType kNavX{"NavX"};
constexpr HardwareType kPigeon{"Pigeon"};
constexpr HardwareType kPigeon2{"Pigeon2"};
constexpr HardwareType kPigeon2Pro{"Pigeon2 (Pro)"};
constexpr HardwareType kRomiGyro{"Romi"};
constexpr HardwareType kNoGyroOption{"None"};

Expand Down
Loading