2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2014-05-30 14:04:05 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-10-29 12:49:17 -07:00
|
|
|
#include <hal/Types.h>
|
2021-06-13 16:38:05 -07:00
|
|
|
#include <wpi/sendable/Sendable.h>
|
|
|
|
|
#include <wpi/sendable/SendableHelper.h>
|
2014-05-30 14:04:05 -04:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2014-05-30 14:04:05 -04:00
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Class for getting voltage, current, temperature, power and energy from the
|
|
|
|
|
* CAN PDP.
|
2014-05-30 14:04:05 -04:00
|
|
|
*/
|
2021-08-04 20:31:17 -07:00
|
|
|
class PowerDistribution : public wpi::Sendable,
|
|
|
|
|
public wpi::SendableHelper<PowerDistribution> {
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
2021-08-14 11:44:56 -07:00
|
|
|
static constexpr int kDefaultModule = -1;
|
2021-11-23 23:03:45 -08:00
|
|
|
enum class ModuleType { kCTRE = 1, kRev = 2 };
|
2021-08-14 11:44:56 -07:00
|
|
|
|
2021-06-10 00:02:51 -07:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Constructs a PowerDistribution.
|
2021-06-10 00:02:51 -07:00
|
|
|
*
|
2021-11-23 23:03:45 -08:00
|
|
|
* Uses the default CAN ID (0 for CTRE and 1 for REV).
|
2021-06-10 00:02:51 -07:00
|
|
|
*/
|
2021-08-04 20:31:17 -07:00
|
|
|
PowerDistribution();
|
2021-06-10 00:02:51 -07:00
|
|
|
|
|
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Constructs a PowerDistribution.
|
2021-06-10 00:02:51 -07:00
|
|
|
*
|
|
|
|
|
* @param module The CAN ID of the PDP
|
2021-08-14 11:44:56 -07:00
|
|
|
* @param moduleType The type of module
|
2021-06-10 00:02:51 -07:00
|
|
|
*/
|
2021-08-14 11:44:56 -07:00
|
|
|
PowerDistribution(int module, ModuleType moduleType);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2021-08-14 11:44:56 -07:00
|
|
|
~PowerDistribution() override;
|
2021-08-04 20:31:17 -07:00
|
|
|
PowerDistribution(PowerDistribution&&) = default;
|
|
|
|
|
PowerDistribution& operator=(PowerDistribution&&) = default;
|
2018-09-24 00:08:25 -07:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Query the input voltage of the PDP.
|
|
|
|
|
*
|
|
|
|
|
* @return The voltage of the PDP in volts
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetVoltage() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query the temperature of the PDP.
|
|
|
|
|
*
|
|
|
|
|
* @return The temperature of the PDP in degrees Celsius
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetTemperature() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query the current of a single channel of the PDP.
|
|
|
|
|
*
|
|
|
|
|
* @return The current of one of the PDP channels (channels 0-15) in Amperes
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetCurrent(int channel) const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query the total current of all monitored PDP channels (0-15).
|
|
|
|
|
*
|
|
|
|
|
* @return The the total current drawn from the PDP channels in Amperes
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetTotalCurrent() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query the total power drawn from the monitored PDP channels.
|
|
|
|
|
*
|
|
|
|
|
* @return The the total power drawn from the PDP channels in Watts
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetTotalPower() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query the total energy drawn from the monitored PDP channels.
|
|
|
|
|
*
|
|
|
|
|
* @return The the total energy drawn from the PDP channels in Joules
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetTotalEnergy() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset the total energy drawn from the PDP.
|
|
|
|
|
*
|
2021-08-04 20:31:17 -07:00
|
|
|
* @see PowerDistribution#GetTotalEnergy
|
2018-05-31 20:47:15 -07:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void ResetTotalEnergy();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove all of the fault flags on the PDP.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void ClearStickyFaults();
|
2014-12-30 12:02:13 -08:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
/**
|
|
|
|
|
* Gets module number (CAN ID).
|
|
|
|
|
*/
|
|
|
|
|
int GetModule() const;
|
|
|
|
|
|
2021-08-14 11:44:56 -07:00
|
|
|
bool GetSwitchableChannel() const;
|
|
|
|
|
|
|
|
|
|
void SetSwitchableChannel(bool enabled);
|
|
|
|
|
|
2021-12-19 13:42:49 -08:00
|
|
|
struct Version {
|
|
|
|
|
uint32_t FirmwareMajor;
|
|
|
|
|
uint32_t FirmwareMinor;
|
|
|
|
|
uint32_t FirmwareFix;
|
|
|
|
|
uint32_t FardwareMinor;
|
|
|
|
|
uint32_t FardwareMajor;
|
|
|
|
|
uint32_t UniqueId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Version GetVersion() const;
|
|
|
|
|
|
|
|
|
|
struct Faults {
|
|
|
|
|
uint32_t Channel0BreakerFault : 1;
|
|
|
|
|
uint32_t Channel1BreakerFault : 1;
|
|
|
|
|
uint32_t Channel2BreakerFault : 1;
|
|
|
|
|
uint32_t Channel3BreakerFault : 1;
|
|
|
|
|
uint32_t Channel4BreakerFault : 1;
|
|
|
|
|
uint32_t Channel5BreakerFault : 1;
|
|
|
|
|
uint32_t Channel6BreakerFault : 1;
|
|
|
|
|
uint32_t Channel7BreakerFault : 1;
|
|
|
|
|
uint32_t Channel8BreakerFault : 1;
|
|
|
|
|
uint32_t Channel9BreakerFault : 1;
|
|
|
|
|
uint32_t Channel10BreakerFault : 1;
|
|
|
|
|
uint32_t Channel11BreakerFault : 1;
|
|
|
|
|
uint32_t Channel12BreakerFault : 1;
|
|
|
|
|
uint32_t Channel13BreakerFault : 1;
|
|
|
|
|
uint32_t Channel14BreakerFault : 1;
|
|
|
|
|
uint32_t Channel15BreakerFault : 1;
|
|
|
|
|
uint32_t Channel16BreakerFault : 1;
|
|
|
|
|
uint32_t Channel17BreakerFault : 1;
|
|
|
|
|
uint32_t Channel18BreakerFault : 1;
|
|
|
|
|
uint32_t Channel19BreakerFault : 1;
|
|
|
|
|
uint32_t Channel20BreakerFault : 1;
|
|
|
|
|
uint32_t Channel21BreakerFault : 1;
|
|
|
|
|
uint32_t Channel22BreakerFault : 1;
|
|
|
|
|
uint32_t Channel23BreakerFault : 1;
|
|
|
|
|
uint32_t Brownout : 1;
|
|
|
|
|
uint32_t CanWarning : 1;
|
|
|
|
|
uint32_t HardwareFault : 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Faults GetFaults() const;
|
|
|
|
|
|
|
|
|
|
struct StickyFaults {
|
|
|
|
|
uint32_t Channel0BreakerFault : 1;
|
|
|
|
|
uint32_t Channel1BreakerFault : 1;
|
|
|
|
|
uint32_t Channel2BreakerFault : 1;
|
|
|
|
|
uint32_t Channel3BreakerFault : 1;
|
|
|
|
|
uint32_t Channel4BreakerFault : 1;
|
|
|
|
|
uint32_t Channel5BreakerFault : 1;
|
|
|
|
|
uint32_t Channel6BreakerFault : 1;
|
|
|
|
|
uint32_t Channel7BreakerFault : 1;
|
|
|
|
|
uint32_t Channel8BreakerFault : 1;
|
|
|
|
|
uint32_t Channel9BreakerFault : 1;
|
|
|
|
|
uint32_t Channel10BreakerFault : 1;
|
|
|
|
|
uint32_t Channel11BreakerFault : 1;
|
|
|
|
|
uint32_t Channel12BreakerFault : 1;
|
|
|
|
|
uint32_t Channel13BreakerFault : 1;
|
|
|
|
|
uint32_t Channel14BreakerFault : 1;
|
|
|
|
|
uint32_t Channel15BreakerFault : 1;
|
|
|
|
|
uint32_t Channel16BreakerFault : 1;
|
|
|
|
|
uint32_t Channel17BreakerFault : 1;
|
|
|
|
|
uint32_t Channel18BreakerFault : 1;
|
|
|
|
|
uint32_t Channel19BreakerFault : 1;
|
|
|
|
|
uint32_t Channel20BreakerFault : 1;
|
|
|
|
|
uint32_t Channel21BreakerFault : 1;
|
|
|
|
|
uint32_t Channel22BreakerFault : 1;
|
|
|
|
|
uint32_t Channel23BreakerFault : 1;
|
|
|
|
|
uint32_t Brownout : 1;
|
|
|
|
|
uint32_t CanWarning : 1;
|
|
|
|
|
uint32_t CanBusOff : 1;
|
|
|
|
|
uint32_t HasReset : 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
StickyFaults GetStickyFaults() const;
|
|
|
|
|
|
2021-06-13 16:38:05 -07:00
|
|
|
void InitSendable(wpi::SendableBuilder& builder) override;
|
2014-12-30 12:02:13 -08:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
2021-08-14 11:44:56 -07:00
|
|
|
hal::Handle<HAL_PowerDistributionHandle> m_handle;
|
2020-07-04 10:10:43 -07:00
|
|
|
int m_module;
|
2014-05-30 14:04:05 -04:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|