Skip to content

Commit 732a3bc

Browse files
committed
Address review comments.
1 parent 635ed68 commit 732a3bc

File tree

5 files changed

+58
-57
lines changed

5 files changed

+58
-57
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ This repository demonstrates the following `ros2_control` concepts:
4646
* Checkout [ros-controls/ros2_control_demos](https://github.com/ros-controls/ros2_control_demos) to get example hardware and robot launch files.
4747

4848
* Install dependencies (maybe you need `sudo`):
49-
```
50-
apt install ros-foxy-realtime-tools ros-foxy-xacro ros-foxy-angles
51-
```
49+
```
50+
apt install ros-foxy-realtime-tools ros-foxy-xacro ros-foxy-angles
51+
```
5252

5353
* Build everything, e.g. with:
5454
```

ros2_control_demo_hardware/include/ros2_control_demo_hardware/rrbot_system_position_only.hpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 ROS2-Control Development Team
1+
// Copyright 2020 ros2_control Development Team
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@
2222

2323
#include "rclcpp/macros.hpp"
2424

25-
#include "hardware_interface/components/base_interface.hpp"
26-
#include "hardware_interface/components/system_interface.hpp"
25+
#include "hardware_interface/base_interface.hpp"
26+
#include "hardware_interface/system_interface.hpp"
2727
#include "hardware_interface/handle.hpp"
2828
#include "hardware_interface/hardware_info.hpp"
2929
#include "hardware_interface/types/hardware_interface_return_values.hpp"
@@ -35,28 +35,38 @@ using hardware_interface::return_type;
3535
namespace ros2_control_demo_hardware
3636
{
3737
class RRBotSystemPositionOnlyHardware : public
38-
hardware_interface::components::BaseInterface<hardware_interface::components::SystemInterface>
38+
hardware_interface::BaseInterface<hardware_interface::SystemInterface>
3939
{
4040
public:
4141
RCLCPP_SHARED_PTR_DEFINITIONS(RRBotSystemPositionOnlyHardware);
4242

43+
ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
4344
return_type configure(const hardware_interface::HardwareInfo & info) override;
4445

46+
ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
4547
std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
4648

49+
ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
4750
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
4851

52+
ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
4953
return_type start() override;
5054

55+
ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
5156
return_type stop() override;
5257

58+
ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
5359
return_type read() override;
5460

61+
ROS2_CONTROL_DEMO_HARDWARE_PUBLIC
5562
return_type write() override;
5663

5764
private:
58-
// Dummy parameters
59-
double hw_start_sec_, hw_stop_sec_, hw_slowdown_;
65+
// Parameters for the RRBot simulation
66+
double hw_start_sec_;
67+
double hw_stop_sec_;
68+
double hw_slowdown_;
69+
6070
// Store the command for the simulated robot
6171
std::vector<double> hw_commands_;
6272
std::vector<double> hw_states_;

ros2_control_demo_hardware/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>ros2_control_demo_hardware</name>
5-
<version>0.0.1</version>
5+
<version>0.0.0</version>
66
<description>Demo package of `ros2_control` Hardware. This package provides example on how to define hardware of your own robot for ROS2 control. The package is used with `demo_robot` from package `ros2_control_demo_robot`.</description>
77

88
<maintainer email="[email protected]">Denis Štogl</maintainer>

ros2_control_demo_hardware/ros2_control_demo_hardware.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<library path="ros2_control_demo_hardware">
22
<class name="ros2_control_demo_hardware/RRBotSystemPositionOnlyHardware"
33
type="ros2_control_demo_hardware::RRBotSystemPositionOnlyHardware"
4-
base_class_type="hardware_interface::components::SystemInterface">
4+
base_class_type="hardware_interface::SystemInterface">
55
<description>
66
The ROS2 Control minimal robot protocol. This is example for start porting the robot from ROS 1.
77
</description>

ros2_control_demo_hardware/src/rrbot_system_position_only.cpp

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 ROS2-Control Development Team
1+
// Copyright 2020 ros2_control Development Team
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -37,53 +37,44 @@ return_type RRBotSystemPositionOnlyHardware::configure(
3737
hw_stop_sec_ = stod(info_.hardware_parameters["example_param_hw_stop_duration_sec"]);
3838
hw_slowdown_ = stod(info_.hardware_parameters["example_param_hw_slowdown"]);
3939
hw_states_.resize(info_.joints.size(), std::numeric_limits<double>::quiet_NaN());
40-
hw_commands_.resize(info_.joints.size());
41-
for (uint i = 0; i < info_.joints.size(); i++) {
42-
hw_states_[i] = std::numeric_limits<double>::quiet_NaN();
43-
hw_commands_[i] = std::numeric_limits<double>::quiet_NaN();
44-
}
40+
hw_commands_.resize(info_.joints.size(), std::numeric_limits<double>::quiet_NaN());
41+
42+
for (const hardware_interface::ComponentInfo & joint : info_.joints) {
43+
// RRBotSystemPositionOnly has exactly one state and command interface on each joint
44+
if (joint.command_interfaces.size() != 1) {
45+
RCLCPP_FATAL(
46+
rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),
47+
"Joint '%s' has %d command interfaces found. 1 expected.",
48+
joint.name.c_str(), joint.command_interfaces.size());
49+
return return_type::ERROR;
50+
}
4551

46-
// TODO(anyone): we should provide helpers for this checking somewhere
47-
{
48-
for (const hardware_interface::ComponentInfo & joint : info_.joints) {
49-
// RRBotSystemPositionOnly has exactly one state and command interface on each joint
50-
if (joint.command_interfaces.size() != 1) {
51-
RCLCPP_FATAL(
52-
rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),
53-
"Joint '%s' has %d command interfaces found. 1 expected.",
54-
joint.name.c_str(), joint.command_interfaces.size());
55-
return return_type::ERROR;
56-
}
57-
58-
if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION) {
59-
RCLCPP_FATAL(
60-
rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),
61-
"Joint '%s' have %s command interfaces found. '%s' expected.",
62-
joint.name.c_str(), joint.command_interfaces[0].name.c_str(),
63-
hardware_interface::HW_IF_POSITION);
64-
return return_type::ERROR;
65-
}
66-
67-
if (joint.state_interfaces.size() != 1) {
68-
RCLCPP_FATAL(
69-
rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),
70-
"Joint '%s' has %d state interface. 1 expected.",
71-
joint.name.c_str(), joint.state_interfaces.size());
72-
return return_type::ERROR;
73-
}
74-
75-
if (joint.state_interfaces[0].name != hardware_interface::HW_IF_POSITION) {
76-
RCLCPP_FATAL(
77-
rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),
78-
"Joint '%s' have %s state interface. '%s' expected.",
79-
joint.name.c_str(), joint.state_interfaces[0].name.c_str(),
80-
hardware_interface::HW_IF_POSITION);
81-
return return_type::ERROR;
82-
}
52+
if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION) {
53+
RCLCPP_FATAL(
54+
rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),
55+
"Joint '%s' have %s command interfaces found. '%s' expected.",
56+
joint.name.c_str(), joint.command_interfaces[0].name.c_str(),
57+
hardware_interface::HW_IF_POSITION);
58+
return return_type::ERROR;
8359
}
84-
}
8560

86-
// TODO(all): ada support for different order of joints than "joint1", "joint2",...
61+
if (joint.state_interfaces.size() != 1) {
62+
RCLCPP_FATAL(
63+
rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),
64+
"Joint '%s' has %d state interface. 1 expected.",
65+
joint.name.c_str(), joint.state_interfaces.size());
66+
return return_type::ERROR;
67+
}
68+
69+
if (joint.state_interfaces[0].name != hardware_interface::HW_IF_POSITION) {
70+
RCLCPP_FATAL(
71+
rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),
72+
"Joint '%s' have %s state interface. '%s' expected.",
73+
joint.name.c_str(), joint.state_interfaces[0].name.c_str(),
74+
hardware_interface::HW_IF_POSITION);
75+
return return_type::ERROR;
76+
}
77+
}
8778

8879
status_ = hardware_interface::status::CONFIGURED;
8980
return return_type::OK;
@@ -213,5 +204,5 @@ hardware_interface::return_type ros2_control_demo_hardware::RRBotSystemPositionO
213204

214205
PLUGINLIB_EXPORT_CLASS(
215206
ros2_control_demo_hardware::RRBotSystemPositionOnlyHardware,
216-
hardware_interface::components::SystemInterface
207+
hardware_interface::SystemInterface
217208
)

0 commit comments

Comments
 (0)