Cancel_task or kill_task failed (#350)

Posted by @[Missing data]:

Hi,

My task json is :
{‘category’: ‘compose’, ‘description’:{‘category’: ‘load_unload’, ‘phases’: [{‘activity’: {‘category’: ‘sequence’, ‘description’: {‘activities’: [{‘category’: ‘go_to_place’, ‘description’: {‘waypoint’: ‘靠墙点位’}}, {‘category’: ‘perform_action’, ‘description’: {‘category’: ‘load_unload’, ‘description’: {‘task_id’: ‘6F22ED8008DB52D38778AFC8B5779094’, ‘waypoint’: ‘靠墙点位’}, ‘unix_millis_action_duration_estimate’: 120000}}]}}}]}}

I execute self.update_handle.submit_direct_request() to submit the task

        def receive_response(rsp):
            self.logger.info("%s[%s]: receive_response rsp %s " % (log_prefix, task_id, rsp))
                if not rsp['success']:
                    self.logger.error("%s[%s]: receive_response with error" % (log_prefix, task_id))

        self.update_handle.submit_direct_request(
            task_json,
            task_id,
            receive_response
        )

Then RMF provides the scheduled path.
After the robot reaches the destination, the callback function is called

  def _action_executor(self, category: str,
                     description: dict,
                     execution:
                     adpt.robot_update_handle.ActionExecution):
                self.action_execution = execution

Then I call the following function periodically, the frequency is 10hz.

    self.update_handle.unstable_declare_holding(self.map_name, self.position, 60.0) 

One question here: Do I need to call self.update_handle.unstable_declare_holding() periodically, for example once per 0.1 second?
or just call that function once?

After several minutes, I execute self.update_handle.cancel_task() or self.update_handle.kill_task() as follows:

        def on_kill(killed):
            self.logger.info("%s on_kill result %s " % (log_prefix, killed,))
                if not killed:
                    self.logger.error("%s on_kill with error" % (self.log_prefix,))

        self.update_handle.kill_task(
            task_id,
            ["kill_task"],
            on_kill
        )

Sometimes, cancel_task or kill_task will fail. (the ‘killed’ parameter given in callback on_kill is False)
Sometimes they will succeed.

Could you please explain whey cancel_task/kill_task fails? That is in what kind of scenario, cancel/kill will fail?

Posted by @mxgrey:

I believe the only situations where it should return false are:

  1. The task did not exist
  2. The task has already been finished or killed

This has caused confusion for users in the past, so in the next major iteration of the API we’ll make the meaning of the return value more clear. In the meantime it’s best to track the published task state of the task if you need feedback on whether it’s been cancelled/killed successfully. The cancellation process is asynchronous so this function can’t give an immediate feedback on the outcome anyway.


Edited by @mxgrey at 2023-05-12T16:06:01Z