mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Added nicer Java interface for Talon SRX -- throttle mode works.
Change-Id: Ia6f4997b4836826f56a3dd4c8f7f29a0bf62d94c
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* This file was automatically generated by SWIG (http://www.swig.org).
|
||||
* Version 2.0.11
|
||||
*
|
||||
* Do not make changes to this file unless you know what you are doing--modify
|
||||
* the SWIG interface file instead.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.CanTalonSRX;
|
||||
|
||||
public class CANTalon implements MotorSafety, PIDOutput, SpeedController {
|
||||
private MotorSafetyHelper m_safetyHelper;
|
||||
public enum ControlMode {
|
||||
PercentVbus(0), Follower(1), Voltage(2), Position(3), Speed(4), Current(5), Disabled(15);
|
||||
|
||||
public int value;
|
||||
|
||||
public static ControlMode valueOf(int value) {
|
||||
for(ControlMode mode : values()) {
|
||||
if(mode.value == value) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ControlMode(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private CanTalonSRX m_impl;
|
||||
|
||||
int m_deviceNumber;
|
||||
boolean m_controlEnabled;
|
||||
|
||||
public CANTalon(int deviceNumber) {
|
||||
m_deviceNumber = deviceNumber;
|
||||
m_impl = new CanTalonSRX(deviceNumber);
|
||||
m_safetyHelper = new MotorSafetyHelper(this);
|
||||
m_controlEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pidWrite(double output) {
|
||||
set(output);
|
||||
}
|
||||
|
||||
public void set(double outputValue) {
|
||||
m_impl.Set(outputValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(double outputValue, byte thisValueDoesNotDoAnything) {
|
||||
set(outputValue);
|
||||
}
|
||||
|
||||
public double get() {
|
||||
// TODO
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// Only supports kPercentVbus mode for now.
|
||||
public void enableControl() {
|
||||
m_impl.SetModeSelect(ControlMode.PercentVbus.value);
|
||||
m_controlEnabled = true;
|
||||
}
|
||||
|
||||
public void disableControl() {
|
||||
m_impl.SetModeSelect(ControlMode.Disabled.value);
|
||||
m_controlEnabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common interface for stopping a motor.
|
||||
*
|
||||
* @deprecated Use disableControl instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void stopMotor() {
|
||||
disableControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
disableControl();
|
||||
}
|
||||
|
||||
public int getDeviceID() {
|
||||
return m_deviceNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpiration(double timeout) {
|
||||
m_safetyHelper.setExpiration(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getExpiration() {
|
||||
return m_safetyHelper.getExpiration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
return m_safetyHelper.isAlive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSafetyEnabled() {
|
||||
return m_safetyHelper.isSafetyEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSafetyEnabled(boolean enabled) {
|
||||
m_safetyHelper.setSafetyEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "CANJaguar ID "+m_deviceNumber;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user