mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
artf4107: Removed most "Init" functions from classes
They were either replaced with delegating constructors or merged into the only constructor in the class. Change-Id: I3d35139f6ab23c719433a9f76942b02a3b07ddac
This commit is contained in:
@@ -131,7 +131,6 @@ class Command : public ErrorBase, public NamedSendable, public ITableListener {
|
||||
virtual void _Cancel();
|
||||
|
||||
private:
|
||||
void InitCommand(const char *name, double timeout);
|
||||
void LockChanges();
|
||||
/*synchronized*/ void Removed();
|
||||
void StartRunning();
|
||||
|
||||
@@ -19,36 +19,24 @@ static const char *kIsParented = "isParented";
|
||||
|
||||
int Command::m_commandCounter = 0;
|
||||
|
||||
void Command::InitCommand(const char *name, double timeout) {
|
||||
m_timeout = timeout;
|
||||
m_name = name == nullptr ? std::string() : name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new command.
|
||||
* The name of this command will be default.
|
||||
*/
|
||||
Command::Command() { InitCommand(nullptr, -1.0); }
|
||||
Command::Command() : Command(nullptr, -1.0) {}
|
||||
|
||||
/**
|
||||
* Creates a new command with the given name and no timeout.
|
||||
* @param name the name for this command
|
||||
*/
|
||||
Command::Command(const char *name) {
|
||||
if (name == nullptr) wpi_setWPIErrorWithContext(NullParameter, "name");
|
||||
InitCommand(name, -1.0);
|
||||
}
|
||||
Command::Command(const char *name) : Command(name, -1.0) {}
|
||||
|
||||
/**
|
||||
* Creates a new command with the given timeout and a default name.
|
||||
* @param timeout the time (in seconds) before this command "times out"
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
*/
|
||||
Command::Command(double timeout) {
|
||||
if (timeout < 0.0)
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
|
||||
InitCommand(nullptr, timeout);
|
||||
}
|
||||
Command::Command(double timeout) : Command(nullptr, timeout) {}
|
||||
|
||||
/**
|
||||
* Creates a new command with the given name and timeout.
|
||||
@@ -60,7 +48,9 @@ Command::Command(const char *name, double timeout) {
|
||||
if (name == nullptr) wpi_setWPIErrorWithContext(NullParameter, "name");
|
||||
if (timeout < 0.0)
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
|
||||
InitCommand(name, timeout);
|
||||
|
||||
m_timeout = timeout;
|
||||
m_name = name == nullptr ? std::string() : name;
|
||||
}
|
||||
|
||||
Command::~Command() { // TODO deal with cleaning up all listeners
|
||||
|
||||
@@ -75,7 +75,6 @@ class AnalogInput : public SensorBase,
|
||||
ITable *GetTable() const override;
|
||||
|
||||
private:
|
||||
void InitAnalogInput(uint32_t channel);
|
||||
uint32_t m_channel;
|
||||
void *m_port;
|
||||
int64_t m_accumulatorOffset;
|
||||
|
||||
@@ -30,7 +30,6 @@ class AnalogOutput : public SensorBase, public LiveWindowSendable {
|
||||
ITable *GetTable() const override;
|
||||
|
||||
protected:
|
||||
void InitAnalogOutput(uint32_t channel);
|
||||
uint32_t m_channel;
|
||||
void *m_port;
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@ class AnalogTrigger : public SensorBase {
|
||||
AnalogTriggerOutput *CreateOutput(AnalogTriggerType type);
|
||||
|
||||
private:
|
||||
void InitTrigger(uint32_t channel);
|
||||
|
||||
uint8_t m_index;
|
||||
void *m_trigger;
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ class Counter : public SensorBase,
|
||||
public CounterBase,
|
||||
public LiveWindowSendable {
|
||||
public:
|
||||
Counter();
|
||||
explicit Counter(Mode mode = kTwoPulse);
|
||||
explicit Counter(int32_t channel);
|
||||
explicit Counter(DigitalSource *source);
|
||||
explicit Counter(DigitalSource &source);
|
||||
@@ -87,8 +87,6 @@ class Counter : public SensorBase,
|
||||
DigitalSource *m_downSource = nullptr; ///< What makes the counter count down.
|
||||
void *m_counter = nullptr; ///< The FPGA counter object.
|
||||
private:
|
||||
void InitCounter(Mode mode = kTwoPulse);
|
||||
|
||||
bool m_allocatedUpSource = false; ///< Was the upSource allocated locally?
|
||||
bool m_allocatedDownSource = false; ///< Was the downSource allocated locally?
|
||||
uint32_t m_index = 0; ///< The index of this counter.
|
||||
|
||||
@@ -39,7 +39,6 @@ class DigitalInput : public DigitalSource, public LiveWindowSendable {
|
||||
ITable *GetTable() const;
|
||||
|
||||
private:
|
||||
void InitDigitalInput(uint32_t channel);
|
||||
uint32_t m_channel;
|
||||
bool m_lastValue;
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@ class DigitalOutput : public DigitalSource,
|
||||
ITable *GetTable() const;
|
||||
|
||||
private:
|
||||
void InitDigitalOutput(uint32_t channel);
|
||||
|
||||
uint32_t m_channel;
|
||||
void *m_pwmGenerator;
|
||||
|
||||
|
||||
@@ -42,8 +42,6 @@ class DoubleSolenoid : public SolenoidBase,
|
||||
ITable* GetTable() const;
|
||||
|
||||
private:
|
||||
virtual void InitSolenoid();
|
||||
|
||||
uint32_t m_forwardChannel; ///< The forward channel on the module to control.
|
||||
uint32_t m_reverseChannel; ///< The reverse channel on the module to control.
|
||||
uint8_t m_forwardMask; ///< The mask for the forward channel.
|
||||
|
||||
@@ -26,6 +26,5 @@ class Jaguar : public SafePWM, public SpeedController {
|
||||
virtual bool GetInverted() const override;
|
||||
|
||||
private:
|
||||
void InitJaguar();
|
||||
bool m_isInverted = false;
|
||||
};
|
||||
|
||||
@@ -102,7 +102,6 @@ class Joystick : public GenericHID, public ErrorBase {
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Joystick);
|
||||
void InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes);
|
||||
|
||||
DriverStation *m_ds = nullptr;
|
||||
uint32_t m_port;
|
||||
|
||||
@@ -109,7 +109,6 @@ class PWM : public SensorBase,
|
||||
ITable* m_table = nullptr;
|
||||
|
||||
private:
|
||||
void InitPWM(uint32_t channel);
|
||||
uint32_t m_channel;
|
||||
int32_t GetMaxPositivePwm() const { return m_maxPwm; }
|
||||
int32_t GetMinPositivePwm() const {
|
||||
|
||||
@@ -50,8 +50,6 @@ class Relay : public SensorBase,
|
||||
ITable* m_table = nullptr;
|
||||
|
||||
private:
|
||||
void InitRelay();
|
||||
|
||||
uint32_t m_channel;
|
||||
Direction m_direction;
|
||||
};
|
||||
|
||||
@@ -36,6 +36,5 @@ class SafePWM : public PWM, public MotorSafety {
|
||||
virtual void SetSpeed(float speed);
|
||||
|
||||
private:
|
||||
void InitSafePWM();
|
||||
MotorSafetyHelper *m_safetyHelper;
|
||||
};
|
||||
|
||||
@@ -40,7 +40,6 @@ class Servo : public SafePWM {
|
||||
ITable* m_table = nullptr;
|
||||
|
||||
private:
|
||||
void InitServo();
|
||||
float GetServoAngleRange() const { return kMaxServoAngle - kMinServoAngle; }
|
||||
|
||||
static constexpr float kMaxServoAngle = 180.0;
|
||||
|
||||
@@ -38,8 +38,6 @@ class Solenoid : public SolenoidBase,
|
||||
ITable* GetTable() const;
|
||||
|
||||
private:
|
||||
void InitSolenoid();
|
||||
|
||||
uint32_t m_channel; ///< The channel on the module to control.
|
||||
ITable* m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -29,7 +29,6 @@ class SolenoidBase : public SensorBase {
|
||||
protected:
|
||||
explicit SolenoidBase(uint8_t pcmID);
|
||||
void Set(uint8_t value, uint8_t mask, int module);
|
||||
virtual void InitSolenoid() = 0;
|
||||
const static int m_maxModules = 63;
|
||||
const static int m_maxPorts = 8;
|
||||
static void* m_ports[m_maxModules][m_maxPorts];
|
||||
|
||||
@@ -26,6 +26,5 @@ class Talon : public SafePWM, public SpeedController {
|
||||
virtual bool GetInverted() const override;
|
||||
|
||||
private:
|
||||
void InitTalon();
|
||||
bool m_isInverted = false;
|
||||
};
|
||||
|
||||
@@ -27,6 +27,5 @@ class TalonSRX : public SafePWM, public SpeedController {
|
||||
virtual bool GetInverted() const override;
|
||||
|
||||
private:
|
||||
void InitTalonSRX();
|
||||
bool m_isInverted = false;
|
||||
};
|
||||
|
||||
@@ -30,6 +30,5 @@ class Victor : public SafePWM, public SpeedController {
|
||||
virtual bool GetInverted() const override;
|
||||
|
||||
private:
|
||||
void InitVictor();
|
||||
bool m_isInverted = false;
|
||||
};
|
||||
|
||||
@@ -27,6 +27,5 @@ class VictorSP : public SafePWM, public SpeedController {
|
||||
virtual bool GetInverted() const override;
|
||||
|
||||
private:
|
||||
void InitVictorSP();
|
||||
bool m_isInverted = false;
|
||||
};
|
||||
|
||||
@@ -18,9 +18,12 @@ const uint32_t AnalogInput::kAccumulatorNumChannels;
|
||||
const uint32_t AnalogInput::kAccumulatorChannels[] = {0, 1};
|
||||
|
||||
/**
|
||||
* Common initialization.
|
||||
* Construct an analog input.
|
||||
*
|
||||
* @param channel The channel number on the roboRIO to represent. 0-3 are
|
||||
* on-board 4-7 are on the MXP port.
|
||||
*/
|
||||
void AnalogInput::InitAnalogInput(uint32_t channel) {
|
||||
AnalogInput::AnalogInput(uint32_t channel) {
|
||||
char buf[64];
|
||||
Resource::CreateResourceObject(&inputs, kAnalogInputs);
|
||||
|
||||
@@ -47,14 +50,6 @@ void AnalogInput::InitAnalogInput(uint32_t channel) {
|
||||
HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an analog input.
|
||||
*
|
||||
* @param channel The channel number on the roboRIO to represent. 0-3 are
|
||||
* on-board 4-7 are on the MXP port.
|
||||
*/
|
||||
AnalogInput::AnalogInput(uint32_t channel) { InitAnalogInput(channel); }
|
||||
|
||||
/**
|
||||
* Channel destructor.
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,12 @@
|
||||
|
||||
static Resource *outputs = nullptr;
|
||||
|
||||
void AnalogOutput::InitAnalogOutput(uint32_t channel) {
|
||||
/**
|
||||
* Construct an analog output on the given channel.
|
||||
* All analog outputs are located on the MXP port.
|
||||
* @param The channel number on the roboRIO to represent.
|
||||
*/
|
||||
AnalogOutput::AnalogOutput(uint32_t channel) {
|
||||
Resource::CreateResourceObject(&outputs, kAnalogOutputs);
|
||||
|
||||
char buf[64];
|
||||
@@ -39,13 +44,6 @@ void AnalogOutput::InitAnalogOutput(uint32_t channel) {
|
||||
HALReport(HALUsageReporting::kResourceType_AnalogOutput, m_channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an analog output on the given channel.
|
||||
* All analog outputs are located on the MXP port.
|
||||
* @param The channel number on the roboRIO to represent.
|
||||
*/
|
||||
AnalogOutput::AnalogOutput(uint32_t channel) { InitAnalogOutput(channel); }
|
||||
|
||||
/**
|
||||
* Destructor. Frees analog output resource
|
||||
*/
|
||||
|
||||
@@ -13,9 +13,12 @@
|
||||
#include "WPIErrors.h"
|
||||
|
||||
/**
|
||||
* Initialize an analog trigger from a channel.
|
||||
* Constructor for an analog trigger given a channel number.
|
||||
*
|
||||
* @param channel The channel number on the roboRIO to represent. 0-3 are
|
||||
* on-board 4-7 are on the MXP port.
|
||||
*/
|
||||
void AnalogTrigger::InitTrigger(uint32_t channel) {
|
||||
AnalogTrigger::AnalogTrigger(int32_t channel) {
|
||||
void *port = getPort(channel);
|
||||
int32_t status = 0;
|
||||
uint32_t index = 0;
|
||||
@@ -26,22 +29,14 @@ void AnalogTrigger::InitTrigger(uint32_t channel) {
|
||||
HALReport(HALUsageReporting::kResourceType_AnalogTrigger, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for an analog trigger given a channel number.
|
||||
*
|
||||
* @param channel The channel number on the roboRIO to represent. 0-3 are
|
||||
* on-board 4-7 are on the MXP port.
|
||||
*/
|
||||
AnalogTrigger::AnalogTrigger(int32_t channel) { InitTrigger(channel); }
|
||||
|
||||
/**
|
||||
* Construct an analog trigger given an analog input.
|
||||
* This should be used in the case of sharing an analog channel between the
|
||||
* trigger and an analog input object.
|
||||
* @param channel The pointer to the existing AnalogInput object
|
||||
*/
|
||||
AnalogTrigger::AnalogTrigger(AnalogInput *input) {
|
||||
InitTrigger(input->GetChannel());
|
||||
AnalogTrigger::AnalogTrigger(AnalogInput *input) :
|
||||
AnalogTrigger(input->GetChannel()) {
|
||||
}
|
||||
|
||||
AnalogTrigger::~AnalogTrigger() {
|
||||
|
||||
@@ -13,14 +13,18 @@
|
||||
#include "WPIErrors.h"
|
||||
|
||||
/**
|
||||
* Create an instance of a counter object.
|
||||
* Create an instance of a counter where no sources are selected.
|
||||
* They all must be selected by calling functions to specify the upsource and
|
||||
* the downsource
|
||||
* independently.
|
||||
*
|
||||
* This creates a ChipObject counter and initializes status variables
|
||||
* appropriately
|
||||
* appropriately.
|
||||
*
|
||||
* The counter will start counting immediately.
|
||||
* @param mode The counter mode
|
||||
*/
|
||||
void Counter::InitCounter(Mode mode) {
|
||||
Counter::Counter(Mode mode) {
|
||||
int32_t status = 0;
|
||||
m_counter = initializeCounter(mode, &m_index, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -30,18 +34,6 @@ void Counter::InitCounter(Mode mode) {
|
||||
HALReport(HALUsageReporting::kResourceType_Counter, m_index, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a counter where no sources are selected.
|
||||
* They all must be selected by calling functions to specify the upsource and
|
||||
* the downsource
|
||||
* independently.
|
||||
*
|
||||
* The counter will start counting immediately.
|
||||
*/
|
||||
Counter::Counter() {
|
||||
InitCounter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a counter from a Digital Source (such as a Digital
|
||||
* Input).
|
||||
@@ -54,8 +46,7 @@ Counter::Counter() {
|
||||
* @param source A pointer to the existing DigitalSource object. It will be set
|
||||
* as the Up Source.
|
||||
*/
|
||||
Counter::Counter(DigitalSource *source) {
|
||||
InitCounter();
|
||||
Counter::Counter(DigitalSource *source) : Counter() {
|
||||
SetUpSource(source);
|
||||
ClearDownSource();
|
||||
}
|
||||
@@ -72,8 +63,7 @@ Counter::Counter(DigitalSource *source) {
|
||||
* @param source A reference to the existing DigitalSource object. It will be
|
||||
* set as the Up Source.
|
||||
*/
|
||||
Counter::Counter(DigitalSource &source) {
|
||||
InitCounter();
|
||||
Counter::Counter(DigitalSource &source) : Counter() {
|
||||
SetUpSource(&source);
|
||||
ClearDownSource();
|
||||
}
|
||||
@@ -86,8 +76,7 @@ Counter::Counter(DigitalSource &source) {
|
||||
* @param channel The DIO channel to use as the up source. 0-9 are on-board,
|
||||
* 10-25 are on the MXP
|
||||
*/
|
||||
Counter::Counter(int32_t channel) {
|
||||
InitCounter();
|
||||
Counter::Counter(int32_t channel) : Counter() {
|
||||
SetUpSource(channel);
|
||||
ClearDownSource();
|
||||
}
|
||||
@@ -100,8 +89,7 @@ Counter::Counter(int32_t channel) {
|
||||
* The counter will start counting immediately.
|
||||
* @param trigger The pointer to the existing AnalogTrigger object.
|
||||
*/
|
||||
Counter::Counter(AnalogTrigger *trigger) {
|
||||
InitCounter();
|
||||
Counter::Counter(AnalogTrigger *trigger) : Counter() {
|
||||
SetUpSource(trigger->CreateOutput(kState));
|
||||
ClearDownSource();
|
||||
m_allocatedUpSource = true;
|
||||
@@ -115,8 +103,7 @@ Counter::Counter(AnalogTrigger *trigger) {
|
||||
* The counter will start counting immediately.
|
||||
* @param trigger The reference to the existing AnalogTrigger object.
|
||||
*/
|
||||
Counter::Counter(AnalogTrigger &trigger) {
|
||||
InitCounter();
|
||||
Counter::Counter(AnalogTrigger &trigger) : Counter() {
|
||||
SetUpSource(trigger.CreateOutput(kState));
|
||||
ClearDownSource();
|
||||
m_allocatedUpSource = true;
|
||||
@@ -132,14 +119,14 @@ Counter::Counter(AnalogTrigger &trigger) {
|
||||
*/
|
||||
|
||||
Counter::Counter(EncodingType encodingType, DigitalSource *upSource,
|
||||
DigitalSource *downSource, bool inverted) {
|
||||
DigitalSource *downSource, bool inverted)
|
||||
: Counter(kExternalDirection) {
|
||||
if (encodingType != k1X && encodingType != k2X) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
ParameterOutOfRange,
|
||||
"Counter only supports 1X and 2X quadrature decoding.");
|
||||
return;
|
||||
}
|
||||
InitCounter(kExternalDirection);
|
||||
SetUpSource(upSource);
|
||||
SetDownSource(downSource);
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -12,11 +12,12 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Create an instance of a DigitalInput.
|
||||
* Creates a digital input given a channel. Common creation routine for all
|
||||
* constructors.
|
||||
* Create an instance of a Digital Input class.
|
||||
* Creates a digital input given a channel.
|
||||
*
|
||||
* @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
|
||||
*/
|
||||
void DigitalInput::InitDigitalInput(uint32_t channel) {
|
||||
DigitalInput::DigitalInput(uint32_t channel) {
|
||||
char buf[64];
|
||||
|
||||
if (!CheckDigitalChannel(channel)) {
|
||||
@@ -34,14 +35,6 @@ void DigitalInput::InitDigitalInput(uint32_t channel) {
|
||||
HALReport(HALUsageReporting::kResourceType_DigitalInput, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a Digital Input class.
|
||||
* Creates a digital input given a channel.
|
||||
*
|
||||
* @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
|
||||
*/
|
||||
DigitalInput::DigitalInput(uint32_t channel) { InitDigitalInput(channel); }
|
||||
|
||||
/**
|
||||
* Free resources associated with the Digital Input class.
|
||||
*/
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
#include "WPIErrors.h"
|
||||
|
||||
/**
|
||||
* Create an instance of a DigitalOutput.
|
||||
* Creates a digital output given a channel. Common creation routine for all
|
||||
* constructors.
|
||||
* Create an instance of a digital output.
|
||||
* Create a digital output given a channel.
|
||||
*
|
||||
* @param channel The digital channel 0-9 are on-board, 10-25 are on the MXP
|
||||
* port
|
||||
*/
|
||||
void DigitalOutput::InitDigitalOutput(uint32_t channel) {
|
||||
DigitalOutput::DigitalOutput(uint32_t channel) {
|
||||
char buf[64];
|
||||
|
||||
if (!CheckDigitalChannel(channel)) {
|
||||
@@ -32,15 +34,6 @@ void DigitalOutput::InitDigitalOutput(uint32_t channel) {
|
||||
HALReport(HALUsageReporting::kResourceType_DigitalOutput, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a digital output.
|
||||
* Create a digital output given a channel.
|
||||
*
|
||||
* @param channel The digital channel 0-9 are on-board, 10-25 are on the MXP
|
||||
* port
|
||||
*/
|
||||
DigitalOutput::DigitalOutput(uint32_t channel) { InitDigitalOutput(channel); }
|
||||
|
||||
/**
|
||||
* Free the resources associated with a digital output.
|
||||
*/
|
||||
|
||||
@@ -10,9 +10,26 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common function to implement constructor behaviour.
|
||||
* Constructor.
|
||||
* Uses the default PCM ID of 0
|
||||
* @param forwardChannel The forward channel number on the PCM (0..7).
|
||||
* @param reverseChannel The reverse channel number on the PCM (0..7).
|
||||
*/
|
||||
void DoubleSolenoid::InitSolenoid() {
|
||||
DoubleSolenoid::DoubleSolenoid(uint32_t forwardChannel, uint32_t reverseChannel)
|
||||
: DoubleSolenoid(GetDefaultSolenoidModule(), forwardChannel, reverseChannel) {}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN ID of the PCM.
|
||||
* @param forwardChannel The forward channel on the PCM to control (0..7).
|
||||
* @param reverseChannel The reverse channel on the PCM to control (0..7).
|
||||
*/
|
||||
DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
|
||||
uint32_t reverseChannel)
|
||||
: SolenoidBase(moduleNumber),
|
||||
m_forwardChannel(forwardChannel),
|
||||
m_reverseChannel(reverseChannel) {
|
||||
char buf[64];
|
||||
if (!CheckSolenoidModule(m_moduleNumber)) {
|
||||
snprintf(buf, 64, "Solenoid Module %d", m_moduleNumber);
|
||||
@@ -58,34 +75,6 @@ void DoubleSolenoid::InitSolenoid() {
|
||||
m_forwardChannel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Uses the default PCM ID of 0
|
||||
* @param forwardChannel The forward channel number on the PCM (0..7).
|
||||
* @param reverseChannel The reverse channel number on the PCM (0..7).
|
||||
*/
|
||||
DoubleSolenoid::DoubleSolenoid(uint32_t forwardChannel, uint32_t reverseChannel)
|
||||
: SolenoidBase(GetDefaultSolenoidModule()),
|
||||
m_forwardChannel(forwardChannel),
|
||||
m_reverseChannel(reverseChannel) {
|
||||
InitSolenoid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN ID of the PCM.
|
||||
* @param forwardChannel The forward channel on the PCM to control (0..7).
|
||||
* @param reverseChannel The reverse channel on the PCM to control (0..7).
|
||||
*/
|
||||
DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
|
||||
uint32_t reverseChannel)
|
||||
: SolenoidBase(moduleNumber),
|
||||
m_forwardChannel(forwardChannel),
|
||||
m_reverseChannel(reverseChannel) {
|
||||
InitSolenoid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
* Constructor for a Jaguar connected via PWM
|
||||
* @param channel The PWM channel that the Jaguar is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
void Jaguar::InitJaguar() {
|
||||
Jaguar::Jaguar(uint32_t channel) : SafePWM(channel) {
|
||||
/**
|
||||
* Input profile defined by Luminary Micro.
|
||||
*
|
||||
@@ -31,13 +33,6 @@ void Jaguar::InitJaguar() {
|
||||
LiveWindow::GetInstance()->AddActuator("Jaguar", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a Jaguar connected via PWM
|
||||
* @param channel The PWM channel that the Jaguar is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
Jaguar::Jaguar(uint32_t channel) : SafePWM(channel) { InitJaguar(); }
|
||||
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
|
||||
@@ -30,9 +30,7 @@ static bool joySticksInitialized = false;
|
||||
* (0-5).
|
||||
*/
|
||||
Joystick::Joystick(uint32_t port)
|
||||
: m_port(port) {
|
||||
InitJoystick(kNumAxisTypes, kNumButtonTypes);
|
||||
|
||||
: Joystick(port, kNumAxisTypes, kNumButtonTypes) {
|
||||
m_axes[kXAxis] = kDefaultXAxis;
|
||||
m_axes[kYAxis] = kDefaultYAxis;
|
||||
m_axes[kZAxis] = kDefaultZAxis;
|
||||
@@ -58,10 +56,6 @@ Joystick::Joystick(uint32_t port)
|
||||
Joystick::Joystick(uint32_t port, uint32_t numAxisTypes,
|
||||
uint32_t numButtonTypes)
|
||||
: m_port(port) {
|
||||
InitJoystick(numAxisTypes, numButtonTypes);
|
||||
}
|
||||
|
||||
void Joystick::InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes) {
|
||||
if (!joySticksInitialized) {
|
||||
for (auto& joystick : joysticks) joystick = nullptr;
|
||||
joySticksInitialized = true;
|
||||
|
||||
@@ -19,17 +19,15 @@ const int32_t PWM::kDefaultPwmStepsDown;
|
||||
const int32_t PWM::kPwmDisabled;
|
||||
|
||||
/**
|
||||
* Initialize PWMs given a channel.
|
||||
* Allocate a PWM given a channel number.
|
||||
*
|
||||
* This method is private and is the common path for all the constructors for
|
||||
* creating PWM
|
||||
* instances. Checks channel value range and allocates the appropriate channel.
|
||||
* Checks channel value range and allocates the appropriate channel.
|
||||
* The allocation is only done to help users ensure that they don't double
|
||||
* assign channels.
|
||||
* @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the MXP
|
||||
* port
|
||||
*/
|
||||
void PWM::InitPWM(uint32_t channel) {
|
||||
PWM::PWM(uint32_t channel) {
|
||||
char buf[64];
|
||||
|
||||
if (!CheckPWMChannel(channel)) {
|
||||
@@ -52,13 +50,6 @@ void PWM::InitPWM(uint32_t channel) {
|
||||
HALReport(HALUsageReporting::kResourceType_PWM, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a PWM given a channel number.
|
||||
*
|
||||
* @param channel The PWM channel.
|
||||
*/
|
||||
PWM::PWM(uint32_t channel) { InitPWM(channel); }
|
||||
|
||||
/**
|
||||
* Free the PWM channel.
|
||||
*
|
||||
|
||||
@@ -18,13 +18,15 @@
|
||||
static Resource *relayChannels = nullptr;
|
||||
|
||||
/**
|
||||
* Common relay initialization method.
|
||||
* This code is common to all Relay constructors and initializes the relay and
|
||||
* reserves
|
||||
* all resources that need to be locked. Initially the relay is set to both
|
||||
* lines at 0v.
|
||||
* Relay constructor given a channel.
|
||||
*
|
||||
* This code initializes the relay and reserves all resources that need to be
|
||||
* locked. Initially the relay is set to both lines at 0v.
|
||||
* @param channel The channel number (0-3).
|
||||
* @param direction The direction that the Relay object will control.
|
||||
*/
|
||||
void Relay::InitRelay() {
|
||||
Relay::Relay(uint32_t channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
char buf[64];
|
||||
Resource::CreateResourceObject(&relayChannels,
|
||||
dio_kNumSystems * kRelayChannels * 2);
|
||||
@@ -61,16 +63,6 @@ void Relay::InitRelay() {
|
||||
LiveWindow::GetInstance()->AddActuator("Relay", 1, m_channel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relay constructor given a channel.
|
||||
* @param channel The channel number (0-3).
|
||||
* @param direction The direction that the Relay object will control.
|
||||
*/
|
||||
Relay::Relay(uint32_t channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
InitRelay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the resource associated with a relay.
|
||||
* The relay channels are set to free and the relay output is turned off.
|
||||
|
||||
@@ -9,20 +9,15 @@
|
||||
|
||||
#include "MotorSafetyHelper.h"
|
||||
|
||||
/**
|
||||
* Initialize a SafePWM object by setting defaults
|
||||
*/
|
||||
void SafePWM::InitSafePWM() {
|
||||
m_safetyHelper = new MotorSafetyHelper(this);
|
||||
m_safetyHelper->SetSafetyEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a SafePWM object taking a channel number.
|
||||
* @param channel The PWM channel number 0-9 are on-board, 10-19 are on the MXP
|
||||
* port
|
||||
*/
|
||||
SafePWM::SafePWM(uint32_t channel) : PWM(channel) { InitSafePWM(); }
|
||||
SafePWM::SafePWM(uint32_t channel) : PWM(channel) {
|
||||
m_safetyHelper = new MotorSafetyHelper(this);
|
||||
m_safetyHelper->SetSafetyEnabled(false);
|
||||
}
|
||||
|
||||
SafePWM::~SafePWM() { delete m_safetyHelper; }
|
||||
|
||||
|
||||
@@ -16,27 +16,17 @@ constexpr float Servo::kMinServoAngle;
|
||||
constexpr float Servo::kDefaultMaxServoPWM;
|
||||
constexpr float Servo::kDefaultMinServoPWM;
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*
|
||||
* InitServo() assigns defaults for the period multiplier for the servo PWM
|
||||
* control signal, as
|
||||
* well as the minimum and maximum PWM values supported by the servo.
|
||||
*/
|
||||
void Servo::InitServo() {
|
||||
SetBounds(kDefaultMaxServoPWM, 0.0, 0.0, 0.0, kDefaultMinServoPWM);
|
||||
SetPeriodMultiplier(kPeriodMultiplier_4X);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Servo", GetChannel(), this);
|
||||
HALReport(HALUsageReporting::kResourceType_Servo, GetChannel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channel The PWM channel to which the servo is attached. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
Servo::Servo(uint32_t channel) : SafePWM(channel) {
|
||||
InitServo();
|
||||
// Set minimum and maximum PWM values supported by the servo
|
||||
SetBounds(kDefaultMaxServoPWM, 0.0, 0.0, 0.0, kDefaultMinServoPWM);
|
||||
|
||||
// Assign defaults for period multiplier for the servo PWM control signal
|
||||
SetPeriodMultiplier(kPeriodMultiplier_4X);
|
||||
|
||||
// printf("Done initializing servo %d\n", channel);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,21 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common function to implement constructor behavior.
|
||||
* Constructor using the default PCM ID (0).
|
||||
*
|
||||
* @param channel The channel on the PCM to control (0..7).
|
||||
*/
|
||||
void Solenoid::InitSolenoid() {
|
||||
Solenoid::Solenoid(uint32_t channel)
|
||||
: Solenoid(GetDefaultSolenoidModule(), channel) {}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN ID of the PCM the solenoid is attached to
|
||||
* @param channel The channel on the PCM to control (0..7).
|
||||
*/
|
||||
Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
|
||||
: SolenoidBase(moduleNumber), m_channel(channel) {
|
||||
char buf[64];
|
||||
if (!CheckSolenoidModule(m_moduleNumber)) {
|
||||
snprintf(buf, 64, "Solenoid Module %d", m_moduleNumber);
|
||||
@@ -40,27 +52,6 @@ void Solenoid::InitSolenoid() {
|
||||
m_moduleNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor using the default PCM ID (0).
|
||||
*
|
||||
* @param channel The channel on the PCM to control (0..7).
|
||||
*/
|
||||
Solenoid::Solenoid(uint32_t channel)
|
||||
: SolenoidBase(GetDefaultSolenoidModule()), m_channel(channel) {
|
||||
InitSolenoid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN ID of the PCM the solenoid is attached to
|
||||
* @param channel The channel on the PCM to control (0..7).
|
||||
*/
|
||||
Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
|
||||
: SolenoidBase(moduleNumber), m_channel(channel) {
|
||||
InitSolenoid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
|
||||
@@ -11,24 +11,24 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*
|
||||
* Note that the Talon 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 Talon User Manual available
|
||||
* from CTRE.
|
||||
*
|
||||
* 2.037ms = full "forward"
|
||||
* 1.539ms = the "high end" of the deadband range
|
||||
* 1.513ms = center of the deadband range (off)
|
||||
* 1.487ms = the "low end" of the deadband range
|
||||
* 0.989ms = full "reverse"
|
||||
* Constructor for a Talon (original or Talon SR)
|
||||
* @param channel The PWM channel number that the Talon is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
void Talon::InitTalon() {
|
||||
Talon::Talon(uint32_t channel) : SafePWM(channel) {
|
||||
/* Note that the Talon 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 Talon User Manual available
|
||||
* from CTRE.
|
||||
*
|
||||
* 2.037ms = full "forward"
|
||||
* 1.539ms = the "high end" of the deadband range
|
||||
* 1.513ms = center of the deadband range (off)
|
||||
* 1.487ms = the "low end" of the deadband range
|
||||
* 0.989ms = full "reverse"
|
||||
*/
|
||||
SetBounds(2.037, 1.539, 1.513, 1.487, .989);
|
||||
SetPeriodMultiplier(kPeriodMultiplier_1X);
|
||||
SetRaw(m_centerPwm);
|
||||
@@ -38,13 +38,6 @@ void Talon::InitTalon() {
|
||||
LiveWindow::GetInstance()->AddActuator("Talon", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a Talon (original or Talon SR)
|
||||
* @param channel The PWM channel number that the Talon is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
Talon::Talon(uint32_t channel) : SafePWM(channel) { InitTalon(); }
|
||||
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
|
||||
@@ -11,23 +11,23 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*
|
||||
* Note that the TalonSRX uses the following bounds for PWM values. These values
|
||||
* should work reasonably well for
|
||||
* most controllers, but if users experience issues such as asymmetric behaviour
|
||||
* around
|
||||
* the deadband or inability to saturate the controller in either direction,
|
||||
* calibration is recommended.
|
||||
* The calibration procedure can be found in the TalonSRX User Manual available
|
||||
* from Cross The Road Electronics.
|
||||
* 2.004ms = full "forward"
|
||||
* 1.52ms = the "high end" of the deadband range
|
||||
* 1.50ms = center of the deadband range (off)
|
||||
* 1.48ms = the "low end" of the deadband range
|
||||
* 0.997ms = full "reverse"
|
||||
* Construct a TalonSRX connected via PWM
|
||||
* @param channel The PWM channel that the TalonSRX is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
void TalonSRX::InitTalonSRX() {
|
||||
TalonSRX::TalonSRX(uint32_t channel) : SafePWM(channel) {
|
||||
/* Note that the TalonSRX 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 TalonSRX User
|
||||
* Manual available from Cross The Road Electronics.
|
||||
* 2.004ms = full "forward"
|
||||
* 1.52ms = the "high end" of the deadband range
|
||||
* 1.50ms = center of the deadband range (off)
|
||||
* 1.48ms = the "low end" of the deadband range
|
||||
* 0.997ms = full "reverse"
|
||||
*/
|
||||
SetBounds(2.004, 1.52, 1.50, 1.48, .997);
|
||||
SetPeriodMultiplier(kPeriodMultiplier_1X);
|
||||
SetRaw(m_centerPwm);
|
||||
@@ -37,13 +37,6 @@ void TalonSRX::InitTalonSRX() {
|
||||
LiveWindow::GetInstance()->AddActuator("TalonSRX", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a TalonSRX connected via PWM
|
||||
* @param channel The PWM channel that the TalonSRX is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
TalonSRX::TalonSRX(uint32_t channel) : SafePWM(channel) { InitTalonSRX(); }
|
||||
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
|
||||
@@ -11,28 +11,26 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*
|
||||
* Note that the Victor uses the following bounds for PWM values. These values
|
||||
* were determined
|
||||
* empirically and optimized for the Victor 888. These values should work
|
||||
* reasonably well for
|
||||
* Victor 884 controllers as well but if users experience issues such as
|
||||
* asymmetric behaviour around
|
||||
* the deadband or inability to saturate the controller in either direction,
|
||||
* calibration is recommended.
|
||||
* The calibration procedure can be found in the Victor 884 User Manual
|
||||
* available from IFI.
|
||||
*
|
||||
* 2.027ms = full "forward"
|
||||
* 1.525ms = the "high end" of the deadband range
|
||||
* 1.507ms = center of the deadband range (off)
|
||||
* 1.49ms = the "low end" of the deadband range
|
||||
* 1.026ms = full "reverse"
|
||||
* Constructor for a Victor
|
||||
* @param channel The PWM channel number that the Victor is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
void Victor::InitVictor() {
|
||||
Victor::Victor(uint32_t channel) : SafePWM(channel) {
|
||||
/* Note that the Victor uses the following bounds for PWM values. These
|
||||
* values were determined empirically and optimized for the Victor 888. These
|
||||
* values should work reasonably well for Victor 884 controllers as well but
|
||||
* if users experience issues such as asymmetric behaviour around the deadband
|
||||
* or inability to saturate the controller in either direction, calibration is
|
||||
* recommended. The calibration procedure can be found in the Victor 884 User
|
||||
* Manual available from IFI.
|
||||
*
|
||||
* 2.027ms = full "forward"
|
||||
* 1.525ms = the "high end" of the deadband range
|
||||
* 1.507ms = center of the deadband range (off)
|
||||
* 1.49ms = the "low end" of the deadband range
|
||||
* 1.026ms = full "reverse"
|
||||
*/
|
||||
SetBounds(2.027, 1.525, 1.507, 1.49, 1.026);
|
||||
|
||||
SetPeriodMultiplier(kPeriodMultiplier_2X);
|
||||
SetRaw(m_centerPwm);
|
||||
SetZeroLatch();
|
||||
@@ -41,13 +39,6 @@ void Victor::InitVictor() {
|
||||
HALReport(HALUsageReporting::kResourceType_Victor, GetChannel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a Victor
|
||||
* @param channel The PWM channel number that the Victor is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
Victor::Victor(uint32_t channel) : SafePWM(channel) { InitVictor(); }
|
||||
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*
|
||||
* Note that the VictorSP 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
|
||||
@@ -28,7 +26,13 @@
|
||||
* 1.48ms = the "low end" of the deadband range
|
||||
* 0.997ms = full "reverse"
|
||||
*/
|
||||
void VictorSP::InitVictorSP() {
|
||||
|
||||
/**
|
||||
* Constructor for a VictorSP
|
||||
* @param channel The PWM channel that the VictorSP is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
VictorSP::VictorSP(uint32_t channel) : SafePWM(channel) {
|
||||
SetBounds(2.004, 1.52, 1.50, 1.48, .997);
|
||||
SetPeriodMultiplier(kPeriodMultiplier_1X);
|
||||
SetRaw(m_centerPwm);
|
||||
@@ -38,13 +42,6 @@ void VictorSP::InitVictorSP() {
|
||||
LiveWindow::GetInstance()->AddActuator("VictorSP", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a VictorSP
|
||||
* @param channel The PWM channel that the VictorSP is attached to. 0-9 are
|
||||
* on-board, 10-19 are on the MXP port
|
||||
*/
|
||||
VictorSP::VictorSP(uint32_t channel) : SafePWM(channel) { InitVictorSP(); }
|
||||
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
|
||||
@@ -45,7 +45,6 @@ public:
|
||||
ITable * GetTable() const override;
|
||||
|
||||
private:
|
||||
void InitAnalogInput(uint32_t channel);
|
||||
uint32_t m_channel;
|
||||
SimFloatInput* m_impl;
|
||||
int64_t m_accumulatorOffset;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "CounterBase.h"
|
||||
#include "SensorBase.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
@@ -22,7 +23,7 @@ class Counter : public SensorBase, public CounterBase, public LiveWindowSendable
|
||||
{
|
||||
public:
|
||||
|
||||
Counter();
|
||||
explicit Counter(Mode mode = kTwoPulse);
|
||||
explicit Counter(uint32_t channel);
|
||||
// TODO: [Not Supported] explicit Counter(DigitalSource *source);
|
||||
// TODO: [Not Supported] explicit Counter(DigitalSource &source);
|
||||
@@ -81,7 +82,6 @@ protected:
|
||||
// TODO: [Not Supported] DigitalSource *m_downSource; ///< What makes the counter count down.
|
||||
void* m_counter; ///< The FPGA counter object.
|
||||
private:
|
||||
// TODO: [Not Supported] void InitCounter(Mode mode = kTwoPulse);
|
||||
|
||||
bool m_allocatedUpSource; ///< Was the upSource allocated locally?
|
||||
bool m_allocatedDownSource; ///< Was the downSource allocated locally?
|
||||
|
||||
@@ -30,7 +30,6 @@ public:
|
||||
ITable * GetTable() const override;
|
||||
|
||||
private:
|
||||
void InitDigitalInput(uint32_t channel);
|
||||
uint32_t m_channel;
|
||||
bool m_lastValue;
|
||||
SimDigitalInput *m_impl;
|
||||
|
||||
@@ -41,7 +41,6 @@ public:
|
||||
ITable * GetTable() const override;
|
||||
|
||||
private:
|
||||
void InitSolenoid(int slot, int channel1, int channel2);
|
||||
SimContinuousOutput* m_impl;
|
||||
Value m_value;
|
||||
bool m_reversed;
|
||||
|
||||
@@ -22,7 +22,4 @@ public:
|
||||
virtual void Disable();
|
||||
|
||||
virtual void PIDWrite(float output) override;
|
||||
|
||||
private:
|
||||
void InitJaguar();
|
||||
};
|
||||
|
||||
@@ -66,7 +66,6 @@ public:
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Joystick);
|
||||
void InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes);
|
||||
|
||||
DriverStation *m_ds = nullptr;
|
||||
uint32_t m_port;
|
||||
|
||||
@@ -96,7 +96,6 @@ protected:
|
||||
ITable *m_table = nullptr;
|
||||
|
||||
private:
|
||||
void InitPWM(uint32_t channel);
|
||||
uint32_t m_channel;
|
||||
SimContinuousOutput* impl;
|
||||
};
|
||||
|
||||
@@ -56,8 +56,6 @@ public:
|
||||
ITable *m_table = nullptr;
|
||||
|
||||
private:
|
||||
void InitRelay();
|
||||
|
||||
uint32_t m_channel;
|
||||
Direction m_direction;
|
||||
SimContinuousOutput* impl;
|
||||
|
||||
@@ -33,6 +33,5 @@ public:
|
||||
|
||||
virtual void SetSpeed(float speed);
|
||||
private:
|
||||
void InitSafePWM();
|
||||
MotorSafetyHelper *m_safetyHelper;
|
||||
};
|
||||
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
ITable * GetTable() const override;
|
||||
|
||||
private:
|
||||
void InitSolenoid(int slot, int channel);
|
||||
SimContinuousOutput* m_impl;
|
||||
bool m_on;
|
||||
|
||||
|
||||
@@ -22,7 +22,4 @@ public:
|
||||
virtual void Disable();
|
||||
|
||||
virtual void PIDWrite(float output) override;
|
||||
|
||||
private:
|
||||
void InitTalon();
|
||||
};
|
||||
|
||||
@@ -22,7 +22,4 @@ public:
|
||||
virtual void Disable();
|
||||
|
||||
virtual void PIDWrite(float output) override;
|
||||
|
||||
private:
|
||||
void InitVictor();
|
||||
};
|
||||
|
||||
@@ -9,9 +9,11 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization.
|
||||
* Construct an analog input.
|
||||
*
|
||||
* @param channel The channel number to represent.
|
||||
*/
|
||||
void AnalogInput::InitAnalogInput(uint32_t channel)
|
||||
AnalogInput::AnalogInput(uint32_t channel)
|
||||
{
|
||||
m_channel = channel;
|
||||
char buffer[50];
|
||||
@@ -21,16 +23,6 @@ void AnalogInput::InitAnalogInput(uint32_t channel)
|
||||
LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an analog input.
|
||||
*
|
||||
* @param channel The channel number to represent.
|
||||
*/
|
||||
AnalogInput::AnalogInput(uint32_t channel)
|
||||
{
|
||||
InitAnalogInput(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a scaled sample straight from this channel.
|
||||
* The value is scaled to units of Volts using the calibrated scaling data from GetLSBWeight() and GetOffset().
|
||||
|
||||
@@ -7,19 +7,6 @@
|
||||
#include "DigitalInput.h"
|
||||
#include "WPIErrors.h"
|
||||
|
||||
/**
|
||||
* Create an instance of a DigitalInput.
|
||||
* Creates a digital input given a channel. Common creation routine for all
|
||||
* constructors.
|
||||
*/
|
||||
void DigitalInput::InitDigitalInput(uint32_t channel)
|
||||
{
|
||||
char buf[64];
|
||||
m_channel = channel;
|
||||
int n = sprintf(buf, "dio/%d", channel);
|
||||
m_impl = new SimDigitalInput(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a Digital Input class.
|
||||
* Creates a digital input given a channel and uses the default module.
|
||||
@@ -28,7 +15,10 @@ void DigitalInput::InitDigitalInput(uint32_t channel)
|
||||
*/
|
||||
DigitalInput::DigitalInput(uint32_t channel)
|
||||
{
|
||||
InitDigitalInput(channel);
|
||||
char buf[64];
|
||||
m_channel = channel;
|
||||
int n = sprintf(buf, "dio/%d", channel);
|
||||
m_impl = new SimDigitalInput(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -9,26 +9,6 @@
|
||||
#include <string.h>
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common function to implement constructor behavior.
|
||||
*/
|
||||
void DoubleSolenoid::InitSolenoid(int slot, int forwardChannel, int reverseChannel)
|
||||
{
|
||||
m_reversed = false;
|
||||
if (reverseChannel < forwardChannel) { // Swap ports to get the right address
|
||||
int channel = reverseChannel;
|
||||
reverseChannel = forwardChannel;
|
||||
forwardChannel = channel;
|
||||
m_reversed = true;
|
||||
}
|
||||
char buffer[50];
|
||||
int n = sprintf(buffer, "pneumatic/%d/%d/%d/%d", slot, forwardChannel,
|
||||
slot, reverseChannel);
|
||||
m_impl = new SimContinuousOutput(buffer);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("DoubleSolenoid", slot, forwardChannel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -36,9 +16,7 @@ void DoubleSolenoid::InitSolenoid(int slot, int forwardChannel, int reverseChann
|
||||
* @param reverseChannel The reverse channel on the module to control.
|
||||
*/
|
||||
DoubleSolenoid::DoubleSolenoid(uint32_t forwardChannel, uint32_t reverseChannel)
|
||||
{
|
||||
InitSolenoid(1, forwardChannel, reverseChannel);
|
||||
}
|
||||
: DoubleSolenoid(1, forwardChannel, reverseChannel) {}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -49,7 +27,20 @@ DoubleSolenoid::DoubleSolenoid(uint32_t forwardChannel, uint32_t reverseChannel)
|
||||
*/
|
||||
DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel, uint32_t reverseChannel)
|
||||
{
|
||||
InitSolenoid(moduleNumber, forwardChannel, reverseChannel);
|
||||
m_reversed = false;
|
||||
if (reverseChannel < forwardChannel) { // Swap ports to get the right address
|
||||
int channel = reverseChannel;
|
||||
reverseChannel = forwardChannel;
|
||||
forwardChannel = channel;
|
||||
m_reversed = true;
|
||||
}
|
||||
char buffer[50];
|
||||
int n = sprintf(buffer, "pneumatic/%d/%d/%d/%d", moduleNumber,
|
||||
forwardChannel, moduleNumber, reverseChannel);
|
||||
m_impl = new SimContinuousOutput(buffer);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("DoubleSolenoid", moduleNumber,
|
||||
forwardChannel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
* @param channel The PWM channel that the Jaguar is attached to.
|
||||
*/
|
||||
void Jaguar::InitJaguar()
|
||||
Jaguar::Jaguar(uint32_t channel) : SafePWM(channel)
|
||||
{
|
||||
/*
|
||||
* Input profile defined by Luminary Micro.
|
||||
@@ -30,14 +30,6 @@ void Jaguar::InitJaguar()
|
||||
LiveWindow::GetInstance()->AddActuator("Jaguar", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channel The PWM channel that the Jaguar is attached to.
|
||||
*/
|
||||
Jaguar::Jaguar(uint32_t channel) : SafePWM(channel)
|
||||
{
|
||||
InitJaguar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the PWM value.
|
||||
*
|
||||
|
||||
@@ -26,10 +26,8 @@ static bool joySticksInitialized = false;
|
||||
* @param port The port on the driver station that the joystick is plugged into.
|
||||
*/
|
||||
Joystick::Joystick(uint32_t port)
|
||||
: m_port (port)
|
||||
: Joystick(port, kNumAxisTypes, kNumButtonTypes)
|
||||
{
|
||||
InitJoystick(kNumAxisTypes, kNumButtonTypes);
|
||||
|
||||
m_axes[kXAxis] = kDefaultXAxis;
|
||||
m_axes[kYAxis] = kDefaultYAxis;
|
||||
m_axes[kZAxis] = kDefaultZAxis;
|
||||
@@ -52,11 +50,6 @@ Joystick::Joystick(uint32_t port)
|
||||
*/
|
||||
Joystick::Joystick(uint32_t port, uint32_t numAxisTypes, uint32_t numButtonTypes)
|
||||
: m_port (port)
|
||||
{
|
||||
InitJoystick(numAxisTypes, numButtonTypes);
|
||||
}
|
||||
|
||||
void Joystick::InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes)
|
||||
{
|
||||
if ( !joySticksInitialized )
|
||||
{
|
||||
|
||||
@@ -16,13 +16,15 @@ const int32_t PWM::kDefaultPwmStepsDown;
|
||||
const int32_t PWM::kPwmDisabled;
|
||||
|
||||
/**
|
||||
* Initialize PWMs given a channel.
|
||||
* Allocate a PWM given a channel number.
|
||||
*
|
||||
* This method is private and is the common path for all the constructors for creating PWM
|
||||
* instances. Checks channel value range and allocates the appropriate channel.
|
||||
* The allocation is only done to help users ensure that they don't double assign channels.
|
||||
* Checks channel value range and allocates the appropriate channel.
|
||||
* The allocation is only done to help users ensure that they don't double
|
||||
* assign channels.
|
||||
* @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the MXP
|
||||
* port
|
||||
*/
|
||||
void PWM::InitPWM(uint32_t channel)
|
||||
PWM::PWM(uint32_t channel)
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
@@ -41,16 +43,6 @@ void PWM::InitPWM(uint32_t channel)
|
||||
m_centerPwm = kPwmDisabled; // In simulation, the same thing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a PWM given a channel number.
|
||||
*
|
||||
* @param channel The PWM channel.
|
||||
*/
|
||||
PWM::PWM(uint32_t channel)
|
||||
{
|
||||
InitPWM(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally eliminate the deadband from a speed controller.
|
||||
* @param eliminateDeadband If true, set the motor curve on the Jaguar to eliminate
|
||||
|
||||
@@ -11,11 +11,16 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common relay initialization method.
|
||||
* This code is common to all Relay constructors and initializes the relay and reserves
|
||||
* all resources that need to be locked. Initially the relay is set to both lines at 0v.
|
||||
* Relay constructor given a channel.
|
||||
*
|
||||
* This code initializes the relay and reserves all resources that need to be
|
||||
* locked. Initially the relay is set to both lines at 0v.
|
||||
* @param channel The channel number (0-3).
|
||||
* @param direction The direction that the Relay object will control.
|
||||
*/
|
||||
void Relay::InitRelay()
|
||||
Relay::Relay(uint32_t channel, Relay::Direction direction)
|
||||
: m_channel (channel)
|
||||
, m_direction (direction)
|
||||
{
|
||||
char buf[64];
|
||||
if (!SensorBase::CheckRelayChannel(m_channel))
|
||||
@@ -31,18 +36,6 @@ void Relay::InitRelay()
|
||||
go_pos = go_neg = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relay constructor given a channel.
|
||||
* @param channel The channel number.
|
||||
* @param direction The direction that the Relay object will control.
|
||||
*/
|
||||
Relay::Relay(uint32_t channel, Relay::Direction direction)
|
||||
: m_channel (channel)
|
||||
, m_direction (direction)
|
||||
{
|
||||
InitRelay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the resource associated with a relay.
|
||||
* The relay channels are set to free and the relay output is turned off.
|
||||
|
||||
@@ -8,22 +8,14 @@
|
||||
|
||||
#include "MotorSafetyHelper.h"
|
||||
|
||||
/**
|
||||
* Initialize a SafePWM object by setting defaults
|
||||
*/
|
||||
void SafePWM::InitSafePWM()
|
||||
{
|
||||
m_safetyHelper = new MotorSafetyHelper(this);
|
||||
m_safetyHelper->SetSafetyEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a SafePWM object taking a channel number.
|
||||
* @param channel The PWM channel number (0..19).
|
||||
*/
|
||||
SafePWM::SafePWM(uint32_t channel): PWM(channel)
|
||||
{
|
||||
InitSafePWM();
|
||||
m_safetyHelper = new MotorSafetyHelper(this);
|
||||
m_safetyHelper->SetSafetyEnabled(false);
|
||||
}
|
||||
|
||||
SafePWM::~SafePWM()
|
||||
|
||||
@@ -9,27 +9,12 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "simulation/simTime.h"
|
||||
|
||||
/**
|
||||
* Common function to implement constructor behavior.
|
||||
*/
|
||||
void Solenoid::InitSolenoid(int slot, int channel)
|
||||
{
|
||||
char buffer[50];
|
||||
int n = sprintf(buffer, "pneumatic/%d/%d", slot, channel);
|
||||
m_impl = new SimContinuousOutput(buffer);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Solenoid", slot, channel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param channel The channel on the solenoid module to control (1..8).
|
||||
*/
|
||||
Solenoid::Solenoid(uint32_t channel)
|
||||
{
|
||||
InitSolenoid(1, channel);
|
||||
}
|
||||
Solenoid::Solenoid(uint32_t channel) : Solenoid(1, channel) {}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -39,7 +24,12 @@ Solenoid::Solenoid(uint32_t channel)
|
||||
*/
|
||||
Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
|
||||
{
|
||||
InitSolenoid(moduleNumber, channel);
|
||||
char buffer[50];
|
||||
int n = sprintf(buffer, "pneumatic/%d/%d", moduleNumber, channel);
|
||||
m_impl = new SimContinuousOutput(buffer);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Solenoid", moduleNumber, channel,
|
||||
this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,34 +9,29 @@
|
||||
//#include "NetworkCommunication/UsageReporting.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*
|
||||
* Note that the Talon 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 Talon User Manual available from CTRE.
|
||||
*
|
||||
* - 211 = full "forward"
|
||||
* - 133 = the "high end" of the deadband range
|
||||
* - 129 = center of the deadband range (off)
|
||||
* - 125 = the "low end" of the deadband range
|
||||
* - 49 = full "reverse"
|
||||
*/
|
||||
void Talon::InitTalon() {
|
||||
SetBounds(2.037, 1.539, 1.513, 1.487, .989);
|
||||
SetPeriodMultiplier(kPeriodMultiplier_2X);
|
||||
SetRaw(m_centerPwm);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Talon", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channel The PWM channel that the Talon is attached to.
|
||||
*/
|
||||
Talon::Talon(uint32_t channel) : SafePWM(channel)
|
||||
{
|
||||
InitTalon();
|
||||
/* Note that the Talon 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 Talon User Manual available
|
||||
* from CTRE.
|
||||
*
|
||||
* - 211 = full "forward"
|
||||
* - 133 = the "high end" of the deadband range
|
||||
* - 129 = center of the deadband range (off)
|
||||
* - 125 = the "low end" of the deadband range
|
||||
* - 49 = full "reverse"
|
||||
*/
|
||||
SetBounds(2.037, 1.539, 1.513, 1.487, .989);
|
||||
SetPeriodMultiplier(kPeriodMultiplier_2X);
|
||||
SetRaw(m_centerPwm);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Talon", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,36 +9,31 @@
|
||||
//#include "NetworkCommunication/UsageReporting.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*
|
||||
* Note that the Victor uses the following bounds for PWM values. These values were determined
|
||||
* empirically and optimized for the Victor 888. These values should work reasonably well for
|
||||
* Victor 884 controllers as well 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 Victor 884 User Manual available from IFI.
|
||||
*
|
||||
* - 206 = full "forward"
|
||||
* - 131 = the "high end" of the deadband range
|
||||
* - 128 = center of the deadband range (off)
|
||||
* - 125 = the "low end" of the deadband range
|
||||
* - 56 = full "reverse"
|
||||
*/
|
||||
void Victor::InitVictor() {
|
||||
SetBounds(2.027, 1.525, 1.507, 1.49, 1.026);
|
||||
|
||||
SetPeriodMultiplier(kPeriodMultiplier_2X);
|
||||
SetRaw(m_centerPwm);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Victor", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channel The PWM channel that the Victor is attached to.
|
||||
*/
|
||||
Victor::Victor(uint32_t channel) : SafePWM(channel)
|
||||
{
|
||||
InitVictor();
|
||||
/* Note that the Victor uses the following bounds for PWM values. These values
|
||||
* were determined empirically and optimized for the Victor 888. These values
|
||||
* should work reasonably well for Victor 884 controllers as well 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 Victor 884 User
|
||||
* Manual available from IFI.
|
||||
*
|
||||
* - 206 = full "forward"
|
||||
* - 131 = the "high end" of the deadband range
|
||||
* - 128 = center of the deadband range (off)
|
||||
* - 125 = the "low end" of the deadband range
|
||||
* - 56 = full "reverse"
|
||||
*/
|
||||
|
||||
SetBounds(2.027, 1.525, 1.507, 1.49, 1.026);
|
||||
SetPeriodMultiplier(kPeriodMultiplier_2X);
|
||||
SetRaw(m_centerPwm);
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("Victor", GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user