11/* *
22 * @file cartesian_pose_sensor.hpp
33 * @brief Sensor interface to read the Cartesian pose. Adapted from
4- * ros2_control/semantic_components /include/semantic_components/force_torque_sensor.hpp
4+ * ros2_control/controller_interface /include/semantic_components/force_torque_sensor.hpp
55 * @copyright Copyright (C) 2016-2021 Flexiv Ltd. All Rights Reserved.
66 * @author Flexiv
77 */
1919
2020namespace flexiv_controllers {
2121class CartesianPoseSensor
22- : public semantic_components::SemanticComponentInterface<
23- geometry_msgs::msg::Pose>
22+ : public semantic_components::SemanticComponentInterface<geometry_msgs::msg::Pose>
2423{
2524public:
2625 CartesianPoseSensor (const std::string& name)
@@ -38,23 +37,21 @@ class CartesianPoseSensor
3837 std::fill (existing_axes_.begin (), existing_axes_.end (), true );
3938
4039 // Set default position and orientation values to NaN
41- std::fill (positions_.begin (), positions_.end (),
42- std::numeric_limits<double >::quiet_NaN ());
43- std::fill (orientations_.begin (), orientations_.end (),
44- std::numeric_limits<double >::quiet_NaN ());
40+ std::fill (positions_.begin (), positions_.end (), std::numeric_limits<double >::quiet_NaN ());
41+ std::fill (
42+ orientations_.begin (), orientations_.end (), std::numeric_limits<double >::quiet_NaN ());
4543 }
4644
4745 virtual ~CartesianPoseSensor () = default ;
4846
4947 // / Return positions
5048 std::array<double , 3 >& get_positions ()
5149 {
52- size_t interface_counter = 0 ;
50+ size_t position_interface_counter = 0 ;
5351 for (size_t i = 0 ; i < 3 ; ++i) {
5452 if (existing_axes_[i]) {
55- positions_[i]
56- = state_interfaces_[interface_counter].get ().get_value ();
57- ++interface_counter;
53+ positions_[i] = state_interfaces_[position_interface_counter].get ().get_value ();
54+ ++position_interface_counter;
5855 }
5956 }
6057 return positions_;
@@ -63,12 +60,13 @@ class CartesianPoseSensor
6360 // / Return orientations
6461 std::array<double , 4 >& get_orientations ()
6562 {
66- size_t interface_counter = 0 ;
63+ auto orientation_interface_counter
64+ = std::count (existing_axes_.begin (), existing_axes_.begin () + 3 , true );
6765 for (size_t i = 3 ; i < 7 ; ++i) {
6866 if (existing_axes_[i]) {
6967 orientations_[i - 3 ]
70- = state_interfaces_[interface_counter ].get ().get_value ();
71- ++interface_counter ;
68+ = state_interfaces_[orientation_interface_counter ].get ().get_value ();
69+ ++orientation_interface_counter ;
7270 }
7371 }
7472 return orientations_;
0 commit comments