11 #include <std_srvs/Trigger.h> 15 #include <franka_msgs/ErrorRecoveryAction.h> 22 bool success = CombinedRobotHW::init(root_nh, robot_hw_nh);
25 std::make_unique<actionlib::SimpleActionServer<franka_msgs::ErrorRecoveryAction>>(
26 robot_hw_nh,
"error_recovery",
27 [&](
const franka_msgs::ErrorRecoveryGoalConstPtr&) {
31 auto* franka_combinable_hw_ptr =
33 if (franka_combinable_hw_ptr !=
nullptr && franka_combinable_hw_ptr->connected()) {
36 ROS_ERROR(
"FrankaCombinedHW: failed to reset error. Is the robot connected?");
39 franka_msgs::ErrorRecoveryResult(),
40 "dynamic_cast from RobotHW to FrankaCombinableHW failed");
56 robot_hw_nh.advertiseService<std_srvs::Trigger::Request, std_srvs::Trigger::Response>(
58 [
this](std_srvs::Trigger::Request& request,
59 std_srvs::Trigger::Response&
response) ->
bool {
62 ROS_INFO(
"FrankaCombinedHW: successfully connected robots.");
65 }
catch (
const std::exception& e) {
66 ROS_INFO(
"Combined: exception %s", e.what());
69 "FrankaCombinedHW: Failed to connect robot: " + std::string(e.what());
75 robot_hw_nh.advertiseService<std_srvs::Trigger::Request, std_srvs::Trigger::Response>(
77 [
this](std_srvs::Trigger::Request& request,
78 std_srvs::Trigger::Response&
response) ->
bool {
80 response.success = success ? 1u : 0u;
82 ?
"FrankaCombinedHW: Successfully disconnected robots." 83 :
"FrankaCombinedHW: Failed to disconnect robots. All active " 84 "controllers must be stopped before you can disconnect.";
98 CombinedRobotHW::read(time, period);
104 bool controller_reset =
false;
107 if (franka_combinable_hw_ptr !=
nullptr) {
110 ROS_ERROR(
"FrankaCombinedHW: dynamic_cast from RobotHW to FrankaCombinableHW failed.");
114 return controller_reset;
125 bool has_error =
false;
128 if (franka_combinable_hw_ptr !=
nullptr) {
129 has_error = has_error || franka_combinable_hw_ptr->
hasError();
131 ROS_ERROR(
"FrankaCombinedHW: dynamic_cast from RobotHW to FrankaCombinableHW failed.");
142 if (franka_combinable_hw_ptr !=
nullptr) {
145 ROS_ERROR(
"FrankaCombinedHW: dynamic_cast from RobotHW to FrankaCombinableHW failed.");
153 if (franka_combinable_hw_ptr !=
nullptr && !franka_combinable_hw_ptr->connected()) {
154 franka_combinable_hw_ptr->
connect();
163 if (franka_combinable_hw_ptr !=
nullptr && franka_combinable_hw_ptr->controllerActive()) {
170 for (
const auto& robot_hw : robot_hw_list_) {
172 if (franka_combinable_hw_ptr !=
nullptr && !franka_combinable_hw_ptr->disconnect()) {
std::vector< hardware_interface::RobotHWSharedPtr > robot_hw_list_
ros::ServiceServer disconnect_server_
bool hasError()
Checks whether the robots are in error or reflex mode.
void triggerError()
Triggers a stop of the controlLoop.
bool controllerNeedsReset()
Checks whether the controller needs to be reset.
A hardware class for a Panda robot based on the ros_control framework.
ros::ServiceServer connect_server_
bool hasError() const noexcept
Getter for the error flag of the class.
bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh) override
The init function is called to initialize the CombinedFrankaHW from a non-realtime thread...
void resetError()
Recovers the libfranka robot, resets the error flag and publishes the error state.
void connect()
Calls connect on all hardware classes that are of type FrankaCombinableHW.
FrankaCombinedHW()
Creates an instance of CombinedFrankaHW.
std::unique_ptr< actionlib::SimpleActionServer< franka_msgs::ErrorRecoveryAction > > combined_recovery_action_server_
void connect() override
Create a libfranka robot, connecting the hardware class to the master controller. ...
bool disconnect()
Tries to disconnect on all hardware classes that are of type FrankaCombinableHW.
bool controllerNeedsReset() const noexcept
Returns whether the controller needs to be reset e.g.
void read(const ros::Time &time, const ros::Duration &period) override
Reads data from the robot HW.
const std::string response