Squashed commit of the following:

commit a3ccfab0a42414aa169792356bfc47ee8d0d2d7b
Author: Kevin O'Connor <koconnor@usfirst.org>
Date:   Tue Sep 23 13:56:59 2014 -0400

    Implement zero latch (used to reduce brownout latency) in Java

    Change-Id: I3bf4ffbf20cf3d8a42da4fa1755b4306c49ede34

commit 0af37dfcc0d1172974519c44126973c302385d55
Author: Kevin O'Connor <koconnor@usfirst.org>
Date:   Tue Sep 23 13:03:07 2014 -0400

    Implement zero latch (used to improve brownout latency) in C++

    Change-Id: I62bedd1af65d367c32e2ab0b5a4fc679776eecb5

Change-Id: Ic27f37a9ab45aad82c1f7154d4edfbccfaa19229
This commit is contained in:
Kevin O'Connor
2014-09-26 17:20:57 -04:00
parent 19b2d05236
commit d72ee199fe
13 changed files with 50 additions and 10 deletions

View File

@@ -24,6 +24,7 @@ extern "C"
bool allocatePWMChannel(void* digital_port_pointer, int32_t *status);
void freePWMChannel(void* digital_port_pointer, int32_t *status);
unsigned short getPWM(void* digital_port_pointer, int32_t *status);
void latchPWMZero(void* digital_port_pointer, int32_t *status);
void setPWMPeriodScale(void* digital_port_pointer, uint32_t squelchMask, int32_t *status);
void* allocatePWM(int32_t *status);
void freePWM(void* pwmGenerator, int32_t *status);

View File

@@ -217,6 +217,12 @@ unsigned short getPWM(void* digital_port_pointer, int32_t *status) {
}
}
void latchPWMZero(void* digital_port_pointer, int32_t *status) {
DigitalPort* port = (DigitalPort*) digital_port_pointer;
pwmSystem->writeZeroLatch(1 << port->port.pin, true, status);
pwmSystem->writeZeroLatch(1 << port->port.pin, false, status);
}
/**
* Set how how often the PWM signal is squelched, thus scaling the period.
*

View File

@@ -40,6 +40,7 @@ public:
virtual void SetRaw(unsigned short value);
virtual unsigned short GetRaw();
void SetPeriodMultiplier(PeriodMultiplier mult);
void SetZeroLatch();
void EnableDeadbandElimination(bool eliminateDeadband);
void SetBounds(int32_t max, int32_t deadbandMax, int32_t center, int32_t deadbandMin,
int32_t min);

View File

@@ -26,6 +26,7 @@ void Jaguar::InitJaguar()
SetBounds(2.31, 1.55, 1.507, 1.454, .697);
SetPeriodMultiplier(kPeriodMultiplier_1X);
SetRaw(m_centerPwm);
SetZeroLatch();
HALReport(HALUsageReporting::kResourceType_Jaguar, GetChannel());
LiveWindow::GetInstance()->AddActuator("Jaguar", GetChannel(), this);

View File

@@ -352,6 +352,16 @@ void PWM::SetPeriodMultiplier(PeriodMultiplier mult)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
void PWM::SetZeroLatch()
{
if (StatusIsFatal()) return;
int32_t status = 0;
latchPWMZero(m_pwm_ports[m_channel], &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
void PWM::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) {
SetSpeed(value.f);

View File

@@ -27,6 +27,7 @@ void Talon::InitTalon() {
SetBounds(2.037, 1.539, 1.513, 1.487, .989);
SetPeriodMultiplier(kPeriodMultiplier_2X);
SetRaw(m_centerPwm);
SetZeroLatch();
HALReport(HALUsageReporting::kResourceType_Talon, GetChannel());
LiveWindow::GetInstance()->AddActuator("Talon", GetChannel(), this);

View File

@@ -29,6 +29,7 @@ void Victor::InitVictor() {
SetPeriodMultiplier(kPeriodMultiplier_2X);
SetRaw(m_centerPwm);
SetZeroLatch();
LiveWindow::GetInstance()->AddActuator("Victor", GetChannel(), this);
HALReport(HALUsageReporting::kResourceType_Victor, GetChannel());

View File

@@ -32,6 +32,7 @@ public class Jaguar extends SafePWM implements SpeedController {
setBounds(2.31, 1.55, 1.507, 1.454, .697);
setPeriodMultiplier(PeriodMultiplier.k1X);
setRaw(m_centerPwm);
setZeroLatch();
UsageReporting.report(tResourceType.kResourceType_Jaguar, getChannel());
LiveWindow.addActuator("Jaguar", getChannel(), this);

View File

@@ -393,37 +393,37 @@ public class PWM extends SensorBase implements LiveWindowSendable {
HALUtil.checkStatus(status.asIntBuffer());
}
protected void setZeroLatch()
{
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.latchPWMZero(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
private int getMaxPositivePwm() {
return m_maxPwm;
}
;
private int getMinPositivePwm() {
return m_eliminateDeadband ? m_deadbandMaxPwm : m_centerPwm + 1;
}
;
private int getCenterPwm() {
return m_centerPwm;
}
;
private int getMaxNegativePwm() {
return m_eliminateDeadband ? m_deadbandMinPwm : m_centerPwm - 1;
}
;
private int getMinNegativePwm() {
return m_minPwm;
}
;
private int getPositiveScaleFactor() {
return getMaxPositivePwm() - getMinPositivePwm();
} ///< The scale for positive speeds.

View File

@@ -34,6 +34,7 @@ public class Talon extends SafePWM implements SpeedController {
setBounds(2.037, 1.539, 1.513, 1.487, .989);
setPeriodMultiplier(PeriodMultiplier.k2X);
setRaw(m_centerPwm);
setZeroLatch();
LiveWindow.addActuator("Talon", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Talon, getChannel());

View File

@@ -36,6 +36,7 @@ public class Victor extends SafePWM implements SpeedController {
setBounds(2.027, 1.525, 1.507, 1.49, 1.026);
setPeriodMultiplier(PeriodMultiplier.k2X);
setRaw(m_centerPwm);
setZeroLatch();
LiveWindow.addActuator("Victor", getChannel(), this);
UsageReporting.report(tResourceType.kResourceType_Victor, getChannel());

View File

@@ -11,6 +11,7 @@ public class PWMJNI extends DIOJNI {
public static native void freePWMChannel(ByteBuffer digital_port_pointer, IntBuffer status);
public static native void setPWM(ByteBuffer digital_port_pointer, short value, IntBuffer status);
public static native short getPWM(ByteBuffer digital_port_pointer, IntBuffer status);
public static native void latchPWMZero(ByteBuffer digital_port_pointer, IntBuffer status);
public static native void setPWMPeriodScale(ByteBuffer digital_port_pointer, int squelchMask, IntBuffer status);
public static native ByteBuffer allocatePWM(IntBuffer status);
public static native void freePWM(ByteBuffer pwmGenerator, IntBuffer status);

View File

@@ -84,6 +84,21 @@ JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_getPWM
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: latchPWMZero
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_latchPWMZero
(JNIEnv * env, jclass, jobject id, jobject status)
{
void ** javaId = (void**)env->GetDirectBufferAddress(id);
PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId;
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
latchPWMZero( *javaId, statusPtr );
PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr;
}
/*
* Class: edu_wpi_first_wpilibj_hal_PWMJNI
* Method: setPWMPeriodScale