YARP
Yet Another Robot Platform
BatteryClient.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 
10 #include <yarp/os/Network.h>
11 #include <yarp/os/BufferedPort.h>
13 #include <yarp/dev/IBattery.h>
16 #include <yarp/sig/Vector.h>
17 #include <yarp/os/Time.h>
18 #include <yarp/dev/PolyDriver.h>
19 
20 #include <mutex>
21 
22 
23 #define DEFAULT_THREAD_PERIOD 20 //ms
24 const int BATTERY_TIMEOUT=100; //ms
25 
26 
27 class BatteryInputPortProcessor : public yarp::os::BufferedPort<yarp::os::Bottle>
28 {
29  yarp::os::Bottle lastBottle;
30  std::mutex mutex;
31  yarp::os::Stamp lastStamp;
32  double deltaT;
33  double deltaTMax;
34  double deltaTMin;
35  double prev;
36  double now;
37 
38  int state;
39  int count;
40 
41 public:
42 
43  inline void resetStat();
44 
46 
48  void onRead(yarp::os::Bottle &v) override;
49 
50  inline int getLast(yarp::os::Bottle &data, yarp::os::Stamp &stmp);
51 
52  inline int getIterations();
53 
54  // time is in ms
55  void getEstFrequency(int &ite, double &av, double &min, double &max);
56 
57  double getVoltage();
58  double getCurrent();
59  double getCharge();
60  double getTemperature();
61  int getStatus();
62 
63 };
64 
74  public yarp::dev::IBattery
75 {
76 protected:
79  std::string local;
80  std::string remote;
81  yarp::os::Stamp lastTs; //used by IPreciselyTimed
82  std::string deviceId;
83 
84 public:
85 
86  /* DeviceDriver methods */
87  bool open(yarp::os::Searchable& config) override;
88  bool close() override;
89 
90 
91  /* IPreciselyTimed methods */
97 
103  bool getBatteryVoltage(double &voltage) override;
104 
110  bool getBatteryCurrent(double &current) override;
111 
117  bool getBatteryCharge(double &charge) override;
118 
124  bool getBatteryStatus(Battery_status &status) override;
125 
131  bool getBatteryInfo(std::string &battery_info) override;
132 
138  bool getBatteryTemperature(double &temperature) override;
139 };
140 
141 #endif // YARP_DEV_BATTERYCLIENT_BATTERYCLIENT_H
const int BATTERY_TIMEOUT
Definition: BatteryClient.h:24
define control board standard interfaces
contains the definition of a Vector type
batteryClient: The client side of any IBattery capable device.
Definition: BatteryClient.h:75
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
std::string deviceId
Definition: BatteryClient.h:82
bool getBatteryCurrent(double &current) override
Get the instantaneous current measurement.
std::string local
Definition: BatteryClient.h:79
bool close() override
Close the DeviceDriver.
bool getBatteryTemperature(double &temperature) override
get the battery temperature
yarp::os::Stamp lastTs
Definition: BatteryClient.h:81
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
bool getBatteryVoltage(double &voltage) override
Get the instantaneous voltage measurement.
bool getBatteryInfo(std::string &battery_info) override
get the battery hardware charactestics (e.g.
std::string remote
Definition: BatteryClient.h:80
bool getBatteryStatus(Battery_status &status) override
get the battery status
bool getBatteryCharge(double &charge) override
get the battery status of charge
yarp::os::Port rpcPort
Definition: BatteryClient.h:78
BatteryInputPortProcessor inputPort
Definition: BatteryClient.h:77
int getLast(yarp::os::Bottle &data, yarp::os::Stamp &stmp)
void onRead(yarp::os::Bottle &v) override
void getEstFrequency(int &ite, double &av, double &min, double &max)
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
A generic battery interface.
Definition: IBattery.h:30
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:61
A mini-server for network communication.
Definition: Port.h:47
A base class for nested structures that can be searched.
Definition: Searchable.h:66
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:22