WPILibC++  2020.3.2-60-g3011ebe
PDPSim.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 #include <utility>
12 
13 #include "CallbackStore.h"
14 #include "mockdata/PDPData.h"
15 
16 namespace frc {
17 namespace sim {
18 class PDPSim {
19  public:
20  explicit PDPSim(int index) { m_index = index; }
21 
22  std::unique_ptr<CallbackStore> RegisterInitializedCallback(
23  NotifyCallback callback, bool initialNotify) {
24  auto store = std::make_unique<CallbackStore>(
25  m_index, -1, callback, &HALSIM_CancelPDPInitializedCallback);
26  store->SetUid(HALSIM_RegisterPDPInitializedCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetInitialized() const { return HALSIM_GetPDPInitialized(m_index); }
32 
33  void SetInitialized(bool initialized) {
34  HALSIM_SetPDPInitialized(m_index, initialized);
35  }
36 
37  std::unique_ptr<CallbackStore> RegisterTemperatureCallback(
38  NotifyCallback callback, bool initialNotify) {
39  auto store = std::make_unique<CallbackStore>(
40  m_index, -1, callback, &HALSIM_CancelPDPTemperatureCallback);
41  store->SetUid(HALSIM_RegisterPDPTemperatureCallback(
42  m_index, &CallbackStoreThunk, store.get(), initialNotify));
43  return store;
44  }
45 
46  double GetTemperature() const { return HALSIM_GetPDPTemperature(m_index); }
47 
48  void SetTemperature(double temperature) {
49  HALSIM_SetPDPTemperature(m_index, temperature);
50  }
51 
52  std::unique_ptr<CallbackStore> RegisterVoltageCallback(
53  NotifyCallback callback, bool initialNotify) {
54  auto store = std::make_unique<CallbackStore>(
55  m_index, -1, callback, &HALSIM_CancelPDPVoltageCallback);
56  store->SetUid(HALSIM_RegisterPDPVoltageCallback(
57  m_index, &CallbackStoreThunk, store.get(), initialNotify));
58  return store;
59  }
60 
61  double GetVoltage() const { return HALSIM_GetPDPVoltage(m_index); }
62 
63  void SetVoltage(double voltage) { HALSIM_SetPDPVoltage(m_index, voltage); }
64 
65  std::unique_ptr<CallbackStore> RegisterCurrentCallback(
66  int channel, NotifyCallback callback, bool initialNotify) {
67  auto store = std::make_unique<CallbackStore>(
68  m_index, channel, -1, callback, &HALSIM_CancelPDPCurrentCallback);
69  store->SetUid(HALSIM_RegisterPDPCurrentCallback(
70  m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
71  return store;
72  }
73 
74  double GetCurrent(int channel) const {
75  return HALSIM_GetPDPCurrent(m_index, channel);
76  }
77 
78  void SetCurrent(int channel, double current) {
79  HALSIM_SetPDPCurrent(m_index, channel, current);
80  }
81 
82  void GetAllCurrents(double* currents) {
83  HALSIM_GetPDPAllCurrents(m_index, currents);
84  }
85 
86  void SetAllCurrents(const double* currents) {
87  HALSIM_SetPDPAllCurrents(m_index, currents);
88  }
89 
90  void ResetData() { HALSIM_ResetPDPData(m_index); }
91 
92  private:
93  int m_index;
94 };
95 } // namespace sim
96 } // namespace frc
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::sim::PDPSim
Definition: PDPSim.h:18