YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Battery_nws_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_BATTERYWRAPPER_H
7#define YARP_DEV_BATTERYWRAPPER_H
8
9#include <vector>
10#include <iostream>
11#include <string>
12#include <sstream>
13#include <cmath>
14
15#include <yarp/os/Network.h>
16#include <yarp/os/Port.h>
18#include <yarp/os/Bottle.h>
19#include <yarp/os/Time.h>
20#include <yarp/os/Property.h>
21
24#include <yarp/os/Stamp.h>
25
26#include <yarp/sig/Vector.h>
27
28#include <yarp/dev/IBattery.h>
29#include <yarp/dev/PolyDriver.h>
32#include <yarp/dev/api.h>
34
35#include "IBatteryMsgs.h"
36
38
39#define DEFAULT_THREAD_PERIOD 0.02 //s
40
41// rpc commands
43{
44private:
45 std::mutex m_mutex;
46 yarp::dev::IBattery* m_iBat{nullptr};
47
48public:
51 ~IBatteryMsgsImpl() = default;
52
53public:
54 std::mutex* getMutex() { return &m_mutex; }
55};
56
57
74{
75public:
78
79 bool open(yarp::os::Searchable &params) override;
80 bool close() override;
81
82 bool threadInit() override;
83 void threadRelease() override;
84 void run() override;
85
86private:
87
88 yarp::dev::IBattery *m_ibattery_p = nullptr;
89 std::unique_ptr<IBatteryMsgsImpl> m_msgsImpl;
90
91 //ports stuff
92 std::string m_streamingPortName;
93 std::string m_rpcPortName;
94 yarp::os::Port m_rpcPort;
96
97 //data
98 double m_battery_charge = std::nan("");
99 double m_battery_voltage = std::nan("");
100 double m_battery_current = std::nan("");
101 double m_battery_temperature = std::nan("");
103
104 yarp::os::Stamp m_lastStateStamp;
105 double m_period;
106 std::string m_sensorId;
107
108 //log stuff
109 char m_log_buffer[1024];
110 FILE *m_logFile=nullptr;
111
112 //public methods
113 bool read(yarp::os::ConnectionReader& connection) override;
114
115private:
116 //private methods
117 bool attach(yarp::dev::PolyDriver* driver) override;
118 bool detach() override;
119
120 //internal methods to handle particular statuses of the battery
121 bool initialize_YARP(yarp::os::Searchable &config);
122 void notify_message(std::string msg);
123 void emergency_shutdown(std::string msg);
124 void check_battery_status(double battery_charge);
125 void stop_robot(std::string quit_port);
126};
127
128#endif // YARP_DEV_BATTERYWRAPPER_H
contains the definition of a Vector type
This class is the parameters parser for class Battery_nws_yarp.
Battery_nws_yarp: Device that expose a battery sensor (using the IBattery interface) on the YARP netw...
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
void threadRelease() override
Release method.
bool threadInit() override
Initialization method.
void run() override
Loop function.
bool close() override
Close the DeviceDriver.
std::mutex * getMutex()
return_get_BatteryInfo getBatteryInfoRPC() override
~IBatteryMsgsImpl()=default
Interface implemented by all device drivers.
A generic battery interface.
Definition IBattery.h:26
A container for a device driver.
Definition PolyDriver.h:23
Helper interface for an object that can wrap/or "attach" to a single other device.
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An abstraction for a periodic thread.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
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