Skip to content

Commit

Permalink
Removed wheel_joints_ map
Browse files Browse the repository at this point in the history
  • Loading branch information
roni-kreinin committed Nov 26, 2024
1 parent ee12654 commit f6a2efe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ class LynxHardware : public hardware_interface::SystemInterface
std::vector<double> hw_commands_;
std::vector<double> hw_states_position_, hw_states_position_offset_, hw_states_velocity_;

std::map<std::string, uint8_t> wheel_joints_;

uint8_t num_joints_;
std::string hw_name_;
};
Expand Down
21 changes: 12 additions & 9 deletions clearpath_hardware_interfaces/src/lynx/hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ void LynxHardware::writeCommandsToHardware()
{
sensor_msgs::msg::JointState joint_state;

for (const auto &it : wheel_joints_)
for (auto i = 0u; i < num_joints_; i++)
{
joint_state.name.push_back(it.first);
double speed = hw_commands_[it.second];
joint_state.name.push_back(info_.joints[i].name);
double speed = hw_commands_[i];
if (std::abs(speed) < MINIMUM_VELOCITY)
{
speed = 0.0;
}
joint_state.velocity.push_back(speed);
}

node_->drive_command(joint_state);
return;
}
Expand All @@ -79,13 +80,18 @@ void LynxHardware::updateJointsFromHardware(const rclcpp::Duration & period)

if (node_->has_new_feedback())
{

auto msg = node_->get_feedback();

for (auto& lynx : msg.drivers)
{
hw_states_velocity_[wheel_joints_[lynx.joint_name]] = lynx.velocity;
hw_states_position_[wheel_joints_[lynx.joint_name]] += lynx.velocity * period.seconds();
for (auto i = 0; i < num_joints_; i++)
{
if (lynx.joint_name == info_.joints[i].name)
{
hw_states_velocity_[i] = lynx.velocity;
hw_states_position_[i] += lynx.velocity * period.seconds();
}
}
}
}
}
Expand Down Expand Up @@ -238,9 +244,6 @@ std::vector<hardware_interface::CommandInterface> LynxHardware::export_command_i
command_interfaces.emplace_back(
hardware_interface::CommandInterface(
info_.joints[i].name, hardware_interface::HW_IF_VELOCITY, &hw_commands_[i]));

// Map wheel joint name to index
wheel_joints_[info_.joints[i].name] = i;
}

return command_interfaces;
Expand Down

0 comments on commit f6a2efe

Please sign in to comment.