tof_sensor_controller.cpp
Go to the documentation of this file.
1 //
2 // Created by luotinkai on 2022/1/2.
3 //
4 
7 
8 namespace tof_sensor_controller
9 {
11 {
12  const std::vector<std::string>& tof_sensor_names = hw->getNames();
13  for (unsigned i = 0; i < tof_sensor_names.size(); i++)
14  ROS_DEBUG("Got sensor %s", tof_sensor_names[i].c_str());
15 
16  for (unsigned i = 0; i < tof_sensor_names.size(); i++)
17  {
18  // sensor handle
19  tof_sensors_.push_back(hw->getHandle(tof_sensor_names[i]));
20 
21  // realtime publisher
22  tof_pub_.reset(
23  new realtime_tools::RealtimePublisher<rm_msgs::TofSensor>(controller_nh, tof_sensor_names[i] + "/data", 100));
24  realtime_pubs_.push_back(tof_pub_);
25  }
26  return true;
27 }
28 
29 void Controller::update(const ros::Time& time, const ros::Duration& period)
30 {
31  for (unsigned int i = 0; i < realtime_pubs_.size(); ++i)
32  {
33  if (realtime_pubs_[i]->trylock())
34  {
35  realtime_pubs_[i]->msg_.distance = tof_sensors_[i].getDistance();
36  realtime_pubs_[i]->msg_.signal_strength = tof_sensors_[i].getStrength();
37  realtime_pubs_[i]->msg_.dis_status = tof_sensors_[i].getStatus();
38  realtime_pubs_[i]->msg_.stamp = time;
39  realtime_pubs_[i]->unlockAndPublish();
40  }
41  }
42 }
43 
44 } // namespace tof_sensor_controller
45 
tof_sensor_controller::Controller::tof_pub_
RtpublisherPtr tof_pub_
Definition: tof_sensor_controller.h:28
tof_sensor_controller::Controller::tof_sensors_
std::vector< rm_control::TofSensorHandle > tof_sensors_
Definition: tof_sensor_controller.h:26
tof_sensor_controller
Definition: tof_sensor_controller.h:13
realtime_tools::RealtimePublisher
controller_interface::ControllerBase
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
ROS_DEBUG
#define ROS_DEBUG(...)
tof_sensor_controller::Controller::init
bool init(rm_control::TofSensorInterface *hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh) override
Definition: tof_sensor_controller.cpp:10
tof_sensor_controller::Controller::update
void update(const ros::Time &time, const ros::Duration &period) override
Definition: tof_sensor_controller.cpp:29
tof_sensor_controller.h
rm_control::TofSensorInterface
tof_sensor_controller::Controller
Definition: tof_sensor_controller.h:15
ros::Time
class_list_macros.hpp
tof_sensor_controller::Controller::realtime_pubs_
std::vector< RtpublisherPtr > realtime_pubs_
Definition: tof_sensor_controller.h:29
ros::Duration
ros::NodeHandle


tof_sensor_controller
Author(s):
autogenerated on Fri Jun 10 2022 02:55:54