iCub-main
Loading...
Searching...
No Matches
bmsBattery.h
Go to the documentation of this file.
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3// Copyright: (C) 2015 iCub Facility
4// Authors: Marco Randazzo <marco.randazzo@iit.it>
5// CopyPolicy: Released under the terms of the GNU GPL v2.0.
6
7#ifndef __BMSBATTERY_H__
8#define __BMSBATTERY_H__
9
10#include <mutex>
11#include <yarp/os/PeriodicThread.h>
12#include <yarp/dev/IBattery.h>
13#include <yarp/dev/PolyDriver.h>
14#include <yarp/dev/ISerialDevice.h>
15#include <yarp/os/ResourceFinder.h>
16#include <yarp/sig/Vector.h>
17
18using namespace yarp::os;
19using namespace yarp::dev;
20
21class BmsBattery : public PeriodicThread, public yarp::dev::IBattery, public DeviceDriver
22{
23protected:
24 std::mutex mtx;
25
26 unsigned short batteryId;
27 short status;
28 double timeStamp;
29 yarp::sig::Vector data;
34 std::string battery_info;
35 unsigned char backpack_status;
36
40
41 ResourceFinder rf;
42 PolyDriver driver;
43 ISerialDevice *pSerial;
44 char serial_buff[255];
45 std::string remoteName;
46 std::string localName;
47
48public:
49 BmsBattery(int period = 20) : PeriodicThread((double)period/1000.0)
50 {}
51
52
54 {
55 }
56
57 virtual bool open(yarp::os::Searchable& config);
58 virtual bool close();
59
60 virtual bool getBatteryVoltage (double &voltage);
61 virtual bool getBatteryCurrent (double &current);
62 virtual bool getBatteryCharge (double &charge);
63 virtual bool getBatteryStatus (Battery_status &status);
64 virtual bool getBatteryInfo (std::string &info);
65 virtual bool getBatteryTemperature (double &temperature);
66
67 virtual bool threadInit();
68 virtual void threadRelease();
69 virtual void run();
70
71private:
72 virtual bool verify_checksum(int& raw_battery_current, int& raw_battery_voltage, int& raw_battery_charge, int& raw_battery_checksum);
73};
74
75
76#endif
unsigned short batteryId
Definition bmsBattery.h:26
virtual bool getBatteryVoltage(double &voltage)
virtual bool getBatteryTemperature(double &temperature)
double timeStamp
Definition bmsBattery.h:28
std::string battery_info
Definition bmsBattery.h:34
std::string localName
Definition bmsBattery.h:46
ResourceFinder rf
Definition bmsBattery.h:41
double battery_voltage
Definition bmsBattery.h:31
short status
Definition bmsBattery.h:27
bool verboseEnable
Definition bmsBattery.h:37
yarp::sig::Vector data
Definition bmsBattery.h:29
bool screenEnable
Definition bmsBattery.h:38
virtual bool getBatteryStatus(Battery_status &status)
virtual void threadRelease()
virtual bool close()
char serial_buff[255]
Definition bmsBattery.h:44
virtual bool open(yarp::os::Searchable &config)
std::string remoteName
Definition bmsBattery.h:45
virtual bool getBatteryInfo(std::string &info)
virtual bool threadInit()
double battery_current
Definition bmsBattery.h:32
bool debugEnable
Definition bmsBattery.h:39
virtual bool getBatteryCharge(double &charge)
BmsBattery(int period=20)
Definition bmsBattery.h:49
unsigned char backpack_status
Definition bmsBattery.h:35
std::mutex mtx
Definition bmsBattery.h:24
ISerialDevice * pSerial
Definition bmsBattery.h:43
double battery_temperature
Definition bmsBattery.h:33
PolyDriver driver
Definition bmsBattery.h:42
virtual void run()
double battery_charge
Definition bmsBattery.h:30
virtual bool getBatteryCurrent(double &current)