From 1ce24a7a2fe009eed5df5366126c65aecccc5051 Mon Sep 17 00:00:00 2001 From: sciencewhiz Date: Sun, 22 Dec 2019 11:51:43 -0800 Subject: [PATCH] Add 2020 speed controllers (#2188) Add CTRE TalonFX (PWMTalonFX) Add Playing with Fusion Venom (PWMVenom) --- wpilibc/src/main/native/cpp/PWMTalonFX.cpp | 24 +++++++++ wpilibc/src/main/native/cpp/PWMVenom.cpp | 24 +++++++++ .../src/main/native/include/frc/PWMTalonFX.h | 45 +++++++++++++++++ .../src/main/native/include/frc/PWMVenom.h | 43 ++++++++++++++++ .../edu/wpi/first/wpilibj/PWMTalonFX.java | 49 +++++++++++++++++++ .../java/edu/wpi/first/wpilibj/PWMVenom.java | 48 ++++++++++++++++++ 6 files changed, 233 insertions(+) create mode 100644 wpilibc/src/main/native/cpp/PWMTalonFX.cpp create mode 100644 wpilibc/src/main/native/cpp/PWMVenom.cpp create mode 100644 wpilibc/src/main/native/include/frc/PWMTalonFX.h create mode 100644 wpilibc/src/main/native/include/frc/PWMVenom.h create mode 100644 wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonFX.java create mode 100644 wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVenom.java diff --git a/wpilibc/src/main/native/cpp/PWMTalonFX.cpp b/wpilibc/src/main/native/cpp/PWMTalonFX.cpp new file mode 100644 index 0000000000..09b7163c24 --- /dev/null +++ b/wpilibc/src/main/native/cpp/PWMTalonFX.cpp @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "frc/PWMTalonFX.h" + +#include + +#include "frc/smartdashboard/SendableRegistry.h" + +using namespace frc; + +PWMTalonFX::PWMTalonFX(int channel) : PWMSpeedController(channel) { + SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); + SetPeriodMultiplier(kPeriodMultiplier_1X); + SetSpeed(0.0); + SetZeroLatch(); + + HAL_Report(HALUsageReporting::kResourceType_TalonFX, GetChannel() + 1); + SendableRegistry::GetInstance().SetName(this, "PWMTalonFX", GetChannel()); +} diff --git a/wpilibc/src/main/native/cpp/PWMVenom.cpp b/wpilibc/src/main/native/cpp/PWMVenom.cpp new file mode 100644 index 0000000000..9fa14b7245 --- /dev/null +++ b/wpilibc/src/main/native/cpp/PWMVenom.cpp @@ -0,0 +1,24 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#include "frc/PWMVenom.h" + +#include + +#include "frc/smartdashboard/SendableRegistry.h" + +using namespace frc; + +PWMVenom::PWMVenom(int channel) : PWMSpeedController(channel) { + SetBounds(2.004, 1.52, 1.50, 1.48, 0.997); + SetPeriodMultiplier(kPeriodMultiplier_1X); + SetSpeed(0.0); + SetZeroLatch(); + + HAL_Report(HALUsageReporting::kResourceType_FusionVenom, GetChannel() + 1); + SendableRegistry::GetInstance().SetName(this, "PWMVenom", GetChannel()); +} diff --git a/wpilibc/src/main/native/include/frc/PWMTalonFX.h b/wpilibc/src/main/native/include/frc/PWMTalonFX.h new file mode 100644 index 0000000000..d85c7ca5e9 --- /dev/null +++ b/wpilibc/src/main/native/include/frc/PWMTalonFX.h @@ -0,0 +1,45 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include "frc/PWMSpeedController.h" + +namespace frc { + +/** + * Cross the Road Electronics (CTRE) Talon FX Speed Controller with PWM + * control. + * + * Note that the Talon FX uses the following bounds for PWM values. These + * values should work reasonably well for most controllers, but if users + * experience issues such as asymmetric behavior around the deadband or + * inability to saturate the controller in either direction, calibration is + * recommended. The calibration procedure can be found in the Talon FX User + * Manual available from Cross The Road Electronics. + * + * \li 2.004ms = full "forward" + * \li 1.520ms = the "high end" of the deadband range + * \li 1.500ms = center of the deadband range (off) + * \li 1.480ms = the "low end" of the deadband range + * \li 0.997ms = full "reverse" + */ +class PWMTalonFX : public PWMSpeedController { + public: + /** + * Construct a Talon FX connected via PWM. + * + * @param channel The PWM channel that the Talon FX is attached to. 0-9 are + * on-board, 10-19 are on the MXP port + */ + explicit PWMTalonFX(int channel); + + PWMTalonFX(PWMTalonFX&&) = default; + PWMTalonFX& operator=(PWMTalonFX&&) = default; +}; + +} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/PWMVenom.h b/wpilibc/src/main/native/include/frc/PWMVenom.h new file mode 100644 index 0000000000..189db4372a --- /dev/null +++ b/wpilibc/src/main/native/include/frc/PWMVenom.h @@ -0,0 +1,43 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +#pragma once + +#include "frc/PWMSpeedController.h" + +namespace frc { + +/** + * Playing with Fusion Venom Smart Motor with PWM control. + * + * Note that the Venom uses the following bounds for PWM values. These + * values should work reasonably well for most controllers, but if users + * experience issues such as asymmetric behavior around the deadband or + * inability to saturate the controller in either direction, calibration is + * recommended. + * + * \li 2.004ms = full "forward" + * \li 1.520ms = the "high end" of the deadband range + * \li 1.500ms = center of the deadband range (off) + * \li 1.480ms = the "low end" of the deadband range + * \li 0.997ms = full "reverse" + */ +class PWMVenom : public PWMSpeedController { + public: + /** + * Construct a Venom connected via PWM. + * + * @param channel The PWM channel that the Venom is attached to. 0-9 are + * on-board, 10-19 are on the MXP port + */ + explicit PWMVenom(int channel); + + PWMVenom(PWMVenom&&) = default; + PWMVenom& operator=(PWMVenom&&) = default; +}; + +} // namespace frc diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonFX.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonFX.java new file mode 100644 index 0000000000..03acab2c12 --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMTalonFX.java @@ -0,0 +1,49 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj; + +import edu.wpi.first.hal.FRCNetComm.tResourceType; +import edu.wpi.first.hal.HAL; +import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; + +/** + * Cross the Road Electronics (CTRE) Talon FX Speed Controller with PWM control. + * + *

Note that the TalonFX uses the following bounds for PWM values. These values should work + * reasonably well for most controllers, but if users experience issues such as asymmetric + * behavior around the deadband or inability to saturate the controller in either direction, + * calibration is recommended. The calibration procedure can be found in the TalonFX User Manual + * available from CTRE. + * + *

    + *
  • 2.004ms = full "forward" + *
  • 1.520ms = the "high end" of the deadband range + *
  • 1.500ms = center of the deadband range (off) + *
  • 1.480ms = the "low end" of the deadband range + *
  • 0.997ms = full "reverse" + *
+ */ +public class PWMTalonFX extends PWMSpeedController { + /** + * Constructor for a TalonFX connected via PWM. + * + * @param channel The PWM channel that the Talon FX is attached to. 0-9 are on-board, 10-19 are + * on the MXP port + */ + public PWMTalonFX(final int channel) { + super(channel); + + setBounds(2.004, 1.52, 1.50, 1.48, 0.997); + setPeriodMultiplier(PeriodMultiplier.k1X); + setSpeed(0.0); + setZeroLatch(); + + HAL.report(tResourceType.kResourceType_TalonFX, getChannel() + 1); + SendableRegistry.setName(this, "PWMTalonFX", getChannel()); + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVenom.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVenom.java new file mode 100644 index 0000000000..9a1116dedb --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMVenom.java @@ -0,0 +1,48 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj; + +import edu.wpi.first.hal.FRCNetComm.tResourceType; +import edu.wpi.first.hal.HAL; +import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry; + +/** + * Playing with Fusion Venom Smart Motor with PWM control. + * + *

Note that the Venom uses the following bounds for PWM values. These values should work + * reasonably well for most controllers, but if users experience issues such as asymmetric + * behavior around the deadband or inability to saturate the controller in either direction, + * calibration is recommended. + * + *

    + *
  • 2.004ms = full "forward" + *
  • 1.520ms = the "high end" of the deadband range + *
  • 1.500ms = center of the deadband range (off) + *
  • 1.480ms = the "low end" of the deadband range + *
  • 0.997ms = full "reverse" + *
+ */ +public class PWMVenom extends PWMSpeedController { + /** + * Constructor for a Venom connected via PWM. + * + * @param channel The PWM channel that the Venom is attached to. 0-9 are on-board, 10-19 are + * on the MXP port + */ + public PWMVenom(final int channel) { + super(channel); + + setBounds(2.004, 1.52, 1.50, 1.48, 0.997); + setPeriodMultiplier(PeriodMultiplier.k1X); + setSpeed(0.0); + setZeroLatch(); + + HAL.report(tResourceType.kResourceType_FusionVenom, getChannel() + 1); + SendableRegistry.setName(this, "PWMVenom", getChannel()); + } +}