Skip to content

Commit

Permalink
Use set_joint_positions_clamped in update_robot & move_joint_to_zero (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored Dec 23, 2024
1 parent 7902daa commit aa3a91e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ fn move_joint_by_random(robot: &mut k::Chain<f32>) -> Result<(), k::Error> {
robot.set_joint_positions(&angles_vec)
}

fn move_joint_to_zero(robot: &mut k::Chain<f32>) -> Result<(), k::Error> {
fn move_joint_to_zero(robot: &mut k::Chain<f32>) {
let angles_vec = vec![0.0; robot.dof()];
robot.set_joint_positions(&angles_vec)
// use clamped variant because 0.0 is maybe out-of-limits.
robot.set_joint_positions_clamped(&angles_vec)
}

fn move_joint_by_index(
Expand Down Expand Up @@ -332,9 +333,8 @@ impl UrdfViewerApp {
fn update_robot(&mut self) {
// this is hack to handle invalid mimic joints, like hsr
let joint_positions = self.robot.joint_positions();
self.robot
.set_joint_positions(&joint_positions)
.unwrap_or_else(|err| error!("failed to update robot joints {err}"));
// Use clamped variant because 0.0 which is the default position value is maybe out-of-limits.
self.robot.set_joint_positions_clamped(&joint_positions);
self.viewer.update(&self.robot);
self.update_ik_target_marker();
self.update_frame_markers();
Expand Down Expand Up @@ -513,7 +513,7 @@ impl UrdfViewerApp {
Key::Z => {
self.robot.set_origin(na::Isometry::identity());
if self.has_joints() {
move_joint_to_zero(&mut self.robot).unwrap_or(());
move_joint_to_zero(&mut self.robot);
}
self.update_robot();
}
Expand Down

0 comments on commit aa3a91e

Please sign in to comment.