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.
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
#include "frc/simulation/CallbackStore.h"
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
namespace frc {
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-08-04 20:31:17 -07:00
|
|
|
class PowerDistribution;
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
namespace sim {
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Class to control a simulated Power Distribution Panel (PowerDistribution).
|
2020-07-04 10:10:43 -07:00
|
|
|
*/
|
2021-08-04 20:31:17 -07:00
|
|
|
class PowerDistributionSim {
|
2018-05-11 12:38:23 -07:00
|
|
|
public:
|
2020-07-04 10:10:43 -07:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Constructs from a PowerDistribution module number (CAN ID).
|
2020-07-04 10:10:43 -07:00
|
|
|
*
|
|
|
|
|
* @param module module number
|
|
|
|
|
*/
|
2021-08-04 20:31:17 -07:00
|
|
|
explicit PowerDistributionSim(int module = 0);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Constructs from a PowerDistribution object.
|
2020-07-04 10:10:43 -07:00
|
|
|
*
|
2021-08-04 20:31:17 -07:00
|
|
|
* @param pdp PowerDistribution to simulate
|
2020-07-04 10:10:43 -07:00
|
|
|
*/
|
2021-08-04 20:31:17 -07:00
|
|
|
explicit PowerDistributionSim(const PowerDistribution& pdp);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Register a callback to be run when the PowerDistribution is initialized.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
|
|
|
|
* @param callback the callback
|
|
|
|
|
* @param initialNotify whether to run the callback with the initial state
|
|
|
|
|
* @return the CallbackStore object associated with this callback
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Check whether the PowerDistribution has been initialized.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
|
|
|
|
* @return true if initialized
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
bool GetInitialized() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Define whether the PowerDistribution has been initialized.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
|
|
|
|
* @param initialized whether this object is initialized
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetInitialized(bool initialized);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Register a callback to be run whenever the PowerDistribution temperature
|
|
|
|
|
* changes.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
|
|
|
|
* @param callback the callback
|
|
|
|
|
* @param initialNotify whether to call the callback with the initial state
|
|
|
|
|
* @return the CallbackStore object associated with this callback
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterTemperatureCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Check the temperature of the PowerDistribution.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2021-08-04 20:31:17 -07:00
|
|
|
* @return the PowerDistribution temperature
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetTemperature() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Define the PowerDistribution temperature.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2021-08-04 20:31:17 -07:00
|
|
|
* @param temperature the new PowerDistribution temperature
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetTemperature(double temperature);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Register a callback to be run whenever the PowerDistribution voltage
|
|
|
|
|
* changes.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
|
|
|
|
* @param callback the callback
|
|
|
|
|
* @param initialNotify whether to call the callback with the initial state
|
|
|
|
|
* @return the CallbackStore object associated with this callback
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterVoltageCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Check the PowerDistribution voltage.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2021-08-04 20:31:17 -07:00
|
|
|
* @return the PowerDistribution voltage.
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetVoltage() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Set the PowerDistribution voltage.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
2021-08-04 20:31:17 -07:00
|
|
|
* @param voltage the new PowerDistribution voltage
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetVoltage(double voltage);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Register a callback to be run whenever the current of a specific channel
|
|
|
|
|
* changes.
|
|
|
|
|
*
|
|
|
|
|
* @param channel the channel
|
|
|
|
|
* @param callback the callback
|
|
|
|
|
* @param initialNotify whether to call the callback with the initial state
|
|
|
|
|
* @return the CallbackStore object associated with this callback
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterCurrentCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
int channel, NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Read the current in one of the PowerDistribution channels.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
|
|
|
|
* @param channel the channel to check
|
|
|
|
|
* @return the current in the given channel
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetCurrent(int channel) const;
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change the current in the given channel.
|
|
|
|
|
*
|
|
|
|
|
* @param channel the channel to edit
|
|
|
|
|
* @param current the new current for the channel
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetCurrent(int channel, double current);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Read the current of all of the PowerDistribution channels.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
|
|
|
|
* @param currents output array; set to the current in each channel. The
|
2021-08-04 20:31:17 -07:00
|
|
|
* array must be big enough to hold all the PowerDistribution
|
|
|
|
|
* channels
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2021-08-14 11:44:56 -07:00
|
|
|
void GetAllCurrents(double* currents, int length) const;
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Change the current in all of the PowerDistribution channels.
|
2021-01-11 21:55:45 -08:00
|
|
|
*
|
|
|
|
|
* @param currents array containing the current values for each channel. The
|
2021-08-04 20:31:17 -07:00
|
|
|
* array must be big enough to hold all the PowerDistribution
|
|
|
|
|
* channels
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2021-08-14 11:44:56 -07:00
|
|
|
void SetAllCurrents(const double* currents, int length);
|
2020-07-15 23:48:09 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
2021-08-04 20:31:17 -07:00
|
|
|
* Reset all PowerDistribution simulation data.
|
2021-01-11 21:55:45 -08:00
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void ResetData();
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_index;
|
|
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|