DiagnosticsSubUnit.cpp
Go to the documentation of this file.
1 #include "DiagnosticsSubUnit.h"
2 
4 
5 namespace armarx
6 {
7 
8  dto::BatteryStatus
9  DiagnosticsSubUnit::getBatteryStatus(const Ice::Current& current) const
10  {
11  // This diagnostics sub unit should rather report the status report of each battery module,
12  // and additionally an accumulated one for easy use. Detailed reports of each battery module
13  // are important in order to identify faulty modules more quickly. At this point, due to
14  // firmware limitations and only being allowed to return one sensor value per device in the
15  // realtime part, the diagnostics unit now only reports the accumulated values and nothing
16  // else. In future, a dto::BatteryStatus struct must be reported for each battery module, in
17  // addition to one dto::BatteryStatus that accumulates all data. For this, the firmware of
18  // the power board needs to be adjusted to report this data, the EtherCAT SDOs need to be
19  // updated, and the device in devices::ethercat needs to be updated to report more than one
20  // sensor value. Additionally, the BatteryManagement Ice interface needs to be adjusted to
21  // report multiple BatteryStatus structs. Similar to this:
22  //
23  // struct BatteryManagementReport
24  // {
25  // map<string, dto::BatteryStatus> detailedReports;
26  // dto::BatteryStatus cumulativeReport;
27  // };
28  //
29  if (_lastBatteryStatuses.size() > 0 and
30  _lastBatteryStatuses.find("PowerBoard") != _lastBatteryStatuses.end())
31  {
32  return _lastBatteryStatuses.at("PowerBoard");
33  }
34 
35  return {.name = "PowerBoard",
36  .state = dto::BatteryState::unavailable,
37  .designEnergy_Wh = -1,
38  .fullChargeEnergy_Wh = -1,
39  .energy_Wh = -1,
40  .energyFromFullCharge_pct = 0,
41  .fullEnergyFromDesignEnergy_pct = 0,
42  .temperature_degC = -1,
43  .ratedVoltage_V = -1,
44  .voltage_V = -1,
45  .current_A = -1,
46  .power_W = -1,
47  .remainingTime_h = -1,
48  .hasError = false,
49  .error = ""};
50  }
51 
52  std::string
54  {
55  return "DiagnosticsSubUnit";
56  }
57 
58  void
60  {
61  for (auto& [deviceName, deviceIndex] : _batteryManagementDevices)
62  {
63  const SensorValueBase* sv = sc.sensors.at(deviceIndex).get();
66 
67  auto& stat = _lastBatteryStatuses[deviceName];
68  stat.name = deviceName;
69  stat.state = static_cast<dto::BatteryState>(s->state);
70  stat.designEnergy_Wh = s->designEnergy_Wh;
71  stat.fullChargeEnergy_Wh = s->fullChargeEnergy_Wh;
72  stat.energy_Wh = s->energy_Wh;
73  stat.energyFromFullCharge_pct = s->energyFromFullCharge_pct;
74  stat.fullEnergyFromDesignEnergy_pct = s->fullEnergyFromDesignEnergy_pct;
75  stat.temperature_degC = s->temperature_degC;
76  stat.ratedVoltage_V = s->ratedVoltage_V;
77  stat.voltage_V = s->voltage_V;
78  stat.current_A = s->current_A;
79  stat.power_W = s->power_W;
80  stat.remainingTime_h = s->remainingTime_h;
81  stat.hasError = s->hasError;
82  stat.error =
83  ""; // TODO: How to transfer strings from RT? Maybe get rid of this or error codes.
84  }
85  }
86 
87  void
89  std::map<std::string, std::size_t> batteryManagementDevices)
90  {
91  _batteryManagementDevices = batteryManagementDevices;
92 
93  for (auto& [deviceName, deviceIndex] : _batteryManagementDevices)
94  {
95  _lastBatteryStatuses[deviceName] = {};
96  }
97  }
98 
99  void
101  {
102  ;
103  }
104 
105  void
107  {
108  ;
109  }
110 
111 } // namespace armarx
armarx::JointAndNJointControllers
Structure used by the RobotUnit to swap lists of Joint and NJoint controllers.
Definition: JointAndNJointControllers.h:32
armarx::SensorValueBattery::power_W
float power_W
Definition: SensorValueBattery.h:34
armarx::SensorValueBase::asA
const T * asA() const
Definition: SensorValueBase.h:82
armarx::SensorValueBase
The SensorValueBase class.
Definition: SensorValueBase.h:40
SensorValueBattery.h
armarx::SensorValueBattery::remainingTime_h
float remainingTime_h
Definition: SensorValueBattery.h:35
armarx::SensorValueBattery::fullChargeEnergy_Wh
float fullChargeEnergy_Wh
Definition: SensorValueBattery.h:26
armarx::SensorValueBattery::hasError
bool hasError
Definition: SensorValueBattery.h:36
armarx::detail::ControlThreadOutputBufferEntry::sensors
std::vector< PropagateConst< SensorValueBase * > > sensors
Definition: ControlThreadOutputBuffer.h:203
armarx::SensorValueBattery::energyFromFullCharge_pct
float energyFromFullCharge_pct
Definition: SensorValueBattery.h:28
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::BatteryState
BatteryState
Definition: SensorValueBattery.h:10
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::SensorValueBattery::fullEnergyFromDesignEnergy_pct
float fullEnergyFromDesignEnergy_pct
Definition: SensorValueBattery.h:29
armarx::SensorValueBattery::state
DETAIL_SensorValueBase_DEFAULT_METHOD_IMPLEMENTATION std::uint8_t state
Definition: SensorValueBattery.h:24
armarx::SensorValueBattery::ratedVoltage_V
float ratedVoltage_V
Definition: SensorValueBattery.h:31
armarx::DiagnosticsSubUnit::_lastBatteryStatuses
std::map< std::string, dto::BatteryStatus > _lastBatteryStatuses
Definition: DiagnosticsSubUnit.h:35
armarx::SensorValueBattery::voltage_V
float voltage_V
Definition: SensorValueBattery.h:32
DiagnosticsSubUnit.h
armarx::SensorValueBattery::designEnergy_Wh
float designEnergy_Wh
Definition: SensorValueBattery.h:25
armarx::SensorValueBattery::energy_Wh
float energy_Wh
Definition: SensorValueBattery.h:27
armarx::DiagnosticsSubUnit::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: DiagnosticsSubUnit.cpp:53
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::DiagnosticsSubUnit::getBatteryStatus
dto::BatteryStatus getBatteryStatus(const Ice::Current &current) const override
Definition: DiagnosticsSubUnit.cpp:9
armarx::SensorValueBattery::current_A
float current_A
Definition: SensorValueBattery.h:33
armarx::DiagnosticsSubUnit::_batteryManagementDevices
std::map< std::string, std::size_t > _batteryManagementDevices
Definition: DiagnosticsSubUnit.h:33
armarx::SensorValueBattery
Definition: SensorValueBattery.h:19
armarx::DiagnosticsSubUnit::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: DiagnosticsSubUnit.cpp:106
armarx::DiagnosticsSubUnit::setBatteryManagementDevices
void setBatteryManagementDevices(std::map< std::string, std::size_t > batteryManagementDevices)
Definition: DiagnosticsSubUnit.cpp:88
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::DiagnosticsSubUnit::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: DiagnosticsSubUnit.cpp:100
armarx::SensorValueBattery::temperature_degC
float temperature_degC
Definition: SensorValueBattery.h:30
armarx::SensorValueBase::isA
bool isA() const
Definition: SensorValueBase.h:75
armarx::DiagnosticsSubUnit::update
void update(const SensorAndControl &sc, const JointAndNJointControllers &c) override
Definition: DiagnosticsSubUnit.cpp:59