cob_bms_driver_node.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef COB_BMS_DRIVER_NODE_H
19 #define COB_BMS_DRIVER_NODE_H
20 
21 #include <ros/ros.h>
22 #include <XmlRpcValue.h>
25 
28 
30 {
31  unsigned int offset;
32  unsigned int length;
33 
34  bool is_signed;
35 
37 
38  diagnostic_msgs::KeyValue kv;
39 
40  virtual ~BmsParameter() {}
41 
42  virtual void update(const can::Frame &f) = 0;
43  virtual void advertise(ros::NodeHandle &nh, const std::string &topic) = 0;
44 
46 };
47 
49 {
50 private:
53 
54  typedef std::multimap<uint8_t, BmsParameter::Ptr> ConfigMap;
55 
56  //ROS parameters
57  ConfigMap config_map_; //holds all the information that is provided in the configuration file
59  std::string can_device_;
62 
63  boost::mutex data_mutex_;
64 
65  //polling lists that contain CAN-ID(s) that are to be polled. Each CAN-ID corresponds to a group of BMS parameters
66  std::vector<uint8_t> polling_list1_;
67  std::vector<uint8_t> polling_list2_;
68  std::vector<uint8_t>::iterator polling_list1_it_;
69  std::vector<uint8_t>::iterator polling_list2_it_;
70 
71  //interface to send and recieve CAN frames
73 
74  //pointer to callback function to handle CAN frames from BMS
76 
77  //diagnostics data received from BMS
79 
80  //function to get ROS parameters from parameter server
81  bool getParams();
82 
83  //function to interpret the diagnostics XmlRpcValue and save data in config_map_
84  bool loadConfigMap(XmlRpc::XmlRpcValue &diagnostics, std::vector<std::string> &topics);
85 
86  //helper function to evaluate poll period from given poll frequency
87  void evaluatePollPeriodFrom(int poll_frequency);
88 
89  //function that goes through config_map_ and fills polling_list1_ and polling_list2_ with CAN-IDs.
90  //If Topics are found on ROS Parameter Server, they are kept in a separate list (to be polled faster).
91  //Otherwise, all CAN-ID are divided between both lists.
92  void optimizePollingLists();
93 
94  //function that polls BMS (bms_id_to_poll_ is used here!).
95  //Also, this function sleeps for time given by poll_period_for_two_ids_in_ms_ to ensure BMS is polled at the desired frequency
96  void pollBmsForIds(const uint16_t first_id, const uint16_t second_id);
97 
98  //callback function to handle all types of frames received from BMS
99  void handleFrames(const can::Frame &f);
100 
101  //updates the diagnostics data with the new data received from BMS
102  void produceDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat);
103 
104  //calls update function of diagnostics_updater
105  void diagnosticsTimerCallback(const ros::TimerEvent&);
106 public:
107 
108  //updater for diagnostics data
110 
112  ~CobBmsDriverNode();
113 
114  //initlializes SocketCAN interface, saves data from ROS parameter server, loads polling lists and sets up diagnostic updater
115  bool prepare();
116 
117  //cycles through polling lists and sends 2 ids at a time (one from each list) to the BMS
118  void pollNextInLists();
119 };
120 
121 
122 #endif //COB_BMS_DRIVER_NODE_H
ros::Publisher publisher
boost::shared_ptr< BmsParameter > Ptr
f
diagnostic_updater::DiagnosticStatusWrapper stat_
boost::mutex data_mutex_
std::vector< uint8_t > polling_list2_
unsigned int offset
std::vector< uint8_t >::iterator polling_list2_it_
std::vector< uint8_t >::iterator polling_list1_it_
std::vector< uint8_t > polling_list1_
std::multimap< uint8_t, BmsParameter::Ptr > ConfigMap
virtual void update(const can::Frame &f)=0
virtual ~BmsParameter()
ros::NodeHandle nh_
virtual void advertise(ros::NodeHandle &nh, const std::string &topic)=0
can::CommInterface::FrameListenerConstSharedPtr frame_listener_
diagnostic_msgs::KeyValue kv
ros::NodeHandle nh_priv_
can::ThreadedSocketCANInterface socketcan_interface_
unsigned int length
diagnostic_updater::Updater updater_


cob_bms_driver
Author(s): mig-mc , Mathias Lüdtke
autogenerated on Wed Apr 7 2021 02:11:37