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 threading issue for collision velocity scaling in MoveIt Servo #2517

Merged
merged 3 commits into from Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions moveit_ros/moveit_servo/src/collision_monitor.cpp
Expand Up @@ -95,9 +95,6 @@ void CollisionMonitor::checkCollisions()
const double self_velocity_scale_coefficient{ log_val / servo_params_.self_collision_proximity_threshold };
const double scene_velocity_scale_coefficient{ log_val / servo_params_.scene_collision_proximity_threshold };

// Reset the scale on every iteration.
collision_velocity_scale_ = 1.0;

if (servo_params_.check_collisions)
sea-bass marked this conversation as resolved.
Show resolved Hide resolved
{
// Fetch latest robot state.
Expand All @@ -123,6 +120,11 @@ void CollisionMonitor::checkCollisions()
// k = - ln(0.001) / collision_proximity_threshold
// velocity_scale should equal one when collision_distance is at collision_proximity_threshold.
// velocity_scale should equal 0.001 when collision_distance is at zero.
//
// NOTE:
// collision_velocity_scale_ is shared by the primary servo thread. Be sure to not set any
// intermediate values in this loop or they can be picked up and throw off scaling while processing
// joint updates.

if (self_collision_result_.collision || scene_collision_result_.collision)
{
Expand Down Expand Up @@ -154,6 +156,12 @@ void CollisionMonitor::checkCollisions()
collision_velocity_scale_ = std::min(scene_collision_scale, self_collision_scale);
}
}
else
{
// If collision checking is disabled we do not scale
collision_velocity_scale_ = 1.0;
}

rate.sleep();
}
}
Expand Down