YARP
Yet Another Robot Platform
BatteryClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef YARP_DEV_BATTERYCLIENT_BATTERYCLIENT_H
20 #define YARP_DEV_BATTERYCLIENT_BATTERYCLIENT_H
21 
22 
23 #include <yarp/os/Network.h>
24 #include <yarp/os/BufferedPort.h>
26 #include <yarp/dev/IBattery.h>
29 #include <yarp/sig/Vector.h>
30 #include <yarp/os/Time.h>
31 #include <yarp/dev/PolyDriver.h>
32 
33 #include <mutex>
34 
35 
36 #define DEFAULT_THREAD_PERIOD 20 //ms
37 const int BATTERY_TIMEOUT=100; //ms
38 
39 
40 class BatteryInputPortProcessor : public yarp::os::BufferedPort<yarp::os::Bottle>
41 {
42  yarp::os::Bottle lastBottle;
43  std::mutex mutex;
44  yarp::os::Stamp lastStamp;
45  double deltaT;
46  double deltaTMax;
47  double deltaTMin;
48  double prev;
49  double now;
50 
51  int state;
52  int count;
53 
54 public:
55 
56  inline void resetStat();
57 
59 
61  void onRead(yarp::os::Bottle &v) override;
62 
63  inline int getLast(yarp::os::Bottle &data, yarp::os::Stamp &stmp);
64 
65  inline int getIterations();
66 
67  // time is in ms
68  void getEstFrequency(int &ite, double &av, double &min, double &max);
69 
70  double getVoltage();
71  double getCurrent();
72  double getCharge();
73  double getTemperature();
74  int getStatus();
75 
76 };
77 
87  public yarp::dev::IBattery
88 {
89 protected:
92  std::string local;
93  std::string remote;
94  yarp::os::Stamp lastTs; //used by IPreciselyTimed
95  std::string deviceId;
96 
97 public:
98 
99  /* DeviceDriver methods */
100  bool open(yarp::os::Searchable& config) override;
101  bool close() override;
102 
103 
104  /* IPreciselyTimed methods */
110 
116  bool getBatteryVoltage(double &voltage) override;
117 
123  bool getBatteryCurrent(double &current) override;
124 
130  bool getBatteryCharge(double &charge) override;
131 
137  bool getBatteryStatus(Battery_status &status) override;
138 
144  bool getBatteryInfo(std::string &battery_info) override;
145 
151  bool getBatteryTemperature(double &temperature) override;
152 };
153 
154 #endif // YARP_DEV_BATTERYCLIENT_BATTERYCLIENT_H
yarp::dev::IBattery::Battery_status
Battery_status
Definition: IBattery.h:36
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
Network.h
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
BatteryInputPortProcessor::getEstFrequency
void getEstFrequency(int &ite, double &av, double &min, double &max)
Definition: BatteryClient.cpp:168
BatteryInputPortProcessor::onRead
void onRead(yarp::os::Bottle &v) override
Definition: BatteryClient.cpp:53
Vector.h
contains the definition of a Vector type
BatteryInputPortProcessor::BatteryInputPortProcessor
BatteryInputPortProcessor()
Definition: BatteryClient.cpp:47
BatteryClient::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: BatteryClient.cpp:186
BatteryInputPortProcessor::getIterations
int getIterations()
Definition: BatteryClient.cpp:159
BatteryInputPortProcessor::getVoltage
double getVoltage()
Definition: BatteryClient.cpp:119
BatteryClient::getBatteryCurrent
bool getBatteryCurrent(double &current) override
Get the instantaneous current measurement.
Definition: BatteryClient.cpp:257
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
BatteryClient::getLastInputStamp
yarp::os::Stamp getLastInputStamp() override
Get the time stamp for the last read data.
Definition: BatteryClient.cpp:295
ControlBoardHelpers.h
BatteryInputPortProcessor::getLast
int getLast(yarp::os::Bottle &data, yarp::os::Stamp &stmp)
Definition: BatteryClient.cpp:105
BatteryClient::local
std::string local
Definition: BatteryClient.h:92
BatteryInputPortProcessor::getStatus
int getStatus()
Definition: BatteryClient.cpp:143
ControlBoardInterfaces.h
define control board standard interfaces
BatteryClient
batteryClient: The client side of any IBattery capable device.
Definition: BatteryClient.h:88
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:64
BatteryClient::inputPort
BatteryInputPortProcessor inputPort
Definition: BatteryClient.h:90
BatteryInputPortProcessor::getTemperature
double getTemperature()
Definition: BatteryClient.cpp:151
BatteryClient::getBatteryCharge
bool getBatteryCharge(double &charge) override
get the battery status of charge
Definition: BatteryClient.cpp:263
PolyDriver.h
BatteryInputPortProcessor::getCharge
double getCharge()
Definition: BatteryClient.cpp:135
BATTERY_TIMEOUT
const int BATTERY_TIMEOUT
Definition: BatteryClient.h:37
BatteryClient::close
bool close() override
Close the DeviceDriver.
Definition: BatteryClient.cpp:244
BufferedPort.h
BatteryClient::getBatteryTemperature
bool getBatteryTemperature(double &temperature) override
get the battery temperature
Definition: BatteryClient.cpp:275
BatteryClient::remote
std::string remote
Definition: BatteryClient.h:93
BatteryInputPortProcessor::resetStat
void resetStat()
Definition: BatteryClient.cpp:35
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
BatteryClient::getBatteryStatus
bool getBatteryStatus(Battery_status &status) override
get the battery status
Definition: BatteryClient.cpp:269
yarp::dev::IBattery
A generic battery interface.
Definition: IBattery.h:33
IBattery.h
BatteryInputPortProcessor::getCurrent
double getCurrent()
Definition: BatteryClient.cpp:127
BatteryClient::rpcPort
yarp::os::Port rpcPort
Definition: BatteryClient.h:91
BatteryInputPortProcessor
Definition: BatteryClient.h:41
Time.h
BatteryClient::getBatteryVoltage
bool getBatteryVoltage(double &voltage) override
Get the instantaneous voltage measurement.
Definition: BatteryClient.cpp:251
BatteryClient::lastTs
yarp::os::Stamp lastTs
Definition: BatteryClient.h:94
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
BatteryClient::getBatteryInfo
bool getBatteryInfo(std::string &battery_info) override
get the battery hardware charactestics (e.g.
Definition: BatteryClient.cpp:281
BatteryClient::deviceId
std::string deviceId
Definition: BatteryClient.h:95