Add SPARK and SD540 motor controllers

Change-Id: I33f9c588b6d535b1f274d211563ef146f34439b1
This commit is contained in:
Kevin O'Connor
2015-12-11 16:37:53 -05:00
parent 9316933454
commit fa903dd9ce
7 changed files with 486 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "SafePWM.h"
#include "SpeedController.h"
#include "PIDOutput.h"
/**
* Mindsensors SD540 Speed Controller
*/
class SD540 : public SafePWM, public SpeedController {
public:
explicit SD540(uint32_t channel);
virtual ~SD540() = default;
virtual void Set(float value, uint8_t syncGroup = 0) override;
virtual float Get() const override;
virtual void Disable() override;
virtual void PIDWrite(float output) override;
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
private:
bool m_isInverted = false;
};

View File

@@ -0,0 +1,31 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "SafePWM.h"
#include "SpeedController.h"
#include "PIDOutput.h"
/**
* REV Robotics Speed Controller
*/
class Spark : public SafePWM, public SpeedController {
public:
explicit Spark(uint32_t channel);
virtual ~Spark() = default;
virtual void Set(float value, uint8_t syncGroup = 0) override;
virtual float Get() const override;
virtual void Disable() override;
virtual void PIDWrite(float output) override;
virtual void SetInverted(bool isInverted) override;
virtual bool GetInverted() const override;
private:
bool m_isInverted = false;
};

View File

@@ -71,6 +71,7 @@
#include "Resource.h"
#include "RobotBase.h"
#include "RobotDrive.h"
#include "SD540.h"
#include "SensorBase.h"
#include "SerialPort.h"
#include "Servo.h"
@@ -78,6 +79,7 @@
#include "SmartDashboard/SendableChooser.h"
#include "SmartDashboard/SmartDashboard.h"
#include "Solenoid.h"
#include "Spark.h"
#include "SpeedController.h"
#include "SPI.h"
#include "Talon.h"

View File

@@ -0,0 +1,88 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#include "SD540.h"
#include "LiveWindow/LiveWindow.h"
/**
* Note that the SD540 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 SD540 User Manual available
* from Mindsensors.
*
* 2.05ms = full "forward"
* 1.55ms = the "high end" of the deadband range
* 1.50ms = center of the deadband range (off)
* 1.44ms = the "low end" of the deadband range
* 0.94ms = full "reverse"
*/
/**
* Constructor for a SD540
* @param channel The PWM channel that the SD540 is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
SD540::SD540(uint32_t channel) : SafePWM(channel) {
SetBounds(2.05, 1.55, 1.50, 1.44, .94);
SetPeriodMultiplier(kPeriodMultiplier_1X);
SetRaw(m_centerPwm);
SetZeroLatch();
HALReport(HALUsageReporting::kResourceType_MindsensorsSD540, GetChannel());
LiveWindow::GetInstance()->AddActuator("SD540", GetChannel(), this);
}
/**
* Set the PWM value.
*
* The PWM value is set using a range of -1.0 to 1.0, appropriately
* scaling the value for the FPGA.
*
* @param speed The speed value between -1.0 and 1.0 to set.
* @param syncGroup Unused interface.
*/
void SD540::Set(float speed, uint8_t syncGroup) {
SetSpeed(m_isInverted ? -speed : speed);
}
/**
* Get the recently set value of the PWM.
*
* @return The most recently set value for the PWM between -1.0 and 1.0.
*/
float SD540::Get() const { return GetSpeed(); }
/**
* Common interface for inverting direction of a speed controller.
* @param isInverted The state of inversion, true is inverted.
*/
void SD540::SetInverted(bool isInverted) { m_isInverted = isInverted; }
/**
* Common interface for the inverting direction of a speed controller.
*
* @return isInverted The state of inversion, true is inverted.
*
*/
bool SD540::GetInverted() const { return m_isInverted; }
/**
* Common interface for disabling a motor.
*/
void SD540::Disable() { SetRaw(kPwmDisabled); }
/**
* Write out the PID value as seen in the PIDOutput base object.
*
* @param output Write out the PWM value as was found in the PIDController
*/
void SD540::PIDWrite(float output) { Set(output); }

View File

@@ -0,0 +1,88 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#include "Spark.h"
#include "LiveWindow/LiveWindow.h"
/**
* 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
* 0.999ms = full "reverse"
*/
/**
* Constructor for a Spark
* @param channel The PWM channel that the Spark is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
Spark::Spark(uint32_t channel) : SafePWM(channel) {
SetBounds(2.003, 1.55, 1.50, 1.46, .999);
SetPeriodMultiplier(kPeriodMultiplier_1X);
SetRaw(m_centerPwm);
SetZeroLatch();
HALReport(HALUsageReporting::kResourceType_RevSPARK, GetChannel());
LiveWindow::GetInstance()->AddActuator("Spark", GetChannel(), this);
}
/**
* Set the PWM value.
*
* The PWM value is set using a range of -1.0 to 1.0, appropriately
* scaling the value for the FPGA.
*
* @param speed The speed value between -1.0 and 1.0 to set.
* @param syncGroup Unused interface.
*/
void Spark::Set(float speed, uint8_t syncGroup) {
SetSpeed(m_isInverted ? -speed : speed);
}
/**
* Get the recently set value of the PWM.
*
* @return The most recently set value for the PWM between -1.0 and 1.0.
*/
float Spark::Get() const { return GetSpeed(); }
/**
* Common interface for inverting direction of a speed controller.
* @param isInverted The state of inversion, true is inverted.
*/
void Spark::SetInverted(bool isInverted) { m_isInverted = isInverted; }
/**
* Common interface for the inverting direction of a speed controller.
*
* @return isInverted The state of inversion, true is inverted.
*
*/
bool Spark::GetInverted() const { return m_isInverted; }
/**
* Common interface for disabling a motor.
*/
void Spark::Disable() { SetRaw(kPwmDisabled); }
/**
* Write out the PID value as seen in the PIDOutput base object.
*
* @param output Write out the PWM value as was found in the PIDController
*/
void Spark::PIDWrite(float output) { Set(output); }

View File

@@ -0,0 +1,123 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. 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.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
/**
* Mindsensors SD540 Speed Controller
*/
public class SD540 extends SafePWM implements SpeedController {
private boolean isInverted = false;
/**
* Common initialization code called by all constructors.
*
* Note that the SD540 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 SD540 User
* Manual available from Mindsensors.
*
* - 2.05ms = full "forward" - 1.55ms = the "high end" of the deadband range
* - 1.50ms = center of the deadband range (off) - 1.44ms = the "low end" of
* the deadband range - .94ms = full "reverse"
*/
protected void initSD540() {
setBounds(2.05, 1.55, 1.50, 1.44, .94);
setPeriodMultiplier(PeriodMultiplier.k1X);
setRaw(m_centerPwm);
setZeroLatch();
LiveWindow.addActuator("SD540", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_MindsensorsSD540, getChannel());
}
/**
* Constructor.
*
* @param channel The PWM channel that the SD540 is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
public SD540(final int channel) {
super(channel);
initSD540();
}
/**
* Set the PWM value.
*
* @deprecated For compatibility with CANJaguar
*
* The PWM value is set using a range of -1.0 to 1.0,
* appropriately scaling the value for the FPGA.
*
* @param speed The speed to set. Value should be between -1.0 and 1.0.
* @param syncGroup The update group to add this Set() to, pending
* UpdateSyncGroup(). If 0, update immediately.
*/
public void set(double speed, byte syncGroup) {
setSpeed(isInverted ? -speed : speed);
Feed();
}
/**
* Set the PWM value.
*
* The PWM value is set using a range of -1.0 to 1.0, appropriately scaling
* the value for the FPGA.
*
* @param speed The speed value between -1.0 and 1.0 to set.
*/
public void set(double speed) {
setSpeed(isInverted ? -speed : speed);
Feed();
}
/**
* Common interface for inverting direction of a speed controller
*
* @param isInverted The state of inversion true is inverted
*/
@Override
public void setInverted(boolean isInverted) {
this.isInverted = isInverted;
}
/**
* Common interface for the inverting direction of a speed controller.
*
* @return isInverted The state of inversion, true is inverted.
*
*/
@Override
public boolean getInverted() {
return this.isInverted;
}
/**
* Get the recently set value of the PWM.
*
* @return The most recently set value for the PWM between -1.0 and 1.0.
*/
public double get() {
return getSpeed();
}
/**
* Write out the PID value as seen in the PIDOutput base object.
*
* @param output Write out the PWM value as was found in the PIDController
*/
public void pidWrite(double output) {
set(output);
}
}

View File

@@ -0,0 +1,123 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. 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.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
/**
* REV Robotics SPARK Speed Controller
*/
public class Spark extends SafePWM implements SpeedController {
private boolean isInverted = false;
/**
* 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"
*/
protected void initSpark() {
setBounds(2.003, 1.55, 1.50, 1.46, .999);
setPeriodMultiplier(PeriodMultiplier.k1X);
setRaw(m_centerPwm);
setZeroLatch();
LiveWindow.addActuator("Spark", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_RevSPARK, getChannel());
}
/**
* Constructor.
*
* @param channel The PWM channel that the SPARK is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
public Spark(final int channel) {
super(channel);
initSpark();
}
/**
* Set the PWM value.
*
* @deprecated For compatibility with CANJaguar
*
* The PWM value is set using a range of -1.0 to 1.0,
* appropriately scaling the value for the FPGA.
*
* @param speed The speed to set. Value should be between -1.0 and 1.0.
* @param syncGroup The update group to add this Set() to, pending
* UpdateSyncGroup(). If 0, update immediately.
*/
public void set(double speed, byte syncGroup) {
setSpeed(isInverted ? -speed : speed);
Feed();
}
/**
* Set the PWM value.
*
* The PWM value is set using a range of -1.0 to 1.0, appropriately scaling
* the value for the FPGA.
*
* @param speed The speed value between -1.0 and 1.0 to set.
*/
public void set(double speed) {
setSpeed(isInverted ? -speed : speed);
Feed();
}
/**
* Common interface for inverting direction of a speed controller
*
* @param isInverted The state of inversion true is inverted
*/
@Override
public void setInverted(boolean isInverted) {
this.isInverted = isInverted;
}
/**
* Common interface for the inverting direction of a speed controller.
*
* @return isInverted The state of inversion, true is inverted.
*
*/
@Override
public boolean getInverted() {
return this.isInverted;
}
/**
* Get the recently set value of the PWM.
*
* @return The most recently set value for the PWM between -1.0 and 1.0.
*/
public double get() {
return getSpeed();
}
/**
* Write out the PID value as seen in the PIDOutput base object.
*
* @param output Write out the PWM value as was found in the PIDController
*/
public void pidWrite(double output) {
set(output);
}
}