controller.cpp
Go to the documentation of this file.
1 
20 
22 
23 #include <memory>
24 
25 
27 {
28 
29 
31  InterfaceType* hw,
32  ros::NodeHandle& root_node_handle,
33  ros::NodeHandle& controller_node_handle)
34 {
35  if ((robot_status_interface_ = hw) == nullptr)
36  {
37  ROS_ERROR("IndustrialRobotStatusController: Could not get Industrial "
38  "Robot Status interface from hardware");
39  return false;
40  }
41 
42  publish_rate_ = 10.0;
43  if (!controller_node_handle.getParam("publish_rate", publish_rate_))
44  {
45  ROS_INFO_STREAM("IndustrialRobotStatusController: no 'publish_rate' "
46  "parameter. Using default " << publish_rate_ << " [Hz].");
47  }
48 
49  std::string handle_name = "industrial_robot_status_handle";
50  if (!controller_node_handle.getParam("handle_name", handle_name))
51  {
52  ROS_INFO_STREAM("IndustrialRobotStatusController: no 'handle_name' "
53  "parameter. Using default '" << handle_name << "'.");
54  }
55 
56  try
57  {
58  robot_status_handle_ = std::make_unique<HandleType>(
59  robot_status_interface_->getHandle(handle_name));
60  }
62  {
63  ROS_ERROR_STREAM("IndustrialRobotStatusController: exception getting "
64  "robot status handle: " << ex.what());
65  return false;
66  }
67 
68  // init publisher for robot status
69  robot_status_pub_.init(root_node_handle, "robot_status", 1);
70 
71  return true;
72 }
73 
74 
76 {
77  last_publish_time_ = time;
78 }
79 
80 
81 static industrial_msgs::TriState::_val_type convert(const industrial_robot_status_interface::TriState& tristate)
82 {
84  return industrial_msgs::TriState::TRUE;
86  return industrial_msgs::TriState::FALSE;
88  return industrial_msgs::TriState::UNKNOWN;
89 }
90 
91 
92 static industrial_msgs::RobotMode::_val_type convert(const industrial_robot_status_interface::RobotMode& robot_mode)
93 {
95  return industrial_msgs::RobotMode::MANUAL;
97  return industrial_msgs::RobotMode::AUTO;
99  return industrial_msgs::RobotMode::UNKNOWN;
100 }
101 
102 
104 {
105  // obey configured publication rate
106  if (!(publish_rate_ > 0.0 && last_publish_time_ + ros::Duration(1.0/publish_rate_) < time))
107  return;
108 
110  {
111  // we're actually publishing, so increment time
113 
114  // TODO: should we use stamp from hw RobotStatus instead?
115  robot_status_pub_.msg_.header.stamp = time;
116 
117  // publish msg based on last state from hw interface
118  auto robot_status_hw = robot_status_handle_->getRobotStatus();
119 
120  // simple conversion operation
121  robot_status_pub_.msg_.in_motion.val = convert(robot_status_hw.in_motion);
122  robot_status_pub_.msg_.motion_possible.val = convert(robot_status_hw.motion_possible);
123  robot_status_pub_.msg_.drives_powered.val = convert(robot_status_hw.drives_powered);
124  robot_status_pub_.msg_.e_stopped.val = convert(robot_status_hw.e_stopped);
125  robot_status_pub_.msg_.in_error.val = convert(robot_status_hw.in_error);
126  robot_status_pub_.msg_.mode.val = convert(robot_status_hw.mode);
127  robot_status_pub_.msg_.error_code = robot_status_hw.error_code;
128 
130  }
131 }
132 
133 
134 } // namespace industrial_robot_status_controller
135 
industrial_robot_status_controller::IndustrialRobotStatusController::init
bool init(InterfaceType *hw, ros::NodeHandle &root_node_handle, ros::NodeHandle &controller_node_handle) override
Definition: controller.cpp:30
industrial_robot_status_controller::convert
static industrial_msgs::TriState::_val_type convert(const industrial_robot_status_interface::TriState &tristate)
Definition: controller.cpp:81
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
industrial_robot_status_controller::IndustrialRobotStatusController
Definition: industrial_robot_status_controller.h:39
industrial_robot_status_controller::IndustrialRobotStatusController::update
void update(const ros::Time &time, const ros::Duration &period) override
Definition: controller.cpp:103
hardware_interface::HardwareInterfaceException::what
const char * what() const noexcept override
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
industrial_robot_status_interface::TriState
TriState
industrial_robot_status_interface::TriState::FALSE
@ FALSE
industrial_robot_status_controller
Definition: industrial_robot_status_controller.h:31
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(industrial_robot_status_controller::IndustrialRobotStatusController, controller_interface::ControllerBase)
industrial_robot_status_interface::RobotMode::UNKNOWN
@ UNKNOWN
realtime_tools::RealtimePublisher::init
void init(const ros::NodeHandle &node, const std::string &topic, int queue_size, bool latched=false)
controller_interface::ControllerBase
industrial_robot_status_controller::IndustrialRobotStatusController::last_publish_time_
ros::Time last_publish_time_
Definition: industrial_robot_status_controller.h:59
realtime_tools::RealtimePublisher::unlockAndPublish
void unlockAndPublish()
industrial_robot_status_interface::RobotMode::AUTO
@ AUTO
realtime_tools::RealtimePublisher::msg_
Msg msg_
industrial_robot_status_interface::IndustrialRobotStatusInterface
realtime_tools::RealtimePublisher::trylock
bool trylock()
industrial_robot_status_interface::TriState::UNKNOWN
@ UNKNOWN
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
industrial_robot_status_controller.h
industrial_robot_status_controller::IndustrialRobotStatusController::starting
void starting(const ros::Time &time) override
Definition: controller.cpp:75
hardware_interface::HardwareInterfaceException
ros::Time
ROS_ERROR
#define ROS_ERROR(...)
industrial_robot_status_controller::IndustrialRobotStatusController::robot_status_pub_
realtime_tools::RealtimePublisher< industrial_msgs::RobotStatus > robot_status_pub_
Definition: industrial_robot_status_controller.h:58
class_list_macros.hpp
industrial_robot_status_controller::IndustrialRobotStatusController::robot_status_interface_
InterfaceType * robot_status_interface_
Definition: industrial_robot_status_controller.h:55
industrial_robot_status_controller::IndustrialRobotStatusController::robot_status_handle_
std::unique_ptr< HandleType > robot_status_handle_
Definition: industrial_robot_status_controller.h:56
industrial_robot_status_controller::IndustrialRobotStatusController::publish_rate_
double publish_rate_
Definition: industrial_robot_status_controller.h:60
ros::Duration
industrial_robot_status_interface::RobotMode::MANUAL
@ MANUAL
ros::NodeHandle
industrial_robot_status_interface::TriState::TRUE
@ TRUE
industrial_robot_status_interface::RobotMode
RobotMode


industrial_robot_status_controller
Author(s): G.A. vd. Hoorn (TU Delft Robotics Institute)
autogenerated on Sun Jul 2 2023 02:32:38