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

ROS2 cancel action_server goal #718

Open
dines1111 opened this issue Apr 22, 2024 · 0 comments
Open

ROS2 cancel action_server goal #718

dines1111 opened this issue Apr 22, 2024 · 0 comments

Comments

@dines1111
Copy link

dines1111 commented Apr 22, 2024

Hai, can someone help me regrading how to cancel the action server goal?

This is my current code:

document.addEventListener('DOMContentLoaded', function() {
  var fibonacciClient = new ROSLIB.Action({
    ros : ros,
    name : '/fibonacci',
    actionType : 'action_tutorials_interfaces/Fibonacci'

  });

  // Send an action goal
  var goal = new ROSLIB.ActionGoal({
    order: 10,
  });

  // Variable to store the goal ID
  var actionGoalId ;

  document.getElementById('sendGoalButton').addEventListener('click', function() {
    // Send an action goal
    
    actionGoalId = fibonacciClient.sendGoal(goal,
      function(result) {
        console.log('Result for action goal on ' + fibonacciClient.name + ': ' + result.result.sequence);
      },
      function(feedback) {
        console.log('Feedback for action on ' + fibonacciClient.name + ': ' + feedback.partial_sequence);
      } 
    ); 
  });

  document.getElementById('cancelGoalButton').addEventListener('click', function() {
    // Check if a goal has been sent previously
    if (actionGoalId) {
      // Send a cancel request for the previously sent goal
      fibonacciClient.cancelGoal(actionGoalId);
      console.log('Cancel request sent for goal: ' + actionGoalId);
      goal_id = null; // Reset goal_id after cancellation
    } else {
      console.log('No goal has been sent yet.');
    }   
  });
});
@MatthijsBurgh MatthijsBurgh changed the title ROS2 CANCEL ACTION SERVER GOAL ROS2 cancel action_server goal Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant