Compare commits

...

6 Commits

Author SHA1 Message Date
Kevin O'Connor
0e46592ad1 Don't send DS errors if no DS.
Change-Id: I765d8c21371e772ec09bf696f6dd2fff43f8ed24
2015-02-23 16:19:16 -05:00
Brad Miller (WPI)
d2edb80da2 Merge "Use PCM Device ID when getting status. Fixes artf4014." 2015-02-23 13:15:26 -08:00
Brad Miller
6159fde98e Set POV values on error to return -1 rather than 0 AND bump the version number (artf4005)
Change-Id: I6fffb693a8e58427086b9f9a673cd70bebdbca33
2015-02-20 18:35:38 -05:00
Joe Ross
7bdd91a058 Use PCM Device ID when getting status. Fixes artf4014.
Change-Id: I0e1f478d1b96d20b97dec8d0ffe251c8fd0f6897
2015-02-15 16:43:09 -08:00
Kevin O'Connor
605bb45e0c Fix endian order of buffers in AnalogTrigger.java
Change-Id: Ica262494c4b8169d812295006e24f9cb440de078
2015-02-13 11:16:55 -05:00
Brad Miller
215002e487 Fix analog trigger bug with MXP mapping (artf4010)
Add the interrupt code for MXP mapping and analog triggers
Took out the unneeded static definition
Change-Id: I9a3483ee8f806b46b4349845e7a189f497c36916
2015-02-12 17:33:31 -05:00
8 changed files with 77 additions and 56 deletions

View File

@@ -632,6 +632,25 @@ void setCounterAverageSize(void* counter_pointer, int32_t size, int32_t *status)
counter->counter->writeTimerConfig_AverageSize(size, status);
}
/**
* remap the digital source pin and set the module.
* If it's an analog trigger, determine the module from the high order routing channel
* else do normal digital input remapping based on pin number (MXP)
*/
void remapDigitalSource(bool analogTrigger, uint32_t &pin, uint8_t &module) {
if (analogTrigger) {
module = pin >> 4;
} else {
if(pin >= kNumHeaders) {
pin = remapMXPChannel(pin);
module = 1;
} else {
module = 0;
}
}
}
/**
* Set the source object that causes the counter to count up.
* Set the up counting DigitalSource.
@@ -641,12 +660,7 @@ void setCounterUpSource(void* counter_pointer, uint32_t pin, bool analogTrigger,
uint8_t module;
if(pin >= kNumHeaders) {
pin = remapMXPChannel(pin);
module = 1;
} else {
module = 0;
}
remapDigitalSource(analogTrigger, pin, module);
counter->counter->writeConfig_UpSource_Module(module, status);
counter->counter->writeConfig_UpSource_Channel(pin, status);
@@ -696,12 +710,7 @@ void setCounterDownSource(void* counter_pointer, uint32_t pin, bool analogTrigge
uint8_t module;
if(pin >= kNumHeaders) {
pin = remapMXPChannel(pin);
module = 1;
} else {
module = 0;
}
remapDigitalSource(analogTrigger, pin, module);
counter->counter->writeConfig_DownSource_Module(module, status);
counter->counter->writeConfig_DownSource_Channel(pin, status);
@@ -925,15 +934,8 @@ void* initializeEncoder(uint8_t port_a_module, uint32_t port_a_pin, bool port_a_
// Initialize encoder structure
Encoder* encoder = new Encoder();
if(port_a_pin >= kNumHeaders) {
port_a_pin = remapMXPChannel(port_a_pin);
port_a_module = 1;
}
if(port_b_pin >= kNumHeaders) {
port_b_pin = remapMXPChannel(port_b_pin);
port_b_module = 1;
}
remapDigitalSource(port_a_analog_trigger, port_a_pin, port_a_module);
remapDigitalSource(port_b_analog_trigger, port_b_pin, port_b_module);
Resource::CreateResourceObject(&quadEncoders, tEncoder::kNumSystems);
encoder->index = quadEncoders->Allocate("4X Encoder");

View File

@@ -1,6 +1,8 @@
#include "HAL/Interrupts.hpp"
#include "ChipObject.h"
extern void remapDigitalSource(bool analogTrigger, uint32_t &pin, uint8_t &module);
struct Interrupt // FIXME: why is this internal?
{
tInterrupt *anInterrupt;
@@ -99,6 +101,7 @@ void requestInterrupts(void* interrupt_pointer, uint8_t routing_module, uint32_t
{
Interrupt* anInterrupt = (Interrupt*)interrupt_pointer;
anInterrupt->anInterrupt->writeConfig_WaitForAck(false, status);
remapDigitalSource(routing_analog_trigger, routing_pin, routing_module);
anInterrupt->anInterrupt->writeConfig_Source_AnalogTrigger(routing_analog_trigger, status);
anInterrupt->anInterrupt->writeConfig_Source_Channel(routing_pin, status);
anInterrupt->anInterrupt->writeConfig_Source_Module(routing_module, status);

View File

@@ -13,9 +13,9 @@ static const INT32 kCANPeriod = 20;
#define STATUS_DEBUG 0x9041480
#define EXPECTED_RESPONSE_TIMEOUT_MS (50)
#define GET_PCM_STATUS() CtreCanNode::recMsg<PcmStatus_t> rx = GetRx<PcmStatus_t> (STATUS_1,EXPECTED_RESPONSE_TIMEOUT_MS)
#define GET_PCM_SOL_FAULTS() CtreCanNode::recMsg<PcmStatusFault_t> rx = GetRx<PcmStatusFault_t> (STATUS_SOL_FAULTS,EXPECTED_RESPONSE_TIMEOUT_MS)
#define GET_PCM_DEBUG() CtreCanNode::recMsg<PcmDebug_t> rx = GetRx<PcmDebug_t> (STATUS_DEBUG,EXPECTED_RESPONSE_TIMEOUT_MS)
#define GET_PCM_STATUS() CtreCanNode::recMsg<PcmStatus_t> rx = GetRx<PcmStatus_t> (STATUS_1|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
#define GET_PCM_SOL_FAULTS() CtreCanNode::recMsg<PcmStatusFault_t> rx = GetRx<PcmStatusFault_t> (STATUS_SOL_FAULTS|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
#define GET_PCM_DEBUG() CtreCanNode::recMsg<PcmDebug_t> rx = GetRx<PcmDebug_t> (STATUS_DEBUG|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
#define CONTROL_1 0x09041C00 /* PCM_Control */
#define CONTROL_2 0x09041C40 /* PCM_SupplemControl */

View File

@@ -270,7 +270,7 @@ int DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) {
if (stick >= kJoystickPorts)
{
wpi_setWPIError(BadJoystickIndex);
return 0;
return -1;
}
if (pov >= m_joystickPOVs[stick].count)
@@ -279,7 +279,7 @@ int DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) {
wpi_setWPIError(BadJoystickAxis);
else
ReportJoystickUnpluggedError("WARNING: Joystick POV missing, check if all controllers are plugged in\n");
return 0;
return -1;
}
return m_joystickPOVs[stick].povs[pov];
@@ -530,5 +530,11 @@ double DriverStation::GetMatchTime()
void DriverStation::ReportError(std::string error)
{
std::cout << error << std::endl;
HALSetErrorData(error.c_str(), error.size(), 0);
HALControlWord controlWord;
HALGetControlWord(&controlWord);
if(controlWord.dsAttached)
{
HALSetErrorData(error.c_str(), error.size(), 0);
}
}

View File

@@ -65,7 +65,7 @@ RobotBase::RobotBase()
FILE *file = NULL;
file = fopen("/tmp/frc_versions/FRC_Lib_Version.ini", "w");
fputs("2015 C++ 1.1.0", file);
fputs("2015 C++ 1.2.0", file);
if (file != NULL)
fclose(file);
}

View File

@@ -15,6 +15,7 @@ import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.util.BoundaryException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
//import com.sun.jna.Pointer;
@@ -57,12 +58,14 @@ public class AnalogTrigger {
*/
protected void initTrigger(final int channel) {
ByteBuffer port_pointer = AnalogJNI.getPort((byte) channel);
IntBuffer index = ByteBuffer.allocateDirect(4).asIntBuffer();
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
ByteBuffer index = ByteBuffer.allocateDirect(4);
ByteBuffer status = ByteBuffer.allocateDirect(4);
index.order(ByteOrder.LITTLE_ENDIAN);
status.order(ByteOrder.LITTLE_ENDIAN);
m_port = AnalogJNI.initializeAnalogTrigger(port_pointer, index, status);
HALUtil.checkStatus(status);
m_index = index.get(0);
m_port = AnalogJNI.initializeAnalogTrigger(port_pointer, index.asIntBuffer(), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
m_index = index.asIntBuffer().get(0);
UsageReporting.report(tResourceType.kResourceType_AnalogTrigger, channel);
}
@@ -96,9 +99,10 @@ public class AnalogTrigger {
* Release the resources used by this object
*/
public void free() {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
AnalogJNI.cleanAnalogTrigger(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.cleanAnalogTrigger(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
m_port = null;
}
@@ -116,9 +120,10 @@ public class AnalogTrigger {
if (lower > upper) {
throw new BoundaryException("Lower bound is greater than upper");
}
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -135,10 +140,11 @@ public class AnalogTrigger {
throw new BoundaryException(
"Lower bound is greater than upper bound");
}
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, (float) lower,
(float) upper, status);
HALUtil.checkStatus(status);
(float) upper, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -150,10 +156,11 @@ public class AnalogTrigger {
* true to use an averaged value, false otherwise
*/
public void setAveraged(boolean useAveragedValue) {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogTriggerAveraged(m_port,
(byte) (useAveragedValue ? 1 : 0), status);
HALUtil.checkStatus(status);
(byte) (useAveragedValue ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -166,10 +173,11 @@ public class AnalogTrigger {
* true to use a filterd value, false otherwise
*/
public void setFiltered(boolean useFilteredValue) {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogTriggerFiltered(m_port,
(byte) (useFilteredValue ? 1 : 0), status);
HALUtil.checkStatus(status);
(byte) (useFilteredValue ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -189,9 +197,10 @@ public class AnalogTrigger {
* @return The InWindow output of the analog trigger.
*/
public boolean getInWindow() {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
byte value = AnalogJNI.getAnalogTriggerInWindow(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
byte value = AnalogJNI.getAnalogTriggerInWindow(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value != 0;
}
@@ -203,9 +212,10 @@ public class AnalogTrigger {
* @return The TriggerState output of the analog trigger.
*/
public boolean getTriggerState() {
IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer();
byte value = AnalogJNI.getAnalogTriggerTriggerState(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
byte value = AnalogJNI.getAnalogTriggerTriggerState(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value != 0;
}

View File

@@ -267,7 +267,7 @@ public class DriverStation implements RobotState.Interface {
if (pov >= m_joystickPOVs[stick].length) {
reportJoystickUnpluggedError("WARNING: Joystick POV " + pov + " on port " + stick + " not available, check if controller is plugged in\n");
return 0;
return -1;
}
return m_joystickPOVs[stick][pov];

View File

@@ -216,7 +216,7 @@ public abstract class RobotBase {
output = new FileOutputStream(file);
output.write("2015 Java 1.1.0".getBytes());
output.write("2015 Java 1.2.0".getBytes());
} catch (IOException ex) {
ex.printStackTrace();