Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting initial values if command interfaces are not defined. #110

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions gazebo_ros2_control/src/gazebo_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ void GazeboSystem::registerJoints(
this->dataPtr->joint_position_cmd_[j] = initial_position;
}
}
// independently of existence of command interface set initial value if defined
if (!std::isnan(initial_position)) {
this->dataPtr->sim_joints_[j]->SetPosition(0, initial_position, true);
}
if (joint_info.command_interfaces[i].name == "velocity") {
RCLCPP_INFO_STREAM(this->nh_->get_logger(), "\t\t velocity");
this->dataPtr->joint_control_methods_[j] |= VELOCITY;
Expand All @@ -272,6 +276,10 @@ void GazeboSystem::registerJoints(
this->dataPtr->joint_velocity_cmd_[j] = initial_velocity;
}
}
// independently of existence of command interface set initial value if defined
if (!std::isnan(initial_velocity)) {
this->dataPtr->sim_joints_[j]->SetVelocity(0, initial_velocity);
}
if (joint_info.command_interfaces[i].name == "effort") {
this->dataPtr->joint_control_methods_[j] |= EFFORT;
RCLCPP_INFO_STREAM(this->nh_->get_logger(), "\t\t effort");
Expand All @@ -283,6 +291,10 @@ void GazeboSystem::registerJoints(
this->dataPtr->joint_effort_cmd_[j] = initial_effort;
}
}
// independently of existence of command interface set initial value if defined
if (!std::isnan(initial_effort)) {
this->dataPtr->sim_joints_[j]->SetForce(0, initial_effort);
}
}
}
}
Expand Down Expand Up @@ -531,18 +543,13 @@ hardware_interface::return_type GazeboSystem::write(
for (unsigned int j = 0; j < this->dataPtr->joint_names_.size(); j++) {
if (this->dataPtr->sim_joints_[j]) {
if (this->dataPtr->joint_control_methods_[j] & POSITION) {
this->dataPtr->sim_joints_[j]->SetPosition(
0, this->dataPtr->joint_position_cmd_[j],
true);
this->dataPtr->sim_joints_[j]->SetPosition(0, this->dataPtr->joint_position_cmd_[j], true);
}
if (this->dataPtr->joint_control_methods_[j] & VELOCITY) {
this->dataPtr->sim_joints_[j]->SetVelocity(
0,
this->dataPtr->joint_velocity_cmd_[j]);
this->dataPtr->sim_joints_[j]->SetVelocity(0, this->dataPtr->joint_velocity_cmd_[j]);
}
if (this->dataPtr->joint_control_methods_[j] & EFFORT) {
const double effort = this->dataPtr->joint_effort_cmd_[j];
this->dataPtr->sim_joints_[j]->SetForce(0, effort);
this->dataPtr->sim_joints_[j]->SetForce(0, this->dataPtr->joint_effort_cmd_[j]);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion gazebo_ros2_control_demos/urdf/test_cart_effort.xacro.urdf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
<param name="min">-1000</param>
<param name="max">1000</param>
</command_interface>
<state_interface name="position"/>
<state_interface name="position">
<param name="initial_value">1.0</param>
</state_interface>
<state_interface name="velocity"/>
<state_interface name="effort"/>
</joint>
Expand Down