YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Battery_nwc_yarp.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#ifndef YARP_DEV_BATTERYCLIENT_BATTERYCLIENT_H
7#define YARP_DEV_BATTERYCLIENT_BATTERYCLIENT_H
8
9#include <mutex>
10
11#include <yarp/os/Network.h>
14#include <yarp/dev/IBattery.h>
17#include <yarp/sig/Vector.h>
18#include <yarp/os/Time.h>
19#include <yarp/dev/PolyDriver.h>
21
22#include "IBatteryMsgs.h"
24
25#define DEFAULT_THREAD_PERIOD 20 //ms
26
27class Battery_InputPortProcessor : public yarp::os::BufferedPort<yarp::dev::BatteryData>
28{
29 const int BATTERY_TIMEOUT=100; //ms
30
32 std::mutex mutex;
33 yarp::os::Stamp lastStamp;
34 double deltaT;
35 double deltaTMax;
36 double deltaTMin;
37 double prev;
38 double now;
39
40 int state;
41 int count;
42
43public:
44
45 inline void resetStat();
46
48
50 void onRead(yarp::dev::BatteryData &v) override;
51
53
54 inline int getIterations();
55
56 // time is in ms
57 void getEstFrequency(int &ite, double &av, double &min, double &max);
58
59 double getVoltage();
60 double getCurrent();
61 double getCharge();
62 double getTemperature();
64
65};
66
80{
81protected:
85 yarp::os::Stamp lastTs; //used by IPreciselyTimed
86 std::string deviceId;
87
88public:
89
90 /* DeviceDriver methods */
91 bool open(yarp::os::Searchable& config) override;
92 bool close() override;
93
94
95 /* IPreciselyTimed methods */
101
107 yarp::dev::ReturnValue getBatteryVoltage(double &voltage) override;
108
114 yarp::dev::ReturnValue getBatteryCurrent(double &current) override;
115
121 yarp::dev::ReturnValue getBatteryCharge(double &charge) override;
122
129
135 yarp::dev::ReturnValue getBatteryInfo(std::string &battery_info) override;
136
142 yarp::dev::ReturnValue getBatteryTemperature(double &temperature) override;
143};
144
145#endif // YARP_DEV_BATTERYCLIENT_BATTERYCLIENT_H
define control board standard interfaces
contains the definition of a Vector type
yarp::dev::IBattery::Battery_status getStatus()
void onRead(yarp::dev::BatteryData &v) override
int getLast(yarp::dev::BatteryData &data, yarp::os::Stamp &stmp)
void getEstFrequency(int &ite, double &av, double &min, double &max)
This class is the parameters parser for class Battery_nwc_yarp.
Battery_nwc_yarp: The client side of any IBattery capable device.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getBatteryVoltage(double &voltage) override
Get the instantaneous voltage measurement.
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
IBatteryMsgs m_battery_RPC
Battery_InputPortProcessor inputPort
yarp::dev::ReturnValue getBatteryCharge(double &charge) override
get the battery status of charge
yarp::dev::ReturnValue getBatteryStatus(yarp::dev::IBattery::Battery_status &status) override
get the battery status
yarp::dev::ReturnValue getBatteryTemperature(double &temperature) override
get the battery temperature
yarp::dev::ReturnValue getBatteryInfo(std::string &battery_info) override
get the battery hardware characteristics (e.g.
yarp::os::Stamp lastTs
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::os::Port rpcPort
yarp::dev::ReturnValue getBatteryCurrent(double &current) override
Get the instantaneous current measurement.
Interface implemented by all device drivers.
A generic battery interface.
Definition IBattery.h:26
A mini-server for performing network communication in the background.
A mini-server for network communication.
Definition Port.h:46
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21