Merge "Updated the HAL, wpilibj, and wpilibc for PCM and PDP"

This commit is contained in:
Brad Miller (WPI)
2014-07-02 14:04:51 -07:00
committed by Gerrit Code Review
17 changed files with 42 additions and 50 deletions

View File

@@ -2,21 +2,20 @@
#include "ctre/PCM.h"
#include <iostream>
static const int NUM_PCMS = 2;
extern PCM *modules[NUM_PCMS];
extern void initializePCM();
static const int NUM_MODULE_NUMBERS = 63;
extern PCM *modules[NUM_MODULE_NUMBERS];
extern void initializePCM(int module);
void *initializeCompressor(uint8_t module) {
initializePCM();
initializePCM(module);
return modules[module - 1];
return modules[module];
}
bool checkCompressorModule(uint8_t module) {
return module > 0 and module <= NUM_PCMS;
return module < NUM_MODULE_NUMBERS;
}
bool getCompressor(void *pcm_pointer, int32_t *status) {
PCM *module = (PCM *)pcm_pointer;
bool value;

View File

@@ -8,39 +8,34 @@
#include "NetworkCommunication/LoadOut.h"
#include "ctre/PCM.h"
bool pcmModulesInitialized = false;
static const int NUM_MODULE_NUMBERS = 63;
static const int NUM_PCMS = 2;
PCM *modules[NUM_PCMS];
PCM *modules[NUM_MODULE_NUMBERS] = { NULL };
struct solenoid_port_t {
PCM *module;
uint32_t pin;
};
void initializePCM() {
if(!pcmModulesInitialized) {
modules[0] = new PCM(50);
modules[1] = new PCM(51);
pcmModulesInitialized = true;
void initializePCM(int module) {
if(!modules[module]) {
modules[module] = new PCM(module);
}
}
void* initializeSolenoidPort(void *port_pointer, int32_t *status) {
initializePCM();
Port* port = (Port*) port_pointer;
initializePCM(port->module);
solenoid_port_t *solenoid_port = new solenoid_port_t;
solenoid_port->module = modules[port->module - 1];
solenoid_port->module = modules[port->module];
solenoid_port->pin = port->pin;
return solenoid_port;
}
bool checkSolenoidModule(uint8_t module) {
return module > 0 and module <= NUM_PCMS;
return module < NUM_MODULE_NUMBERS;
}
bool getSolenoid(void* solenoid_port_pointer, int32_t *status) {

View File

@@ -1,4 +1,3 @@
#if 0
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#include "PCM.h"
@@ -453,4 +452,3 @@ extern "C" {
return retval;
}
}
#endif

View File

@@ -23,7 +23,7 @@ public:
static uint32_t GetDefaultSolenoidModule()
{
return 1;
return 0;
}
static bool CheckSolenoidModule(uint8_t moduleNumber);

View File

@@ -47,7 +47,7 @@ PowerDistributionPanel::GetTemperature() {
}
/**
* @return The current of one of the PDP channels (channels 1-16) in Amperes
* @return The current of one of the PDP channels (channels 0-15) in Amperes
*/
double
PowerDistributionPanel::GetCurrent(uint8_t channel) {

View File

@@ -153,7 +153,7 @@ bool SensorBase::CheckAnalogOutput(uint32_t channel)
*/
bool SensorBase::CheckSolenoidChannel(uint32_t channel)
{
if (channel > 0 && channel <= kSolenoidChannels)
if (channel < kSolenoidChannels)
return true;
return false;
}
@@ -165,7 +165,7 @@ bool SensorBase::CheckSolenoidChannel(uint32_t channel)
*/
bool SensorBase::CheckPDPChannel(uint32_t channel)
{
if (channel > 0 && channel <= kPDPChannels)
if (channel < kPDPChannels)
return true;
return false;
}

View File

@@ -31,14 +31,14 @@ void Solenoid::InitSolenoid()
Resource::CreateResourceObject(&m_allocated, solenoid_kNumDO7_0Elements * kSolenoidChannels);
snprintf(buf, 64, "Solenoid %d (Module: %d)", m_channel, m_moduleNumber);
if (m_allocated->Allocate((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1, buf) == ~0ul)
if (m_allocated->Allocate(m_moduleNumber * kSolenoidChannels + m_channel, buf) == ~0ul)
{
CloneError(m_allocated);
return;
}
LiveWindow::GetInstance()->AddActuator("Solenoid", m_moduleNumber, m_channel, this);
HALReport(HALUsageReporting::kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_Solenoid, m_channel, m_moduleNumber);
}
/**
@@ -73,7 +73,7 @@ Solenoid::~Solenoid()
{
if (CheckSolenoidModule(m_moduleNumber))
{
m_allocated->Free((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1);
m_allocated->Free(m_moduleNumber * kSolenoidChannels + m_channel);
}
}
@@ -86,7 +86,7 @@ void Solenoid::Set(bool on)
{
if (StatusIsFatal()) return;
uint8_t value = on ? 0xFF : 0x00;
uint8_t mask = 1 << (m_channel - 1);
uint8_t mask = 1 << m_channel;
SolenoidBase::Set(value, mask);
}
@@ -99,7 +99,7 @@ void Solenoid::Set(bool on)
bool Solenoid::Get()
{
if (StatusIsFatal()) return false;
uint8_t value = GetAll() & ( 1 << (m_channel - 1));
uint8_t value = GetAll() & ( 1 << m_channel);
return (value != 0);
}

View File

@@ -19,7 +19,7 @@ SolenoidBase::SolenoidBase(uint8_t moduleNumber)
{
for (uint32_t i = 0; i < kSolenoidChannels; i++)
{
void* port = getPortWithModule(moduleNumber, i+1);
void* port = getPortWithModule(moduleNumber, i);
int32_t status = 0;
m_ports[i] = initializeSolenoidPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));

View File

@@ -55,7 +55,7 @@ public:
static const uint32_t kCANJaguarID = 2;
/* PDP channels */
static const uint32_t kJaguarPDPChannel = 7;
static const uint32_t kVictorPDPChannel = 11;
static const uint32_t kTalonPDPChannel = 12;
static const uint32_t kJaguarPDPChannel = 6;
static const uint32_t kVictorPDPChannel = 10;
static const uint32_t kTalonPDPChannel = 11;
};

View File

@@ -37,8 +37,8 @@ protected:
m_fakePressureSwitch = new DigitalOutput(TestBench::kFakePressureSwitchChannel);
m_fakeCompressor = new AnalogInput(TestBench::kFakeCompressorChannel);
m_solenoid1 = new Solenoid(1);
m_solenoid2 = new Solenoid(2);
m_solenoid1 = new Solenoid(0);
m_solenoid2 = new Solenoid(1);
m_fakeSolenoid1 = new DigitalInput(TestBench::kFakeSolenoid1Channel);
m_fakeSolenoid2 = new DigitalInput(TestBench::kFakeSolenoid2Channel);

View File

@@ -47,7 +47,7 @@ public class PowerDistributionPanel extends SensorBase {
}
/**
* @return The current of one of the PDP channels (channels 1-16) in Amperes
* @return The current of one of the PDP channels (channels 0-15) in Amperes
*/
public double getCurrent(int channel) {
ByteBuffer status = ByteBuffer.allocateDirect(4);

View File

@@ -69,7 +69,7 @@ public abstract class SensorBase { // TODO: Refactor
private static int m_defaultAnalogModule = 1;
private static int m_defaultDigitalModule = 1;
private static int m_defaultSolenoidModule = 1;
private static int m_defaultSolenoidModule = 0;
/**
* Creates an instance of the sensor base and gets an FPGA handle
@@ -242,7 +242,7 @@ public abstract class SensorBase { // TODO: Refactor
* @param channel The channel number to check.
*/
protected static void checkSolenoidChannel(final int channel) {
if (channel <= 0 || channel > kSolenoidChannels) {
if (channel < 0 || channel >= kSolenoidChannels) {
System.err.println("Requested solenoid channel number is out of range.");
}
}
@@ -254,7 +254,7 @@ public abstract class SensorBase { // TODO: Refactor
* @param channel The channel number to check.
*/
protected static void checkPDPChannel(final int channel) {
if (channel <= 0 || channel > kPDPChannels) {
if (channel < 0 || channel >= kPDPChannels) {
System.err.println("Requested solenoid channel number is out of range.");
}
}

View File

@@ -54,7 +54,7 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
HALUtil.checkStatus(status.asIntBuffer());
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber);
}
/**

View File

@@ -30,7 +30,7 @@ public abstract class SolenoidBase extends SensorBase implements IDeviceControll
* @param moduleNumber The number of the solenoid module to use.
*/
public SolenoidBase(final int moduleNumber) {
// m_moduleNumber = moduleNumber;
m_moduleNumber = moduleNumber;
// m_ports = new ByteBuffer[SensorBase.kSolenoidChannels];
// for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
// ByteBuffer port = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) (i+1));

View File

@@ -54,8 +54,8 @@ public class PCMTest extends AbstractComsSetup {
fakePressureSwitch = new DigitalOutput(11);
fakeCompressor = new AnalogInput(1);
solenoid1 = new Solenoid(1);
solenoid2 = new Solenoid(2);
solenoid1 = new Solenoid(0);
solenoid2 = new Solenoid(1);
fakeSolenoid1 = new DigitalInput(12);
fakeSolenoid2 = new DigitalInput(13);

View File

@@ -56,9 +56,9 @@ public final class TestBench {
/* PowerDistributionPanel channels */
public static final int kJaguarPDPChannel = 7;
public static final int kVictorPDPChannel = 11;
public static final int kTalonPDPChannel = 12;
public static final int kJaguarPDPChannel = 6;
public static final int kVictorPDPChannel = 10;
public static final int kTalonPDPChannel = 11;
/* CAN ASSOICATED CHANNELS */
public static final int kFakeJaguarPotentiometer = 1;

View File

@@ -51,7 +51,7 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWith
(JNIEnv *env, jclass, jbyte module, jbyte channel)
{
VoidPointer *port_pointer = new VoidPointer;
*port_pointer = getPortWithModule(module + 1, channel);
*port_pointer = getPortWithModule(module, channel);
return env->NewDirectByteBuffer(port_pointer, 4);
}