battery_pub.cpp
Go to the documentation of this file.
1 //
2 // Created by sub on 31/10/17.
3 //
4 
5 #include "battery_pub.h"
6 
7 namespace armadillo2_hw
8 {
10  {
11  /* get batt params */
12  ros::param::get("~load_battery_hw", load_battery_hw_);
13 
14  if (!load_battery_hw_)
15  {
16  ROS_WARN("[armadillo2_hw/battery_pub]: battery hardware is disabled");
17  return;
18  }
19 
21  {
22  ROS_ERROR("[armadillo2_hw/battery_pub]: %s param is missing on param server. make sure that this param exist in battery_config.yaml "
23  "and that your launch includes this param file. shutting down...", BATT_PORT_PARAM);
24  ros::shutdown();
25  exit (EXIT_FAILURE);
26  }
27  ros::param::get("~low_batt_val", low_batt_val_);
28  ros::param::get("~show_warnings", show_warnings_);
29 
30  /* connect to batt FTDI */
31  try
32  {
34  }
35  catch (bms::BMSException exp)
36  {
37  ROS_ERROR("[armadillo2_hw/battery_pub]: %s", exp.what());
38  ros::shutdown();
39  exit(EXIT_FAILURE);
40  }
41  ROS_INFO("[armadillo2_hw/battery_pub]: battery port opened successfully \nport name: %s \nbaudrate: 9600", batt_port_.c_str());
42 
43  /* batt publisher */
44  bat_pub_ = nh.advertise<sensor_msgs::BatteryState>("battery", 10);
48  ROS_INFO("[armadillo2_hw/battery_pub]: battery publisher is up");
49  espeak_pub_ = nh.advertise<std_msgs::String>("/espeak_node/speak_line", 10);
50  /*speakMsg("battery management system is up",1);*/
51  }
52 
54  {
55  speakMsg("low battery", 0);
56  }
57 
59  {
60  try
61  {
62  bms::data bms_data = bms_.read();
63 
64  sensor_msgs::BatteryState msg;
65  msg.header.stamp = ros::Time::now();
66  msg.present = true;
67  msg.voltage = bms_data.vbat;
68  msg.percentage = bms_data.soc;
69  msg.current = bms_data.chrg_current - bms_data.dchrg_current;
70  msg.charge = bms_data.chrg_current;
71  msg.capacity = bms_data.cap_full; //Ah
72  msg.power_supply_status = bms_data.is_chrg;
73  msg.cell_voltage = bms_data.vcells;
74  msg.location = "base_link";
75 
76  /* if battery low and not in charging print warning */
77  if ((low_batt_val_ >=0 && msg.percentage <= low_batt_val_) && !bms_data.is_chrg)
78  {
79  ROS_WARN("[armadillo2_hw/battery_pub]: LOW BATTERY, please connect Armadillo2 to charger");
81  }
82  else
84 
85  bat_pub_.publish(msg);
86  }
87  catch(bms::BMSErrorException exp)
88  {
89  ROS_ERROR("[armadillo2_hw/battery_pub]: %s", exp.what());
90  ros::shutdown();
91  exit(EXIT_FAILURE);
92  }
93  catch(bms::BMSWarnException exp)
94  {
95  if (show_warnings_)
96  ROS_WARN("[armadillo2_hw/battery_pub]: %s", exp.what());
97  }
98  }
99 }
msg
uint8_t is_chrg
void publish(const boost::shared_ptr< M > &message) const
ros::Timer speak_low_batt_timer_
Definition: battery_pub.h:25
void stop()
#define BATT_PUB_INTERVAL
Definition: battery_pub.h:14
void start()
ros::Publisher espeak_pub_
Definition: battery_pub.h:33
#define ROS_WARN(...)
float chrg_current
bms::BMSInterface bms_
Definition: battery_pub.h:26
std::vector< float > vcells
float vbat
ROSCPP_DECL bool get(const std::string &key, std::string &s)
#define ROS_INFO(...)
#define BATT_PORT_PARAM
Definition: battery_pub.h:16
BatteryPub(ros::NodeHandle nh)
Definition: battery_pub.cpp:9
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
uint8_t soc
uint16_t cap_full
void connect(std::string port)
void speakLowTimerCB(const ros::TimerEvent &event)
Definition: battery_pub.cpp:53
ros::Publisher bat_pub_
Definition: battery_pub.h:23
void speakMsg(std::string msg, int sleep_time)
Definition: battery_pub.h:39
static Time now()
ROSCPP_DECL void shutdown()
float dchrg_current
#define ROS_ERROR(...)
#define SPEAK_LOW_BAT_INTERVAL
Definition: battery_pub.h:15
void pubBatTimerCB(const ros::TimerEvent &event)
Definition: battery_pub.cpp:58


armadillo2_hw
Author(s):
autogenerated on Wed Jan 3 2018 03:48:27