Skip to content

Commit

Permalink
Fixed for loop issiue, effort commands are working!
Browse files Browse the repository at this point in the history
  • Loading branch information
BartlomiejK2 committed Nov 17, 2024
1 parent b59477b commit 7b99fda
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions joint_controller_msgs/msg/JointCommand.msg
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# constants for a PD controller.
#
# Applied joint torque is calculated as follows:
# effort = feedforward_effort + kp_scale * kp * position_error + kd_scale * kd * velocity_error
# where kp and kd are constants in joint controller
# effort = feedforward_effort + kp_scale * kp * position_error
# + kd_scale * kd * velocity_error + ki * integration_error
# where kp, kd and ki are constants in joint controller parameters

std_msgs/Header header

Expand Down
3 changes: 2 additions & 1 deletion joint_controller_ros2_control/src/joint_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ controller_interface::return_type JointController::update_reference_from_subscri
controller_interface::return_type JointController::update_and_write_commands(
const rclcpp::Time & time, const rclcpp::Duration & period)
{
for(size_t i; i < joint_num_; ++i)
for(size_t i = 0; i < joint_num_; ++i)
{
joint_states_[i].position_ = position_state_interfaces_[i].get().get_value();
joint_states_[i].velocity_ = velocity_state_interfaces_[i].get().get_value();

double torque = joint_controllers_[i].calculateEffort(joint_commands_[i], joint_states_[i]);
std::cout << "Torque: " << torque << std::endl;
effort_command_interfaces_[i].get().set_value(torque);
}
return controller_interface::return_type::OK;
Expand Down

0 comments on commit 7b99fda

Please sign in to comment.