Skip to content

Commit

Permalink
Get task id from task state json instead of ros2 message's request id…
Browse files Browse the repository at this point in the history
…. (ROSI-AP/rosi-ap_commercial/cag/rmf_scheduler!29)

* Get task id from task state json instead of ros2 message's request id.

Signed-off-by: Kai Wen Lum <[email protected]>
  • Loading branch information
lkw303 authored and Briancbn committed Oct 19, 2023
1 parent 38d2fa2 commit 8e7d64b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions rmf_scheduler_plugins/src/robot_task_execution_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,34 +193,38 @@ void RobotTaskExecutionClient::cancel(const std::string & id)
void RobotTaskExecutionClient::handle_response(
const rmf_task_msgs::msg::ApiResponse & response)
{
auto task_status_itr = task_status_map_.find(response.request_id);
if (task_status_itr == task_status_map_.end()) {
return;
}

nlohmann::json task_state_json;
try {
task_state_json = nlohmann::json::parse(response.json_msg);
} catch (const std::exception & e) {
RCLCPP_ERROR(
node_->get_logger(),
"Error when parsing task states for task [%s]%s",
response.request_id.c_str(),
"Error when parsing task states %s",
e.what());
return;
}
std::string status = task_state_json["status"].get<std::string>();
auto task_id = task_state_json["data"]["booking"]["id"].get<std::string>();
auto task_status_itr = task_status_map_.find(task_id);
if (task_status_itr == task_status_map_.end()) {
return;
}
std::string status = task_state_json["data"]["status"].get<std::string>();
if (status != task_status_itr->second) {
RCLCPP_INFO(
node_->get_logger(),
"Received new task status [%s] for task [%s];",
status.c_str(),
response.request_id.c_str());
task_id.c_str());
task_status_itr->second = status;
}

if (status == "completed") {
notify_completion(response.request_id, true, "completed");
RCLCPP_INFO(
node_->get_logger(),
"Task [%s] is [%s];",
task_id.c_str(),
status.c_str());
notify_completion(task_id, true, "completed");
}
}

Expand Down

0 comments on commit 8e7d64b

Please sign in to comment.