From 1ab3ea670d655e674505b2f5a6009a3634d5dbec Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Mon, 29 Jun 2015 02:43:44 -0700 Subject: [PATCH] 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 --- wpilibc/wpilibC++/include/Commands/Command.h | 1 - wpilibc/wpilibC++/src/Commands/Command.cpp | 22 +++------ .../wpilibC++Devices/include/AnalogInput.h | 1 - .../wpilibC++Devices/include/AnalogOutput.h | 1 - .../wpilibC++Devices/include/AnalogTrigger.h | 2 - wpilibc/wpilibC++Devices/include/Counter.h | 4 +- .../wpilibC++Devices/include/DigitalInput.h | 1 - .../wpilibC++Devices/include/DigitalOutput.h | 2 - .../wpilibC++Devices/include/DoubleSolenoid.h | 2 - wpilibc/wpilibC++Devices/include/Jaguar.h | 1 - wpilibc/wpilibC++Devices/include/Joystick.h | 1 - wpilibc/wpilibC++Devices/include/PWM.h | 1 - wpilibc/wpilibC++Devices/include/Relay.h | 2 - wpilibc/wpilibC++Devices/include/SafePWM.h | 1 - wpilibc/wpilibC++Devices/include/Servo.h | 1 - wpilibc/wpilibC++Devices/include/Solenoid.h | 2 - .../wpilibC++Devices/include/SolenoidBase.h | 1 - wpilibc/wpilibC++Devices/include/Talon.h | 1 - wpilibc/wpilibC++Devices/include/TalonSRX.h | 1 - wpilibc/wpilibC++Devices/include/Victor.h | 1 - wpilibc/wpilibC++Devices/include/VictorSP.h | 1 - wpilibc/wpilibC++Devices/src/AnalogInput.cpp | 15 ++---- wpilibc/wpilibC++Devices/src/AnalogOutput.cpp | 14 +++--- .../wpilibC++Devices/src/AnalogTrigger.cpp | 19 +++---- wpilibc/wpilibC++Devices/src/Counter.cpp | 41 ++++++---------- wpilibc/wpilibC++Devices/src/DigitalInput.cpp | 17 ++----- .../wpilibC++Devices/src/DigitalOutput.cpp | 19 +++---- .../wpilibC++Devices/src/DoubleSolenoid.cpp | 49 +++++++------------ wpilibc/wpilibC++Devices/src/Jaguar.cpp | 13 ++--- wpilibc/wpilibC++Devices/src/Joystick.cpp | 8 +-- wpilibc/wpilibC++Devices/src/PWM.cpp | 15 ++---- wpilibc/wpilibC++Devices/src/Relay.cpp | 24 +++------ wpilibc/wpilibC++Devices/src/SafePWM.cpp | 13 ++--- wpilibc/wpilibC++Devices/src/Servo.cpp | 22 +++------ wpilibc/wpilibC++Devices/src/Solenoid.cpp | 37 ++++++-------- wpilibc/wpilibC++Devices/src/Talon.cpp | 41 +++++++--------- wpilibc/wpilibC++Devices/src/TalonSRX.cpp | 39 ++++++--------- wpilibc/wpilibC++Devices/src/Victor.cpp | 45 +++++++---------- wpilibc/wpilibC++Devices/src/VictorSP.cpp | 17 +++---- wpilibc/wpilibC++Sim/include/AnalogInput.h | 1 - wpilibc/wpilibC++Sim/include/Counter.h | 4 +- wpilibc/wpilibC++Sim/include/DigitalInput.h | 1 - wpilibc/wpilibC++Sim/include/DoubleSolenoid.h | 1 - wpilibc/wpilibC++Sim/include/Jaguar.h | 3 -- wpilibc/wpilibC++Sim/include/Joystick.h | 1 - wpilibc/wpilibC++Sim/include/PWM.h | 1 - wpilibc/wpilibC++Sim/include/Relay.h | 2 - wpilibc/wpilibC++Sim/include/SafePWM.h | 1 - wpilibc/wpilibC++Sim/include/Solenoid.h | 1 - wpilibc/wpilibC++Sim/include/Talon.h | 3 -- wpilibc/wpilibC++Sim/include/Victor.h | 3 -- wpilibc/wpilibC++Sim/src/AnalogInput.cpp | 16 ++---- wpilibc/wpilibC++Sim/src/DigitalInput.cpp | 18 ++----- wpilibc/wpilibC++Sim/src/DoubleSolenoid.cpp | 39 ++++++--------- wpilibc/wpilibC++Sim/src/Jaguar.cpp | 12 +---- wpilibc/wpilibC++Sim/src/Joystick.cpp | 9 +--- wpilibc/wpilibC++Sim/src/PWM.cpp | 22 +++------ wpilibc/wpilibC++Sim/src/Relay.cpp | 25 ++++------ wpilibc/wpilibC++Sim/src/SafePWM.cpp | 12 +---- wpilibc/wpilibC++Sim/src/Solenoid.cpp | 24 +++------ wpilibc/wpilibC++Sim/src/Talon.cpp | 41 +++++++--------- wpilibc/wpilibC++Sim/src/Victor.cpp | 45 ++++++++--------- 62 files changed, 258 insertions(+), 525 deletions(-) diff --git a/wpilibc/wpilibC++/include/Commands/Command.h b/wpilibc/wpilibC++/include/Commands/Command.h index 9335bf4403..99d4feb7f7 100644 --- a/wpilibc/wpilibC++/include/Commands/Command.h +++ b/wpilibc/wpilibC++/include/Commands/Command.h @@ -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(); diff --git a/wpilibc/wpilibC++/src/Commands/Command.cpp b/wpilibc/wpilibC++/src/Commands/Command.cpp index 1beb069306..5c6af1b472 100644 --- a/wpilibc/wpilibC++/src/Commands/Command.cpp +++ b/wpilibc/wpilibC++/src/Commands/Command.cpp @@ -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 diff --git a/wpilibc/wpilibC++Devices/include/AnalogInput.h b/wpilibc/wpilibC++Devices/include/AnalogInput.h index f37c95b88f..f91c512731 100644 --- a/wpilibc/wpilibC++Devices/include/AnalogInput.h +++ b/wpilibc/wpilibC++Devices/include/AnalogInput.h @@ -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; diff --git a/wpilibc/wpilibC++Devices/include/AnalogOutput.h b/wpilibc/wpilibC++Devices/include/AnalogOutput.h index 25c273a81f..e0e091ef4f 100644 --- a/wpilibc/wpilibC++Devices/include/AnalogOutput.h +++ b/wpilibc/wpilibC++Devices/include/AnalogOutput.h @@ -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; diff --git a/wpilibc/wpilibC++Devices/include/AnalogTrigger.h b/wpilibc/wpilibC++Devices/include/AnalogTrigger.h index 1f6c7aeba5..6b1df97967 100644 --- a/wpilibc/wpilibC++Devices/include/AnalogTrigger.h +++ b/wpilibc/wpilibC++Devices/include/AnalogTrigger.h @@ -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; }; diff --git a/wpilibc/wpilibC++Devices/include/Counter.h b/wpilibc/wpilibC++Devices/include/Counter.h index 953bc3cd38..d04c1e1371 100644 --- a/wpilibc/wpilibC++Devices/include/Counter.h +++ b/wpilibc/wpilibC++Devices/include/Counter.h @@ -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. diff --git a/wpilibc/wpilibC++Devices/include/DigitalInput.h b/wpilibc/wpilibC++Devices/include/DigitalInput.h index ea46d53ee9..a6c69a954a 100644 --- a/wpilibc/wpilibC++Devices/include/DigitalInput.h +++ b/wpilibc/wpilibC++Devices/include/DigitalInput.h @@ -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; diff --git a/wpilibc/wpilibC++Devices/include/DigitalOutput.h b/wpilibc/wpilibC++Devices/include/DigitalOutput.h index 55a6eadf07..b73b141a6f 100644 --- a/wpilibc/wpilibC++Devices/include/DigitalOutput.h +++ b/wpilibc/wpilibC++Devices/include/DigitalOutput.h @@ -46,8 +46,6 @@ class DigitalOutput : public DigitalSource, ITable *GetTable() const; private: - void InitDigitalOutput(uint32_t channel); - uint32_t m_channel; void *m_pwmGenerator; diff --git a/wpilibc/wpilibC++Devices/include/DoubleSolenoid.h b/wpilibc/wpilibC++Devices/include/DoubleSolenoid.h index 40818a5fec..48ab49c107 100644 --- a/wpilibc/wpilibC++Devices/include/DoubleSolenoid.h +++ b/wpilibc/wpilibC++Devices/include/DoubleSolenoid.h @@ -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. diff --git a/wpilibc/wpilibC++Devices/include/Jaguar.h b/wpilibc/wpilibC++Devices/include/Jaguar.h index f343139890..feb00c7699 100644 --- a/wpilibc/wpilibC++Devices/include/Jaguar.h +++ b/wpilibc/wpilibC++Devices/include/Jaguar.h @@ -26,6 +26,5 @@ class Jaguar : public SafePWM, public SpeedController { virtual bool GetInverted() const override; private: - void InitJaguar(); bool m_isInverted = false; }; diff --git a/wpilibc/wpilibC++Devices/include/Joystick.h b/wpilibc/wpilibC++Devices/include/Joystick.h index 2776f198a1..94ad3714d4 100644 --- a/wpilibc/wpilibC++Devices/include/Joystick.h +++ b/wpilibc/wpilibC++Devices/include/Joystick.h @@ -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; diff --git a/wpilibc/wpilibC++Devices/include/PWM.h b/wpilibc/wpilibC++Devices/include/PWM.h index e2932e3747..ca874c4098 100644 --- a/wpilibc/wpilibC++Devices/include/PWM.h +++ b/wpilibc/wpilibC++Devices/include/PWM.h @@ -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 { diff --git a/wpilibc/wpilibC++Devices/include/Relay.h b/wpilibc/wpilibC++Devices/include/Relay.h index 6c8c6e3f4d..9279a1ec5b 100644 --- a/wpilibc/wpilibC++Devices/include/Relay.h +++ b/wpilibc/wpilibC++Devices/include/Relay.h @@ -50,8 +50,6 @@ class Relay : public SensorBase, ITable* m_table = nullptr; private: - void InitRelay(); - uint32_t m_channel; Direction m_direction; }; diff --git a/wpilibc/wpilibC++Devices/include/SafePWM.h b/wpilibc/wpilibC++Devices/include/SafePWM.h index 1896884718..f672dc6210 100644 --- a/wpilibc/wpilibC++Devices/include/SafePWM.h +++ b/wpilibc/wpilibC++Devices/include/SafePWM.h @@ -36,6 +36,5 @@ class SafePWM : public PWM, public MotorSafety { virtual void SetSpeed(float speed); private: - void InitSafePWM(); MotorSafetyHelper *m_safetyHelper; }; diff --git a/wpilibc/wpilibC++Devices/include/Servo.h b/wpilibc/wpilibC++Devices/include/Servo.h index 298c29a63d..8386023fff 100644 --- a/wpilibc/wpilibC++Devices/include/Servo.h +++ b/wpilibc/wpilibC++Devices/include/Servo.h @@ -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; diff --git a/wpilibc/wpilibC++Devices/include/Solenoid.h b/wpilibc/wpilibC++Devices/include/Solenoid.h index 0344398e58..a760413805 100644 --- a/wpilibc/wpilibC++Devices/include/Solenoid.h +++ b/wpilibc/wpilibC++Devices/include/Solenoid.h @@ -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; }; diff --git a/wpilibc/wpilibC++Devices/include/SolenoidBase.h b/wpilibc/wpilibC++Devices/include/SolenoidBase.h index a164d322da..0a51be6352 100644 --- a/wpilibc/wpilibC++Devices/include/SolenoidBase.h +++ b/wpilibc/wpilibC++Devices/include/SolenoidBase.h @@ -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]; diff --git a/wpilibc/wpilibC++Devices/include/Talon.h b/wpilibc/wpilibC++Devices/include/Talon.h index d3a52dad12..38764b850d 100644 --- a/wpilibc/wpilibC++Devices/include/Talon.h +++ b/wpilibc/wpilibC++Devices/include/Talon.h @@ -26,6 +26,5 @@ class Talon : public SafePWM, public SpeedController { virtual bool GetInverted() const override; private: - void InitTalon(); bool m_isInverted = false; }; diff --git a/wpilibc/wpilibC++Devices/include/TalonSRX.h b/wpilibc/wpilibC++Devices/include/TalonSRX.h index 9747807739..8819723f7c 100644 --- a/wpilibc/wpilibC++Devices/include/TalonSRX.h +++ b/wpilibc/wpilibC++Devices/include/TalonSRX.h @@ -27,6 +27,5 @@ class TalonSRX : public SafePWM, public SpeedController { virtual bool GetInverted() const override; private: - void InitTalonSRX(); bool m_isInverted = false; }; diff --git a/wpilibc/wpilibC++Devices/include/Victor.h b/wpilibc/wpilibC++Devices/include/Victor.h index 5d7cc42bbe..755955f306 100644 --- a/wpilibc/wpilibC++Devices/include/Victor.h +++ b/wpilibc/wpilibC++Devices/include/Victor.h @@ -30,6 +30,5 @@ class Victor : public SafePWM, public SpeedController { virtual bool GetInverted() const override; private: - void InitVictor(); bool m_isInverted = false; }; diff --git a/wpilibc/wpilibC++Devices/include/VictorSP.h b/wpilibc/wpilibC++Devices/include/VictorSP.h index a6eb821e08..978cd0ac0c 100644 --- a/wpilibc/wpilibC++Devices/include/VictorSP.h +++ b/wpilibc/wpilibC++Devices/include/VictorSP.h @@ -27,6 +27,5 @@ class VictorSP : public SafePWM, public SpeedController { virtual bool GetInverted() const override; private: - void InitVictorSP(); bool m_isInverted = false; }; diff --git a/wpilibc/wpilibC++Devices/src/AnalogInput.cpp b/wpilibc/wpilibC++Devices/src/AnalogInput.cpp index c0b3bb276f..ef3ab5915d 100644 --- a/wpilibc/wpilibC++Devices/src/AnalogInput.cpp +++ b/wpilibc/wpilibC++Devices/src/AnalogInput.cpp @@ -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. */ diff --git a/wpilibc/wpilibC++Devices/src/AnalogOutput.cpp b/wpilibc/wpilibC++Devices/src/AnalogOutput.cpp index 388ab51971..c6f2def0c2 100644 --- a/wpilibc/wpilibC++Devices/src/AnalogOutput.cpp +++ b/wpilibc/wpilibC++Devices/src/AnalogOutput.cpp @@ -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 */ diff --git a/wpilibc/wpilibC++Devices/src/AnalogTrigger.cpp b/wpilibc/wpilibC++Devices/src/AnalogTrigger.cpp index 80be7fe862..9289a2ca58 100644 --- a/wpilibc/wpilibC++Devices/src/AnalogTrigger.cpp +++ b/wpilibc/wpilibC++Devices/src/AnalogTrigger.cpp @@ -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() { diff --git a/wpilibc/wpilibC++Devices/src/Counter.cpp b/wpilibc/wpilibC++Devices/src/Counter.cpp index deccebe887..c4e333ce83 100644 --- a/wpilibc/wpilibC++Devices/src/Counter.cpp +++ b/wpilibc/wpilibC++Devices/src/Counter.cpp @@ -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; diff --git a/wpilibc/wpilibC++Devices/src/DigitalInput.cpp b/wpilibc/wpilibC++Devices/src/DigitalInput.cpp index 6c75747bf7..b80bebd4d7 100644 --- a/wpilibc/wpilibC++Devices/src/DigitalInput.cpp +++ b/wpilibc/wpilibC++Devices/src/DigitalInput.cpp @@ -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. */ diff --git a/wpilibc/wpilibC++Devices/src/DigitalOutput.cpp b/wpilibc/wpilibC++Devices/src/DigitalOutput.cpp index e97555faee..56157661c1 100644 --- a/wpilibc/wpilibC++Devices/src/DigitalOutput.cpp +++ b/wpilibc/wpilibC++Devices/src/DigitalOutput.cpp @@ -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. */ diff --git a/wpilibc/wpilibC++Devices/src/DoubleSolenoid.cpp b/wpilibc/wpilibC++Devices/src/DoubleSolenoid.cpp index 2ed7fc689a..ede689f573 100644 --- a/wpilibc/wpilibC++Devices/src/DoubleSolenoid.cpp +++ b/wpilibc/wpilibC++Devices/src/DoubleSolenoid.cpp @@ -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. */ diff --git a/wpilibc/wpilibC++Devices/src/Jaguar.cpp b/wpilibc/wpilibC++Devices/src/Jaguar.cpp index 81afe86abd..9b02302eb9 100644 --- a/wpilibc/wpilibC++Devices/src/Jaguar.cpp +++ b/wpilibc/wpilibC++Devices/src/Jaguar.cpp @@ -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. * diff --git a/wpilibc/wpilibC++Devices/src/Joystick.cpp b/wpilibc/wpilibC++Devices/src/Joystick.cpp index d5c36f1cad..6bf01fceda 100644 --- a/wpilibc/wpilibC++Devices/src/Joystick.cpp +++ b/wpilibc/wpilibC++Devices/src/Joystick.cpp @@ -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; diff --git a/wpilibc/wpilibC++Devices/src/PWM.cpp b/wpilibc/wpilibC++Devices/src/PWM.cpp index 2980ff7385..e5efc069ac 100644 --- a/wpilibc/wpilibC++Devices/src/PWM.cpp +++ b/wpilibc/wpilibC++Devices/src/PWM.cpp @@ -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. * diff --git a/wpilibc/wpilibC++Devices/src/Relay.cpp b/wpilibc/wpilibC++Devices/src/Relay.cpp index f60b63ef4f..98948e5818 100644 --- a/wpilibc/wpilibC++Devices/src/Relay.cpp +++ b/wpilibc/wpilibC++Devices/src/Relay.cpp @@ -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. diff --git a/wpilibc/wpilibC++Devices/src/SafePWM.cpp b/wpilibc/wpilibC++Devices/src/SafePWM.cpp index dd4d1aba07..09689eddbd 100644 --- a/wpilibc/wpilibC++Devices/src/SafePWM.cpp +++ b/wpilibc/wpilibC++Devices/src/SafePWM.cpp @@ -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; } diff --git a/wpilibc/wpilibC++Devices/src/Servo.cpp b/wpilibc/wpilibC++Devices/src/Servo.cpp index bd495b3cc5..304c97cb32 100644 --- a/wpilibc/wpilibC++Devices/src/Servo.cpp +++ b/wpilibc/wpilibC++Devices/src/Servo.cpp @@ -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); } diff --git a/wpilibc/wpilibC++Devices/src/Solenoid.cpp b/wpilibc/wpilibC++Devices/src/Solenoid.cpp index ed89663b10..422c5adeeb 100644 --- a/wpilibc/wpilibC++Devices/src/Solenoid.cpp +++ b/wpilibc/wpilibC++Devices/src/Solenoid.cpp @@ -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. */ diff --git a/wpilibc/wpilibC++Devices/src/Talon.cpp b/wpilibc/wpilibC++Devices/src/Talon.cpp index 6c07c28d05..1270af839b 100644 --- a/wpilibc/wpilibC++Devices/src/Talon.cpp +++ b/wpilibc/wpilibC++Devices/src/Talon.cpp @@ -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. * diff --git a/wpilibc/wpilibC++Devices/src/TalonSRX.cpp b/wpilibc/wpilibC++Devices/src/TalonSRX.cpp index 661b089b4d..6e6115f872 100644 --- a/wpilibc/wpilibC++Devices/src/TalonSRX.cpp +++ b/wpilibc/wpilibC++Devices/src/TalonSRX.cpp @@ -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. * diff --git a/wpilibc/wpilibC++Devices/src/Victor.cpp b/wpilibc/wpilibC++Devices/src/Victor.cpp index 9b6f5ec93f..30202db528 100644 --- a/wpilibc/wpilibC++Devices/src/Victor.cpp +++ b/wpilibc/wpilibC++Devices/src/Victor.cpp @@ -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. * diff --git a/wpilibc/wpilibC++Devices/src/VictorSP.cpp b/wpilibc/wpilibC++Devices/src/VictorSP.cpp index 1167bc0c94..5341ccfb93 100644 --- a/wpilibc/wpilibC++Devices/src/VictorSP.cpp +++ b/wpilibc/wpilibC++Devices/src/VictorSP.cpp @@ -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. * diff --git a/wpilibc/wpilibC++Sim/include/AnalogInput.h b/wpilibc/wpilibC++Sim/include/AnalogInput.h index eb5d355fa9..9b17ccd9a8 100644 --- a/wpilibc/wpilibC++Sim/include/AnalogInput.h +++ b/wpilibc/wpilibC++Sim/include/AnalogInput.h @@ -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; diff --git a/wpilibc/wpilibC++Sim/include/Counter.h b/wpilibc/wpilibC++Sim/include/Counter.h index 4ccee43b72..ade463ba47 100644 --- a/wpilibc/wpilibC++Sim/include/Counter.h +++ b/wpilibc/wpilibC++Sim/include/Counter.h @@ -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? diff --git a/wpilibc/wpilibC++Sim/include/DigitalInput.h b/wpilibc/wpilibC++Sim/include/DigitalInput.h index 3b2e25e6e7..82066068f4 100644 --- a/wpilibc/wpilibC++Sim/include/DigitalInput.h +++ b/wpilibc/wpilibC++Sim/include/DigitalInput.h @@ -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; diff --git a/wpilibc/wpilibC++Sim/include/DoubleSolenoid.h b/wpilibc/wpilibC++Sim/include/DoubleSolenoid.h index c03fc38f79..b9f15832a9 100644 --- a/wpilibc/wpilibC++Sim/include/DoubleSolenoid.h +++ b/wpilibc/wpilibC++Sim/include/DoubleSolenoid.h @@ -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; diff --git a/wpilibc/wpilibC++Sim/include/Jaguar.h b/wpilibc/wpilibC++Sim/include/Jaguar.h index 88008aa58f..1f522d922e 100644 --- a/wpilibc/wpilibC++Sim/include/Jaguar.h +++ b/wpilibc/wpilibC++Sim/include/Jaguar.h @@ -22,7 +22,4 @@ public: virtual void Disable(); virtual void PIDWrite(float output) override; - -private: - void InitJaguar(); }; diff --git a/wpilibc/wpilibC++Sim/include/Joystick.h b/wpilibc/wpilibC++Sim/include/Joystick.h index 5974b8dcda..998ad886c2 100644 --- a/wpilibc/wpilibC++Sim/include/Joystick.h +++ b/wpilibc/wpilibC++Sim/include/Joystick.h @@ -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; diff --git a/wpilibc/wpilibC++Sim/include/PWM.h b/wpilibc/wpilibC++Sim/include/PWM.h index 69a7337806..7a27684fd8 100644 --- a/wpilibc/wpilibC++Sim/include/PWM.h +++ b/wpilibc/wpilibC++Sim/include/PWM.h @@ -96,7 +96,6 @@ protected: ITable *m_table = nullptr; private: - void InitPWM(uint32_t channel); uint32_t m_channel; SimContinuousOutput* impl; }; diff --git a/wpilibc/wpilibC++Sim/include/Relay.h b/wpilibc/wpilibC++Sim/include/Relay.h index b1526f4e39..7f90c34df8 100644 --- a/wpilibc/wpilibC++Sim/include/Relay.h +++ b/wpilibc/wpilibC++Sim/include/Relay.h @@ -56,8 +56,6 @@ public: ITable *m_table = nullptr; private: - void InitRelay(); - uint32_t m_channel; Direction m_direction; SimContinuousOutput* impl; diff --git a/wpilibc/wpilibC++Sim/include/SafePWM.h b/wpilibc/wpilibC++Sim/include/SafePWM.h index 569665e9cd..d0d2d7bd93 100644 --- a/wpilibc/wpilibC++Sim/include/SafePWM.h +++ b/wpilibc/wpilibC++Sim/include/SafePWM.h @@ -33,6 +33,5 @@ public: virtual void SetSpeed(float speed); private: - void InitSafePWM(); MotorSafetyHelper *m_safetyHelper; }; diff --git a/wpilibc/wpilibC++Sim/include/Solenoid.h b/wpilibc/wpilibC++Sim/include/Solenoid.h index a3b346197c..3cc6ab7adf 100644 --- a/wpilibc/wpilibC++Sim/include/Solenoid.h +++ b/wpilibc/wpilibC++Sim/include/Solenoid.h @@ -33,7 +33,6 @@ public: ITable * GetTable() const override; private: - void InitSolenoid(int slot, int channel); SimContinuousOutput* m_impl; bool m_on; diff --git a/wpilibc/wpilibC++Sim/include/Talon.h b/wpilibc/wpilibC++Sim/include/Talon.h index 4a4e0db639..4b7794a8e1 100644 --- a/wpilibc/wpilibC++Sim/include/Talon.h +++ b/wpilibc/wpilibC++Sim/include/Talon.h @@ -22,7 +22,4 @@ public: virtual void Disable(); virtual void PIDWrite(float output) override; - -private: - void InitTalon(); }; diff --git a/wpilibc/wpilibC++Sim/include/Victor.h b/wpilibc/wpilibC++Sim/include/Victor.h index fb779ffde8..b629bb4ade 100644 --- a/wpilibc/wpilibC++Sim/include/Victor.h +++ b/wpilibc/wpilibC++Sim/include/Victor.h @@ -22,7 +22,4 @@ public: virtual void Disable(); virtual void PIDWrite(float output) override; - -private: - void InitVictor(); }; diff --git a/wpilibc/wpilibC++Sim/src/AnalogInput.cpp b/wpilibc/wpilibC++Sim/src/AnalogInput.cpp index aba1fb1813..29032d818c 100644 --- a/wpilibc/wpilibC++Sim/src/AnalogInput.cpp +++ b/wpilibc/wpilibC++Sim/src/AnalogInput.cpp @@ -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(). diff --git a/wpilibc/wpilibC++Sim/src/DigitalInput.cpp b/wpilibc/wpilibC++Sim/src/DigitalInput.cpp index f9bddaed2f..a4b15c065b 100644 --- a/wpilibc/wpilibC++Sim/src/DigitalInput.cpp +++ b/wpilibc/wpilibC++Sim/src/DigitalInput.cpp @@ -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); } /* diff --git a/wpilibc/wpilibC++Sim/src/DoubleSolenoid.cpp b/wpilibc/wpilibC++Sim/src/DoubleSolenoid.cpp index 3e67df07ba..2fa6709c1f 100644 --- a/wpilibc/wpilibC++Sim/src/DoubleSolenoid.cpp +++ b/wpilibc/wpilibC++Sim/src/DoubleSolenoid.cpp @@ -9,26 +9,6 @@ #include #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); } /** diff --git a/wpilibc/wpilibC++Sim/src/Jaguar.cpp b/wpilibc/wpilibC++Sim/src/Jaguar.cpp index bd5ca85351..fab109d578 100644 --- a/wpilibc/wpilibC++Sim/src/Jaguar.cpp +++ b/wpilibc/wpilibC++Sim/src/Jaguar.cpp @@ -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. * diff --git a/wpilibc/wpilibC++Sim/src/Joystick.cpp b/wpilibc/wpilibC++Sim/src/Joystick.cpp index 06171a330f..01439dafe0 100644 --- a/wpilibc/wpilibC++Sim/src/Joystick.cpp +++ b/wpilibc/wpilibC++Sim/src/Joystick.cpp @@ -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 ) { diff --git a/wpilibc/wpilibC++Sim/src/PWM.cpp b/wpilibc/wpilibC++Sim/src/PWM.cpp index 3557f57e68..6e5078b43e 100644 --- a/wpilibc/wpilibC++Sim/src/PWM.cpp +++ b/wpilibc/wpilibC++Sim/src/PWM.cpp @@ -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 diff --git a/wpilibc/wpilibC++Sim/src/Relay.cpp b/wpilibc/wpilibC++Sim/src/Relay.cpp index d136526ebe..9f92a8fb54 100644 --- a/wpilibc/wpilibC++Sim/src/Relay.cpp +++ b/wpilibc/wpilibC++Sim/src/Relay.cpp @@ -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. diff --git a/wpilibc/wpilibC++Sim/src/SafePWM.cpp b/wpilibc/wpilibC++Sim/src/SafePWM.cpp index b5c4c42022..ab57c21c14 100644 --- a/wpilibc/wpilibC++Sim/src/SafePWM.cpp +++ b/wpilibc/wpilibC++Sim/src/SafePWM.cpp @@ -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() diff --git a/wpilibc/wpilibC++Sim/src/Solenoid.cpp b/wpilibc/wpilibC++Sim/src/Solenoid.cpp index b113d6cafd..9cfbc945ec 100644 --- a/wpilibc/wpilibC++Sim/src/Solenoid.cpp +++ b/wpilibc/wpilibC++Sim/src/Solenoid.cpp @@ -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); } /** diff --git a/wpilibc/wpilibC++Sim/src/Talon.cpp b/wpilibc/wpilibC++Sim/src/Talon.cpp index a506c95ffe..0e9505dbf4 100644 --- a/wpilibc/wpilibC++Sim/src/Talon.cpp +++ b/wpilibc/wpilibC++Sim/src/Talon.cpp @@ -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); } /** diff --git a/wpilibc/wpilibC++Sim/src/Victor.cpp b/wpilibc/wpilibC++Sim/src/Victor.cpp index ed4bf73b43..54ba61fd8d 100644 --- a/wpilibc/wpilibC++Sim/src/Victor.cpp +++ b/wpilibc/wpilibC++Sim/src/Victor.cpp @@ -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); } /**