20 m_battery_interface =
nullptr;
28 driver->
view(m_battery_interface);
33 if (m_battery_interface ==
nullptr)
39 return PeriodicThread::start();
45 if (PeriodicThread::isRunning())
47 PeriodicThread::stop();
49 m_battery_interface =
nullptr;
61 rclcpp::NodeOptions node_options;
62 node_options.allow_undeclared_parameters(
true);
63 node_options.automatically_declare_parameters_from_overrides(
true);
65 if (m_node ==
nullptr) {
70 m_ros2Publisher = m_node->create_publisher<sensor_msgs::msg::BatteryState>(
m_topic_name, 10);
80 if (m_battery_interface==
nullptr)
84 else if (!m_ros2Publisher)
95 std::string battery_info;
105 battMsg.voltage = voltage;
106 battMsg.current = current;
107 battMsg.temperature = temperature;
108 battMsg.charge = std::numeric_limits<double>::quiet_NaN();
111 battMsg.percentage = charge;
112 battMsg.power_supply_status = 0;
113 battMsg.power_supply_health = 0;
114 battMsg.power_supply_technology = 0;
115 battMsg.present=
true;
117 battMsg.serial_number=
"";
119 battMsg.header.frame_id =
"" ;
120 battMsg.header.stamp.sec = int(m_timeStamp.
getTime());
121 battMsg.header.stamp.nanosec = int(1000000000UL * (m_timeStamp.
getTime() -
int(m_timeStamp.
getTime())));
123 m_ros2Publisher->publish(battMsg);
130 if (PeriodicThread::isRunning())
132 PeriodicThread::stop();
const yarp::os::LogComponent & BATTERY_NWS_ROS2()
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
Battery_nws_ros2: A ros2 nws to get the status of a battery and publish it on a ros2 topic....
bool close() override
Close the DeviceDriver.
void run() override
Loop function.
bool detach() override
Detach the object (you must have first called attach).
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
void threadRelease() override
Release method.
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
bool threadInit() override
Initialization method.
static rclcpp::Node::SharedPtr createNode(std::string name)
bool view(T *&x)
Get an interface to the device driver.
virtual bool getBatteryCurrent(double ¤t)=0
Get the instantaneous current measurement.
virtual bool getBatteryVoltage(double &voltage)=0
Get the instantaneous voltage measurement.
virtual bool getBatteryInfo(std::string &battery_info)=0
get the battery hardware characteristics (e.g.
virtual bool getBatteryStatus(Battery_status &status)=0
get the battery status
virtual bool getBatteryCharge(double &charge)=0
get the battery status of charge
virtual bool getBatteryTemperature(double &temperature)=0
get the battery temperature
A container for a device driver.
bool isValid() const
Check if device is valid.
A base class for nested structures that can be searched.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
double getTime() const
Get the time stamp.
#define yCError(component,...)
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
The main, catch-all namespace for YARP.