From 5621c358e6113bf96889a41c80b13ba3594dafff Mon Sep 17 00:00:00 2001 From: Felix Exner Date: Mon, 11 May 2020 12:13:39 +0200 Subject: [PATCH] Initialize member variables It can happen that the action gets triggered before the mode callback got triggered While this changes stops the helper from crashing when this happens, it might not be the best idea to do so as the question remains, what we should do if we haven't even received a current status from the robot. With the changes introduced inside this commit, the helper would trigger the respective state changes, which might lead to wrong requests if we aren't entirely sure what to do. One solution would be to reject goals as long as no status was received, but that would break such scenarios where you want to activate the robot automatically during startup. Another idea would be to delay actually starting the action server until we received both, robot mode and safety mode. But I am not entirely sure whether this will scale well. --- ur_robot_driver/src/ros/robot_state_helper.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ur_robot_driver/src/ros/robot_state_helper.cpp b/ur_robot_driver/src/ros/robot_state_helper.cpp index 3ff662831..50f9a9257 100644 --- a/ur_robot_driver/src/ros/robot_state_helper.cpp +++ b/ur_robot_driver/src/ros/robot_state_helper.cpp @@ -30,7 +30,11 @@ #include namespace ur_driver { -RobotStateHelper::RobotStateHelper(const ros::NodeHandle& nh) : nh_(nh), set_mode_as_(nh_, "set_mode", false) +RobotStateHelper::RobotStateHelper(const ros::NodeHandle& nh) + : nh_(nh) + , robot_mode_(RobotMode::POWER_OFF) + , safety_mode_(SafetyMode::UNDEFINED_SAFETY_MODE) + , set_mode_as_(nh_, "set_mode", false) { // Topic on which the robot_mode is published by the driver robot_mode_sub_ = nh_.subscribe("robot_mode", 1, &RobotStateHelper::robotModeCallback, this);