DiagnosticsSubUnit.cpp
Go to the documentation of this file.
2
4
5namespace 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
104
105 void
110
111} // namespace armarx
constexpr T c
dto::BatteryStatus getBatteryStatus(const Ice::Current &current) const override
void onInitComponent() override
Pure virtual hook for the subclass.
void update(const SensorAndControl &sc, const JointAndNJointControllers &c) override
void onConnectComponent() override
Pure virtual hook for the subclass.
std::map< std::string, std::size_t > _batteryManagementDevices
void setBatteryManagementDevices(std::map< std::string, std::size_t > batteryManagementDevices)
std::string getDefaultName() const override
Retrieve default name of component.
std::map< std::string, dto::BatteryStatus > _lastBatteryStatuses
The SensorValueBase class.
const T * asA() const
DETAIL_SensorValueBase_DEFAULT_METHOD_IMPLEMENTATION std::uint8_t state
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
This file offers overloads of toIce() and fromIce() functions for STL container types.
detail::ControlThreadOutputBufferEntry SensorAndControl
Structure used by the RobotUnit to swap lists of Joint and NJoint controllers.
std::vector< PropagateConst< SensorValueBase * > > sensors