Skip to content

Commit 13ae973

Browse files
committed
Update estimation function for updated schemas.
Signed-off-by: Kai Wen Lum <lum_kai_wen@artc.a-star.edu.sg>
1 parent aff37ef commit 13ae973

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

rmf_fleet_adapter/src/rmf_fleet_adapter/TaskManager.cpp

+38-35
Original file line numberDiff line numberDiff line change
@@ -1280,8 +1280,8 @@ nlohmann::json TaskManager::estimate_task_request(
12801280
"Unable to estimate final state for direct task request [%s]. This may "
12811281
"be due to insufficient resources to perform the task.",
12821282
request_id.c_str());
1283-
finish_state = start_state;
1284-
deployment_time = new_request->booking()->earliest_start_time();
1283+
return _make_error_response(
1284+
21, "Failed", "Failed Task Estimation");
12851285
}
12861286
else
12871287
{
@@ -1291,76 +1291,79 @@ nlohmann::json TaskManager::estimate_task_request(
12911291

12921292

12931293
// calculate estimated duration of task
1294-
nlohmann::json response_json;
1294+
nlohmann::json result_json;
12951295

12961296
RCLCPP_INFO(
12971297
_context->node()->get_logger(),
12981298
"Estimated results: \n"
12991299
);
13001300

1301-
response_json["deployment_time"] =
1301+
result_json["deployment_time"] =
13021302
to_millis(deployment_time.time_since_epoch()).count();
13031303

13041304
RCLCPP_INFO(
13051305
_context->node()->get_logger(),
13061306
" estimated deployment time: [%f]\n",
1307-
response_json["deployment_time"].get<double>()
1307+
result_json["deployment_time"].get<double>()
13081308
);
13091309

13101310
if (finish_state.time().has_value())
13111311
{
1312-
response_json["finish_time"] =
1312+
result_json["finish_time"] =
13131313
to_millis(finish_state.time().value().time_since_epoch()).count();
13141314

13151315
RCLCPP_INFO(
13161316
_context->node()->get_logger(),
13171317
" estimated finish time: [%f]\n",
1318-
response_json["finish_time"].get<double>()
1318+
result_json["finish_time"].get<double>()
13191319
);
13201320

13211321
auto estimate_duration_rmf =
13221322
std::chrono::duration_cast<std::chrono::milliseconds>(
13231323
finish_state.time().value() - deployment_time);
1324-
response_json["duration"] = estimate_duration_rmf.count();
1324+
result_json["duration"] = estimate_duration_rmf.count();
13251325

13261326
RCLCPP_INFO(
13271327
_context->node()->get_logger(),
13281328
" estimated duration: [%f] seconds\n",
1329-
response_json["duration"].get<double>()
1329+
result_json["duration"].get<double>()
13301330
);
13311331
}
13321332

13331333
// Convert rmf_task::State into a JSON
13341334
nlohmann::json state;
1335-
if (finish_state.waypoint().has_value())
1336-
{
1337-
state["waypoint"] = int(finish_state.waypoint().value());
1338-
RCLCPP_INFO(
1339-
_context->node()->get_logger(),
1340-
" waypoint: [%i]\n",
1341-
state["waypoint"].get<int>()
1342-
);
1343-
}
1344-
if (finish_state.orientation().has_value())
1335+
if (!finish_state.waypoint().has_value() || !finish_state.orientation().has_value()
1336+
|| !finish_state.battery_soc().has_value())
13451337
{
1346-
state["orientation"] = finish_state.orientation().value();
1347-
RCLCPP_INFO(
1348-
_context->node()->get_logger(),
1349-
" orientation: [%f]\n",
1350-
state["orientation"].get<double>()
1351-
);
1352-
}
1353-
if (finish_state.battery_soc().has_value())
1354-
{
1355-
state["battery_soc"] = finish_state.battery_soc().value();
1356-
RCLCPP_INFO(
1357-
_context->node()->get_logger(),
1358-
" battery soc: [%f]\n",
1359-
state["battery_soc"].get<double>()
1360-
);
1338+
return _make_error_response(
1339+
21, "Failed", "Failed Task Estimation");
13611340
}
13621341

1363-
response_json["state"] = state;
1342+
state["waypoint"] = int(finish_state.waypoint().value());
1343+
RCLCPP_INFO(
1344+
_context->node()->get_logger(),
1345+
" waypoint: [%i]\n",
1346+
state["waypoint"].get<int>()
1347+
);
1348+
1349+
state["orientation"] = finish_state.orientation().value();
1350+
RCLCPP_INFO(
1351+
_context->node()->get_logger(),
1352+
" orientation: [%f]\n",
1353+
state["orientation"].get<double>()
1354+
);
1355+
1356+
state["battery_soc"] = finish_state.battery_soc().value();
1357+
RCLCPP_INFO(
1358+
_context->node()->get_logger(),
1359+
" battery soc: [%f]\n",
1360+
state["battery_soc"].get<double>()
1361+
);
1362+
1363+
result_json["state"] = state;
1364+
nlohmann::json response_json;
1365+
response_json["success"] = false;
1366+
response_json["result"] = result_json;
13641367
return response_json;
13651368
}
13661369

0 commit comments

Comments
 (0)