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
|
|
|
|
|
|
|
|
class PowerDistributionPanel;
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
namespace sim {
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to control a simulated Power Distribution Panel (PDP).
|
|
|
|
|
*/
|
2018-05-11 12:38:23 -07:00
|
|
|
class PDPSim {
|
|
|
|
|
public:
|
2020-07-04 10:10:43 -07:00
|
|
|
/**
|
|
|
|
|
* Constructs from a PDP module number (CAN ID).
|
|
|
|
|
*
|
|
|
|
|
* @param module module number
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
explicit PDPSim(int module = 0);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs from a PowerDistributionPanel object.
|
|
|
|
|
*
|
|
|
|
|
* @param pdp PowerDistributionPanel to simulate
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
explicit PDPSim(const PowerDistributionPanel& pdp);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Register a callback to be run when the PDP is initialized.
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
|
* Check whether the PDP has been initialized.
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
|
* Define whether the PDP has been initialized.
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
|
* Register a callback to be run whenever the PDP temperature changes.
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
|
* Check the temperature of the PDP.
|
|
|
|
|
*
|
|
|
|
|
* @return the PDP temperature
|
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
|
* Define the PDP temperature.
|
|
|
|
|
*
|
|
|
|
|
* @param temperature the new PDP temperature
|
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
|
* Register a callback to be run whenever the PDP voltage changes.
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
|
* Check the PDP voltage.
|
|
|
|
|
*
|
|
|
|
|
* @return the PDP voltage.
|
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
|
* Set the PDP voltage.
|
|
|
|
|
*
|
|
|
|
|
* @param voltage the new PDP voltage
|
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
|
* Read the current in one of the PDP channels.
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
|
* Read the current of all of the PDP channels.
|
|
|
|
|
*
|
|
|
|
|
* @param currents output array; set to the current in each channel. The
|
|
|
|
|
* array must be big enough to hold all the PDP channels
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void GetAllCurrents(double* currents) const;
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Change the current in all of the PDP channels.
|
|
|
|
|
*
|
|
|
|
|
* @param currents array containing the current values for each channel. The
|
|
|
|
|
* array must be big enough to hold all the PDP channels
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetAllCurrents(const double* currents);
|
|
|
|
|
|
2021-01-11 21:55:45 -08:00
|
|
|
/**
|
|
|
|
|
* Reset all PDP simulation data.
|
|
|
|
|
*/
|
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
|