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
103 
104  //calls update function of diagnostics_updater
106 public:
107 
108  //updater for diagnostics data
110 
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
can::CommInterface::FrameListenerConstSharedPtr
FrameListener::ListenerConstSharedPtr FrameListenerConstSharedPtr
ros::Publisher
can::Frame
BmsParameter::is_signed
bool is_signed
Definition: cob_bms_driver_node.h:34
CobBmsDriverNode::frame_listener_
can::CommInterface::FrameListenerConstSharedPtr frame_listener_
Definition: cob_bms_driver_node.h:75
boost::shared_ptr
BmsParameter::Ptr
boost::shared_ptr< BmsParameter > Ptr
Definition: cob_bms_driver_node.h:45
BmsParameter::~BmsParameter
virtual ~BmsParameter()
Definition: cob_bms_driver_node.h:40
threading.h
CobBmsDriverNode::produceDiagnostics
void produceDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat)
Definition: cob_bms_driver_node.cpp:415
CobBmsDriverNode::nh_priv_
ros::NodeHandle nh_priv_
Definition: cob_bms_driver_node.h:52
ros.h
CobBmsDriverNode::getParams
bool getParams()
Definition: cob_bms_driver_node.cpp:172
CobBmsDriverNode::socketcan_interface_
can::ThreadedSocketCANInterface socketcan_interface_
Definition: cob_bms_driver_node.h:72
diagnostic_updater::Updater
CobBmsDriverNode::handleFrames
void handleFrames(const can::Frame &f)
Definition: cob_bms_driver_node.cpp:401
CobBmsDriverNode::can_device_
std::string can_device_
Definition: cob_bms_driver_node.h:59
socketcan.h
BmsParameter::offset
unsigned int offset
Definition: cob_bms_driver_node.h:31
publisher.h
diagnostic_updater.h
BmsParameter
Definition: cob_bms_driver_node.h:29
CobBmsDriverNode::loadConfigMap
bool loadConfigMap(XmlRpc::XmlRpcValue &diagnostics, std::vector< std::string > &topics)
Definition: cob_bms_driver_node.cpp:231
CobBmsDriverNode::bms_id_to_poll_
int bms_id_to_poll_
Definition: cob_bms_driver_node.h:60
CobBmsDriverNode::updater_timer_
ros::Timer updater_timer_
Definition: cob_bms_driver_node.h:61
CobBmsDriverNode::~CobBmsDriverNode
~CobBmsDriverNode()
Definition: cob_bms_driver_node.cpp:133
CobBmsDriverNode::updater_
diagnostic_updater::Updater updater_
Definition: cob_bms_driver_node.h:109
CobBmsDriverNode::pollNextInLists
void pollNextInLists()
Definition: cob_bms_driver_node.cpp:380
can::ThreadedInterface
CobBmsDriverNode::poll_period_for_two_ids_in_ms_
int poll_period_for_two_ids_in_ms_
Definition: cob_bms_driver_node.h:58
BmsParameter::advertise
virtual void advertise(ros::NodeHandle &nh, const std::string &topic)=0
XmlRpcValue.h
ros::TimerEvent
CobBmsDriverNode::stat_
diagnostic_updater::DiagnosticStatusWrapper stat_
Definition: cob_bms_driver_node.h:78
CobBmsDriverNode::diagnosticsTimerCallback
void diagnosticsTimerCallback(const ros::TimerEvent &)
Definition: cob_bms_driver_node.cpp:447
CobBmsDriverNode::polling_list2_
std::vector< uint8_t > polling_list2_
Definition: cob_bms_driver_node.h:67
CobBmsDriverNode::CobBmsDriverNode
CobBmsDriverNode()
Definition: cob_bms_driver_node.cpp:129
CobBmsDriverNode::polling_list1_it_
std::vector< uint8_t >::iterator polling_list1_it_
Definition: cob_bms_driver_node.h:68
CobBmsDriverNode::data_mutex_
boost::mutex data_mutex_
Definition: cob_bms_driver_node.h:63
BmsParameter::length
unsigned int length
Definition: cob_bms_driver_node.h:32
CobBmsDriverNode::prepare
bool prepare()
Definition: cob_bms_driver_node.cpp:139
BmsParameter::kv
diagnostic_msgs::KeyValue kv
Definition: cob_bms_driver_node.h:38
CobBmsDriverNode::polling_list2_it_
std::vector< uint8_t >::iterator polling_list2_it_
Definition: cob_bms_driver_node.h:69
diagnostic_updater::DiagnosticStatusWrapper
CobBmsDriverNode::polling_list1_
std::vector< uint8_t > polling_list1_
Definition: cob_bms_driver_node.h:66
BmsParameter::update
virtual void update(const can::Frame &f)=0
CobBmsDriverNode::ConfigMap
std::multimap< uint8_t, BmsParameter::Ptr > ConfigMap
Definition: cob_bms_driver_node.h:54
CobBmsDriverNode
Definition: cob_bms_driver_node.h:48
CobBmsDriverNode::optimizePollingLists
void optimizePollingLists()
Definition: cob_bms_driver_node.cpp:349
CobBmsDriverNode::evaluatePollPeriodFrom
void evaluatePollPeriodFrom(int poll_frequency)
Definition: cob_bms_driver_node.cpp:335
CobBmsDriverNode::pollBmsForIds
void pollBmsForIds(const uint16_t first_id, const uint16_t second_id)
Definition: cob_bms_driver_node.cpp:366
CobBmsDriverNode::nh_
ros::NodeHandle nh_
Definition: cob_bms_driver_node.h:51
ros::Timer
XmlRpc::XmlRpcValue
CobBmsDriverNode::config_map_
ConfigMap config_map_
Definition: cob_bms_driver_node.h:57
ros::NodeHandle
BmsParameter::publisher
ros::Publisher publisher
Definition: cob_bms_driver_node.h:36


cob_bms_driver
Author(s): mig-mc , Mathias Lüdtke
autogenerated on Wed Nov 8 2023 03:47:34