From e45fdbb8080a41050dd170d206d49220e79fb5df Mon Sep 17 00:00:00 2001 From: Wiktor Bajor Date: Thu, 19 Dec 2024 11:38:21 +0100 Subject: [PATCH] Add fixes after review --- .../semantic_components/force_torque_sensor.hpp | 14 +++++++------- .../include/semantic_components/imu_sensor.hpp | 14 +++++++------- .../include/semantic_components/pose_sensor.hpp | 10 +++++----- .../include/semantic_components/range_sensor.hpp | 4 ++-- .../semantic_component_interface.hpp | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/controller_interface/include/semantic_components/force_torque_sensor.hpp b/controller_interface/include/semantic_components/force_torque_sensor.hpp index 408577eddb..b35501e2cd 100644 --- a/controller_interface/include/semantic_components/force_torque_sensor.hpp +++ b/controller_interface/include/semantic_components/force_torque_sensor.hpp @@ -88,12 +88,12 @@ class ForceTorqueSensor : public SemanticComponentInterface get_forces() + std::array get_forces() const { std::array forces{ {double_limits::quiet_NaN(), double_limits::quiet_NaN(), double_limits::quiet_NaN()}}; size_t interface_counter{0}; - for (size_t i{0}; i < forces.size(); ++i) + for (auto i = 0u; i < forces.size(); ++i) { if (existing_axes_[i]) { @@ -110,16 +110,16 @@ class ForceTorqueSensor : public SemanticComponentInterface get_torques() + std::array get_torques() const { std::array torques{ {double_limits::quiet_NaN(), double_limits::quiet_NaN(), double_limits::quiet_NaN()}}; // find out how many force interfaces are being used // torque interfaces will be found from the next index onward - auto torque_interface_counter{static_cast( - std::count(existing_axes_.begin(), existing_axes_.begin() + forces_size_, true))}; + auto torque_interface_counter = static_cast( + std::count(existing_axes_.begin(), existing_axes_.begin() + forces_size_, true)); - for (size_t i{0}; i < torques.size(); ++i) + for (auto i = 0u; i < torques.size(); ++i) { if (existing_axes_[i + forces_size_]) { @@ -138,7 +138,7 @@ class ForceTorqueSensor : public SemanticComponentInterface * * \return Array of size 4 with orientation quaternion (x,y,z,w). */ - std::array get_orientation() + std::array get_orientation() const { std::array orientation; - for (std::size_t i{0}; i < orientation.size(); ++i) + for (auto i = 0u; i < orientation.size(); ++i) { orientation[i] = state_interfaces_[i].get().get_value(); } @@ -64,11 +64,11 @@ class IMUSensor : public SemanticComponentInterface * * \return array of size 3 with angular velocity values (x, y, z). */ - std::array get_angular_velocity() + std::array get_angular_velocity() const { std::array angular_velocity; const std::size_t interface_offset{4}; - for (std::size_t i{0}; i < angular_velocity.size(); ++i) + for (auto i = 0u; i < angular_velocity.size(); ++i) { angular_velocity[i] = state_interfaces_[interface_offset + i].get().get_value(); } @@ -81,11 +81,11 @@ class IMUSensor : public SemanticComponentInterface * * \return array of size 3 with linear acceleration values (x, y, z). */ - std::array get_linear_acceleration() + std::array get_linear_acceleration() const { std::array linear_acceleration; const std::size_t interface_offset{7}; - for (std::size_t i{0}; i < linear_acceleration.size(); ++i) + for (auto i = 0u; i < linear_acceleration.size(); ++i) { linear_acceleration[i] = state_interfaces_[interface_offset + i].get().get_value(); } @@ -97,7 +97,7 @@ class IMUSensor : public SemanticComponentInterface * Constructs and return a IMU message from the current values. * \return imu message from values; */ - bool get_values_as_message(sensor_msgs::msg::Imu & message) + bool get_values_as_message(sensor_msgs::msg::Imu & message) const { const auto [orientation_x, orientation_y, orientation_z, orientation_w] = get_orientation(); const auto [angular_velocity_x, angular_velocity_y, angular_velocity_z] = diff --git a/controller_interface/include/semantic_components/pose_sensor.hpp b/controller_interface/include/semantic_components/pose_sensor.hpp index a65d903f30..1e96aae355 100644 --- a/controller_interface/include/semantic_components/pose_sensor.hpp +++ b/controller_interface/include/semantic_components/pose_sensor.hpp @@ -46,10 +46,10 @@ class PoseSensor : public SemanticComponentInterface * * \return Array of position coordinates. */ - std::array get_position() + std::array get_position() const { std::array position; - for (std::size_t i{0}; i < position.size(); ++i) + for (auto i = 0u; i < position.size(); ++i) { position[i] = state_interfaces_[i].get().get_value(); } @@ -62,11 +62,11 @@ class PoseSensor : public SemanticComponentInterface * * \return Array of orientation coordinates in xyzw convention. */ - std::array get_orientation() + std::array get_orientation() const { std::array orientation; const std::size_t interface_offset{3}; - for (std::size_t i{0}; i < orientation.size(); ++i) + for (auto i = 0u; i < orientation.size(); ++i) { orientation[i] = state_interfaces_[interface_offset + i].get().get_value(); } @@ -77,7 +77,7 @@ class PoseSensor : public SemanticComponentInterface /** * Fill a pose message with current position and orientation from the state interfaces. */ - bool get_values_as_message(geometry_msgs::msg::Pose & message) + bool get_values_as_message(geometry_msgs::msg::Pose & message) const { const auto [position_x, position_y, position_z] = get_position(); const auto [orientation_x, orientation_y, orientation_z, orientation_w] = get_orientation(); diff --git a/controller_interface/include/semantic_components/range_sensor.hpp b/controller_interface/include/semantic_components/range_sensor.hpp index 85edae4d1c..64fb4690fd 100644 --- a/controller_interface/include/semantic_components/range_sensor.hpp +++ b/controller_interface/include/semantic_components/range_sensor.hpp @@ -35,14 +35,14 @@ class RangeSensor : public SemanticComponentInterface * * \return value of the range in meters */ - float get_range() { return state_interfaces_[0].get().get_value(); } + float get_range() const { return state_interfaces_[0].get().get_value(); } /// Return Range message with range in meters /** * Constructs and return a Range message from the current values. * \return Range message from values; */ - bool get_values_as_message(sensor_msgs::msg::Range & message) + bool get_values_as_message(sensor_msgs::msg::Range & message) const { message.range = get_range(); return true; diff --git a/controller_interface/include/semantic_components/semantic_component_interface.hpp b/controller_interface/include/semantic_components/semantic_component_interface.hpp index d50e7112ab..48c0604632 100644 --- a/controller_interface/include/semantic_components/semantic_component_interface.hpp +++ b/controller_interface/include/semantic_components/semantic_component_interface.hpp @@ -33,7 +33,7 @@ class SemanticComponentInterface state_interfaces_.reserve(interface_names.size()); } - explicit SemanticComponentInterface(const std::string & name, size_t size = 0) : name_{name} + explicit SemanticComponentInterface(const std::string & name, std::size_t size = 0) : name_{name} { interface_names_.reserve(size); state_interfaces_.reserve(size);