Skip to content

Commit

Permalink
Update control error log (#24)
Browse files Browse the repository at this point in the history
* Use RCLCPP_ERROR instead of throwing runtime error

* Add emulate_tty option to show colorized error logs
  • Loading branch information
Shota Aoki authored Nov 10, 2020
1 parent a73b352 commit 8e9c9dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions crane_plus_control/launch/crane_plus_control.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def generate_launch_description():
package='crane_plus_control',
executable='crane_plus_control_node',
output='screen',
emulate_tty=True, # This results error logs are colorized in a terminal.
parameters=[{'controller_name': 'crane_plus_arm_controller'},
os.path.join(get_package_share_directory('crane_plus_control'),
'config', 'crane_plus_controllers.yaml'),
Expand Down
12 changes: 8 additions & 4 deletions crane_plus_control/src/crane_plus_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ hardware_interface::return_type CranePlusInterface::init(
driver_ = std::make_shared<CranePlusDriver>(port_name, baudrate, dxl_id_list);

if (!driver_->open_port()) {
throw std::runtime_error(driver_->get_last_error_log());
RCLCPP_ERROR(LOGGER, driver_->get_last_error_log());
return hardware_interface::return_type::ERROR;
}

for (auto joint_name : joint_name_list) {
Expand All @@ -68,22 +69,25 @@ hardware_interface::return_type CranePlusInterface::init(
if (register_joint_state_handle(&joint_state_handles_[i]) !=
hardware_interface::return_type::OK)
{
throw std::runtime_error("unable to register " + joint_state_handles_[i].get_name());
RCLCPP_ERROR(LOGGER, "Unable to register %s.", joint_state_handles_[i].get_name());
return hardware_interface::return_type::ERROR;
}

hardware_interface::JointCommandHandle command_handle(joint_name, &cmd_[i]);
joint_command_handles_[i] = command_handle;
if (register_joint_command_handle(&joint_command_handles_[i]) !=
hardware_interface::return_type::OK)
{
throw std::runtime_error("unable to register " + joint_command_handles_[i].get_name());
RCLCPP_ERROR(LOGGER, "Unable to register %s.", joint_command_handles_[i].get_name());
return hardware_interface::return_type::ERROR;
}

joint_mode_handles_[i] = hardware_interface::OperationModeHandle(joint_name, &op_mode_[i]);
if (register_operation_mode_handle(&joint_mode_handles_[i]) !=
hardware_interface::return_type::OK)
{
throw std::runtime_error("unable to register " + joint_mode_handles_[i].get_name());
RCLCPP_ERROR(LOGGER, "Unable to register %s.", joint_mode_handles_[i].get_name());
return hardware_interface::return_type::ERROR;
}
++i;
}
Expand Down

0 comments on commit 8e9c9dc

Please sign in to comment.