1
0
mirror of https://gitlab.com/obbart/universal_robots_ros_driver.git synced 2026-04-10 18:10:47 +02:00

explicitly throw special exception when tool_comm is not available

This way, we can catch it and give a better feedback to the user.
This commit is contained in:
Felix Mauch
2019-06-12 09:06:34 +02:00
parent 520cd4d860
commit 5f405b3996
4 changed files with 36 additions and 17 deletions

View File

@@ -69,5 +69,17 @@ private:
uint32_t version_actual_; uint32_t version_actual_;
std::string text_; std::string text_;
}; };
class ToolCommNotAvailable : public VersionMismatch
{
public:
explicit ToolCommNotAvailable() : ToolCommNotAvailable("", 0, 0)
{
}
explicit ToolCommNotAvailable(const std::string& text, const uint32_t version_req, const uint32_t version_actual)
: std::runtime_error(text), VersionMismatch(text, version_req, version_actual)
{
}
};
} // namespace ur_driver } // namespace ur_driver
#endif // ifndef UR_RTDE_DRIVER_EXCEPTIONS_H_INCLUDED #endif // ifndef UR_RTDE_DRIVER_EXCEPTIONS_H_INCLUDED

View File

@@ -27,6 +27,7 @@
#include "ur_rtde_driver/ros/hardware_interface.h" #include "ur_rtde_driver/ros/hardware_interface.h"
#include "ur_rtde_driver/ur/tool_communication.h" #include "ur_rtde_driver/ur/tool_communication.h"
#include <ur_rtde_driver/exceptions.h>
#include <Eigen/Geometry> #include <Eigen/Geometry>
@@ -125,9 +126,22 @@ bool HardwareInterface ::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_h
} }
ROS_INFO_STREAM("Initializing urdriver"); ROS_INFO_STREAM("Initializing urdriver");
try
{
ur_driver_.reset(new UrDriver(robot_ip, script_filename, recipe_filename, ur_driver_.reset(new UrDriver(robot_ip, script_filename, recipe_filename,
std::bind(&HardwareInterface::handleRobotProgramState, this, std::placeholders::_1), std::bind(&HardwareInterface::handleRobotProgramState, this, std::placeholders::_1),
std::move(tool_comm_setup))); std::move(tool_comm_setup)));
}
catch (ur_driver::ToolCommNotAvailable& e)
{
ROS_FATAL_STREAM(e.what() << " See parameter '" << robot_hw_nh.resolveName("use_tool_communication") << "'.");
return false;
}
catch (ur_driver::UrException& e)
{
ROS_FATAL_STREAM(e.what());
return false;
}
if (!root_nh.getParam("hardware_interface/joints", joint_names_)) if (!root_nh.getParam("hardware_interface/joints", joint_names_))
{ {

View File

@@ -29,7 +29,6 @@
#include <csignal> #include <csignal>
#include <ur_rtde_driver/ros/hardware_interface.h> #include <ur_rtde_driver/ros/hardware_interface.h>
#include <ur_rtde_driver/exceptions.h>
std::unique_ptr<ur_driver::HardwareInterface> g_hw_interface; std::unique_ptr<ur_driver::HardwareInterface> g_hw_interface;
@@ -65,19 +64,11 @@ int main(int argc, char** argv)
g_hw_interface.reset(new ur_driver::HardwareInterface); g_hw_interface.reset(new ur_driver::HardwareInterface);
try
{
if (!g_hw_interface->init(nh, nh_priv)) if (!g_hw_interface->init(nh, nh_priv))
{ {
ROS_ERROR_STREAM("Could not correctly initialize robot. Exiting"); ROS_ERROR_STREAM("Could not correctly initialize robot. Exiting");
exit(1); exit(1);
} }
}
catch (ur_driver::UrException& e)
{
ROS_FATAL_STREAM("Could not correctly initialize robot: " << e.what());
exit(1);
}
ROS_INFO_STREAM("initialized hw interface"); ROS_INFO_STREAM("initialized hw interface");
controller_manager::ControllerManager cm(g_hw_interface.get(), nh); controller_manager::ControllerManager cm(g_hw_interface.get(), nh);
ROS_INFO_STREAM("started controller manager"); ROS_INFO_STREAM("started controller manager");
@@ -152,7 +143,8 @@ int main(int argc, char** argv)
period.fromSec(std::chrono::duration_cast<std::chrono::duration<double>>(stopwatch_now - stopwatch_last).count()); period.fromSec(std::chrono::duration_cast<std::chrono::duration<double>>(stopwatch_now - stopwatch_last).count());
stopwatch_last = stopwatch_now; stopwatch_last = stopwatch_now;
cm.update(timestamp, period, !g_hw_interface->isRobotProgramRunning()); // cm.update(timestamp, period, !g_hw_interface->isRobotProgramRunning());
cm.update(timestamp, period);
g_hw_interface->write(timestamp, period); g_hw_interface->write(timestamp, period);
// if (!control_rate.sleep()) // if (!control_rate.sleep())

View File

@@ -89,8 +89,9 @@ ur_driver::UrDriver::UrDriver(const std::string& robot_ip, const std::string& sc
{ {
if (urcontrol_version.major < 5) if (urcontrol_version.major < 5)
{ {
throw VersionMismatch("This robot version does not support using the tool communication interface.", 5, throw ToolCommNotAvailable("Tool communication setup requested, but this robot version does not support using "
urcontrol_version.major); "the tool communication interface. Please check your configuration.",
5, urcontrol_version.major);
} }
begin_replace << "set_tool_voltage(" begin_replace << "set_tool_voltage("
<< static_cast<std::underlying_type<ToolVoltage>::type>(tool_comm_setup->getToolVoltage()) << ")\n"; << static_cast<std::underlying_type<ToolVoltage>::type>(tool_comm_setup->getToolVoltage()) << ")\n";