Skip to content

Commit 691dfd8

Browse files
committed
declare on_configure
Update joint_state_topic_hardware_interface.cpp also export the limited commands remove print add limited commands array too Update joint_state_topic_hardware_interface.hpp Apply suggestions from code review
1 parent 1f840c4 commit 691dfd8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

joint_state_topic_hardware_interface/include/joint_state_topic_hardware_interface/joint_state_topic_hardware_interface.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct VelocityLimits
3838
explicit VelocityLimits() = default;
3939
explicit VelocityLimits(const hardware_interface::InterfaceInfo& info)
4040
{
41-
std::cout << "********************* MIN IS " << info.min << " AND MAX IS " << info.max << std::endl;
4241
if(not info.min.empty())
4342
{
4443
min = std::stod(info.min);
@@ -58,6 +57,8 @@ class JointStateTopicSystem : public hardware_interface::SystemInterface
5857
public:
5958
CallbackReturn on_init(const hardware_interface::HardwareComponentInterfaceParams& params) override;
6059

60+
CallbackReturn on_configure(const rclcpp_lifecycle::State & previous_state) override;
61+
6162
std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
6263

6364
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
@@ -92,6 +93,7 @@ class JointStateTopicSystem : public hardware_interface::SystemInterface
9293

9394
bool enable_command_limiting_ = false;
9495
std::vector<double> nonlimited_velocity_commands_;
96+
std::vector<double> limited_velocity_commands_;
9597
std::vector<VelocityLimits> velocity_limits_;
9698

9799
// If the difference between the current joint state and joint command is less than this value,

joint_state_topic_hardware_interface/src/joint_state_topic_hardware_interface.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ CallbackReturn JointStateTopicSystem::on_init(const hardware_interface::Hardware
5959
joint_commands_.resize(standard_interfaces_.size());
6060
joint_states_.resize(standard_interfaces_.size());
6161
velocity_limits_.resize(get_hardware_info().joints.size());
62+
limited_velocity_commands_.resize(get_hardware_info().joints.size());
6263
nonlimited_velocity_commands_.resize(get_hardware_info().joints.size());
6364
for (auto i = 0u; i < standard_interfaces_.size(); i++)
6465
{
@@ -155,7 +156,8 @@ CallbackReturn JointStateTopicSystem::on_configure(const rclcpp_lifecycle::State
155156
{
156157
REGISTER_ROS2_CONTROL_INTROSPECTION("nonlimited_left_wheel_velocity", &nonlimited_velocity_commands_[0]);
157158
REGISTER_ROS2_CONTROL_INTROSPECTION("nonlimited_right_wheel_velocity", &nonlimited_velocity_commands_[1]);
158-
159+
REGISTER_ROS2_CONTROL_INTROSPECTION("limited_left_wheel_velocity", &limited_velocity_commands_[0]);
160+
REGISTER_ROS2_CONTROL_INTROSPECTION("limited_right_wheel_velocity", &limited_velocity_commands_[1]);
159161
return CallbackReturn::SUCCESS;
160162
}
161163

@@ -285,14 +287,12 @@ hardware_interface::return_type JointStateTopicSystem::write(const rclcpp::Time&
285287
}
286288
else if (interface.name == hardware_interface::HW_IF_VELOCITY)
287289
{
290+
nonlimited_velocity_commands_[i] = joint_commands_[VELOCITY_INTERFACE_INDEX][i];
288291
if(enable_command_limiting_)
289292
{
290-
//RCLCPP_WARN(get_node()->get_logger(),"Before clamp: %f",joint_commands_[VELOCITY_INTERFACE_INDEX][i]);
291-
nonlimited_velocity_commands_[i] = joint_commands_[VELOCITY_INTERFACE_INDEX][i];
292-
joint_commands_[VELOCITY_INTERFACE_INDEX][i] = std::clamp(nonlimited_velocity_commands_[i], velocity_limits_[i].min, velocity_limits_[i].max);
293-
//RCLCPP_WARN(get_node()->get_logger(),"After clamp: %f",joint_commands_[VELOCITY_INTERFACE_INDEX][i]);
293+
limited_velocity_commands_[i] = std::clamp(nonlimited_velocity_commands_[i], velocity_limits_[i].min, velocity_limits_[i].max);
294294
}
295-
joint_state.velocity.push_back(joint_commands_[VELOCITY_INTERFACE_INDEX][i]);
295+
joint_state.velocity.push_back(limited_velocity_commands_[i]);
296296
}
297297
else if (interface.name == hardware_interface::HW_IF_EFFORT)
298298
{

0 commit comments

Comments
 (0)