YARP
Yet Another Robot Platform
fakeBattery.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_FAKEBATTERY_H
10 #define YARP_FAKEBATTERY_H
11 
12 #include <yarp/os/PeriodicThread.h>
13 #include <yarp/os/RpcServer.h>
14 
15 #include <yarp/dev/IBattery.h>
16 #include <yarp/dev/PolyDriver.h>
17 
18 #include <mutex>
19 
20 #include "FakeBatteryService.h"
21 
27 class FakeBattery :
29  public yarp::dev::IBattery,
31  public FakeBatteryService
32 {
33 protected:
34  std::mutex m_mutex;
35  double battery_charge {50.0};
36  double battery_voltage {30.0};
37  double battery_current {3.0};
38  double battery_temperature {20.0};
39  std::string battery_info {"Fake battery system v2.0"};
41 
42  bool debugEnable {false};
43 
45 public:
46  FakeBattery();
47  FakeBattery(const FakeBattery&) = delete;
48  FakeBattery(FakeBattery&&) = delete;
49  FakeBattery& operator=(const FakeBattery&) = delete;
51 
52  ~FakeBattery() override = default;
53 
54  // yarp::dev::DeviceDriver
55  bool open(yarp::os::Searchable& config) override;
56  bool close() override;
57 
58  // yarp::os::PeriodicThread
59  void run() override;
60 
61  // yarp::dev::IBattery
62  bool getBatteryVoltage(double& voltage) override;
63  bool getBatteryCurrent(double& current) override;
64  bool getBatteryCharge(double& charge) override;
65  bool getBatteryStatus(Battery_status& status) override;
66  bool getBatteryInfo(std::string& info) override;
67  bool getBatteryTemperature(double& temperature) override;
68 
69  // FakeBatteryService
70  void setBatteryVoltage(const double voltage) override;
71  void setBatteryCurrent(const double current) override;
72  void setBatteryCharge(const double charge) override;
73  void setBatteryInfo(const std::string& info) override;
74  void setBatteryTemperature(const double temperature) override;
75  double getBatteryVoltage() override;
76  double getBatteryCurrent() override;
77  double getBatteryCharge() override;
78  std::string getBatteryStatus() override;
79  std::string getBatteryInfo() override;
80  double getBatteryTemperature() override;
81 
82 private:
83  void updateStatus();
84 };
85 
86 #endif
FakeBattery::operator=
FakeBattery & operator=(const FakeBattery &)=delete
yarp::dev::IBattery::Battery_status
Battery_status
Definition: IBattery.h:36
FakeBattery::debugEnable
bool debugEnable
Definition: fakeBattery.h:42
FakeBattery::close
bool close() override
Close the DeviceDriver.
Definition: fakeBattery.cpp:72
FakeBattery::battery_info
std::string battery_info
Definition: fakeBattery.h:39
FakeBatteryService.h
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
FakeBattery::FakeBattery
FakeBattery(FakeBattery &&)=delete
FakeBattery::FakeBattery
FakeBattery()
Definition: fakeBattery.cpp:33
FakeBattery::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: fakeBattery.cpp:39
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
FakeBattery::run
void run() override
Loop function.
Definition: fakeBattery.cpp:83
FakeBattery::getBatteryVoltage
double getBatteryVoltage() override
Definition: fakeBattery.cpp:169
FakeBattery::getBatteryTemperature
double getBatteryTemperature() override
Definition: fakeBattery.cpp:216
FakeBattery::getBatteryCharge
double getBatteryCharge() override
Definition: fakeBattery.cpp:181
FakeBattery::m_mutex
std::mutex m_mutex
Definition: fakeBattery.h:34
FakeBattery::getBatteryInfo
std::string getBatteryInfo() override
Definition: fakeBattery.cpp:210
FakeBattery::setBatteryCharge
void setBatteryCharge(const double charge) override
Definition: fakeBattery.cpp:150
FakeBatteryService
Definition: FakeBatteryService.h:22
FakeBattery::battery_charge
double battery_charge
Definition: fakeBattery.h:35
FakeBattery::battery_temperature
double battery_temperature
Definition: fakeBattery.h:38
FakeBattery::operator=
FakeBattery & operator=(FakeBattery &&)=delete
RpcServer.h
PolyDriver.h
yarp::os::RpcServer
A port that is specialized as an RPC server.
Definition: RpcServer.h:27
FakeBattery::battery_voltage
double battery_voltage
Definition: fakeBattery.h:36
yarp::dev::IBattery::BATTERY_OK_IN_USE
@ BATTERY_OK_IN_USE
Definition: IBattery.h:39
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
FakeBattery::ctrl_port
yarp::os::RpcServer ctrl_port
Definition: fakeBattery.h:44
FakeBattery::setBatteryVoltage
void setBatteryVoltage(const double voltage) override
Definition: fakeBattery.cpp:136
PeriodicThread.h
FakeBattery::setBatteryCurrent
void setBatteryCurrent(const double current) override
Definition: fakeBattery.cpp:143
FakeBattery
fakeBattery: Documentation to be added
Definition: fakeBattery.h:32
FakeBattery::~FakeBattery
~FakeBattery() override=default
FakeBattery::getBatteryCurrent
double getBatteryCurrent() override
Definition: fakeBattery.cpp:175
FakeBattery::setBatteryInfo
void setBatteryInfo(const std::string &info) override
Definition: fakeBattery.cpp:157
yarp::dev::IBattery
A generic battery interface.
Definition: IBattery.h:33
IBattery.h
FakeBattery::getBatteryStatus
std::string getBatteryStatus() override
Definition: fakeBattery.cpp:187
FakeBattery::battery_current
double battery_current
Definition: fakeBattery.h:37
FakeBattery::FakeBattery
FakeBattery(const FakeBattery &)=delete
FakeBattery::setBatteryTemperature
void setBatteryTemperature(const double temperature) override
Definition: fakeBattery.cpp:163
FakeBattery::battery_status
Battery_status battery_status
Definition: fakeBattery.h:40