diff --git a/wpilibc/src/main/native/cpp/PWMSparkMax.cpp b/wpilibc/src/main/native/cpp/PWMSparkMax.cpp new file mode 100644 index 0000000000..d441315adb --- /dev/null +++ b/wpilibc/src/main/native/cpp/PWMSparkMax.cpp @@ -0,0 +1,30 @@ +/*----------------------------------------------------------------------------*/ +/* 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/PWMSparkMax.h" + +#include + +using namespace frc; + +PWMSparkMax::PWMSparkMax(int channel) : PWMSpeedController(channel) { + /* Note that the SparkMax uses the following bounds for PWM values. + * + * 2.003ms = full "forward" + * 1.55ms = the "high end" of the deadband range + * 1.50ms = center of the deadband range (off) + * 1.46ms = the "low end" of the deadband range + * 0.999ms = full "reverse" + */ + SetBounds(2.003, 1.55, 1.50, 1.46, .999); + SetPeriodMultiplier(kPeriodMultiplier_1X); + SetSpeed(0.0); + SetZeroLatch(); + + HAL_Report(HALUsageReporting::kResourceType_RevSparkMaxPWM, GetChannel()); + SetName("PWMSparkMax", GetChannel()); +} diff --git a/wpilibc/src/main/native/include/frc/PWMSparkMax.h b/wpilibc/src/main/native/include/frc/PWMSparkMax.h new file mode 100644 index 0000000000..c8b22d7361 --- /dev/null +++ b/wpilibc/src/main/native/include/frc/PWMSparkMax.h @@ -0,0 +1,31 @@ +/*----------------------------------------------------------------------------*/ +/* 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 { + +/** + * REV Robotics SparkMax Speed Controller. + */ +class PWMSparkMax : public PWMSpeedController { + public: + /** + * Constructor for a SparkMax. + * + * @param channel The PWM channel that the Spark is attached to. 0-9 are + * on-board, 10-19 are on the MXP port + */ + explicit PWMSparkMax(int channel); + + PWMSparkMax(PWMSparkMax&&) = default; + PWMSparkMax& operator=(PWMSparkMax&&) = default; +}; + +} // namespace frc diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSparkMax.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSparkMax.java new file mode 100644 index 0000000000..320d8a417a --- /dev/null +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PWMSparkMax.java @@ -0,0 +1,41 @@ +/*----------------------------------------------------------------------------*/ +/* 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; + +/** + * REV Robotics SparkMax Speed Controller. + */ +public class PWMSparkMax extends PWMSpeedController { + /** + * Common initialization code called by all constructors. + * + *

Note that the SPARK 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 Spark User Manual + * available from REV Robotics. + * + *

- 2.003ms = full "forward" - 1.55ms = the "high end" of the deadband range - 1.50ms = + * center of the deadband range (off) - 1.46ms = the "low end" of the deadband range - .999ms = + * full "reverse" + */ + public PWMSparkMax(final int channel) { + super(channel); + + setBounds(2.003, 1.55, 1.50, 1.46, .999); + setPeriodMultiplier(PeriodMultiplier.k1X); + setSpeed(0.0); + setZeroLatch(); + + HAL.report(tResourceType.kResourceType_RevSparkMaxPWM, getChannel()); + setName("PWMSparkMax", getChannel()); + } +}