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

Update robot state if time since last command exceeds timeout #3251

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class ServoNode
planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;

KinematicState last_commanded_state_; // Used when commands go stale;
rclcpp::Time last_commanded_time_;
control_msgs::msg::JointJog latest_joint_jog_;
geometry_msgs::msg::TwistStamped latest_twist_;
geometry_msgs::msg::PoseStamped latest_pose_;
Expand Down
6 changes: 6 additions & 0 deletions moveit_ros/moveit_servo/src/servo_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ void ServoNode::servoLoop()
const bool use_trajectory = servo_params_.command_out_type == "trajectory_msgs/JointTrajectory";
const auto cur_time = node_->now();

if(cur_time.get_clock_type() == last_commanded_time_.get_clock_type() &&
cur_time - last_commanded_time_ > rclcpp::Duration::from_seconds(servo_params_.incoming_command_timeout)){
current_state = servo_->getCurrentRobotState(true /* block for current robot state */);
}

if (use_trajectory && !joint_cmd_rolling_window_.empty() && joint_cmd_rolling_window_.back().time_stamp > cur_time)
{
current_state = joint_cmd_rolling_window_.back();
Expand Down Expand Up @@ -385,6 +390,7 @@ void ServoNode::servoLoop()
multi_array_publisher_->publish(composeMultiArrayMessage(servo_->getParams(), next_joint_state.value()));
}
last_commanded_state_ = next_joint_state.value();
last_commanded_time_ = node_->now();
}
else
{
Expand Down