@@ -1280,8 +1280,8 @@ nlohmann::json TaskManager::estimate_task_request(
1280
1280
" Unable to estimate final state for direct task request [%s]. This may "
1281
1281
" be due to insufficient resources to perform the task." ,
1282
1282
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 " );
1285
1285
}
1286
1286
else
1287
1287
{
@@ -1291,76 +1291,79 @@ nlohmann::json TaskManager::estimate_task_request(
1291
1291
1292
1292
1293
1293
// calculate estimated duration of task
1294
- nlohmann::json response_json ;
1294
+ nlohmann::json result_json ;
1295
1295
1296
1296
RCLCPP_INFO (
1297
1297
_context->node ()->get_logger (),
1298
1298
" Estimated results: \n "
1299
1299
);
1300
1300
1301
- response_json [" deployment_time" ] =
1301
+ result_json [" deployment_time" ] =
1302
1302
to_millis (deployment_time.time_since_epoch ()).count ();
1303
1303
1304
1304
RCLCPP_INFO (
1305
1305
_context->node ()->get_logger (),
1306
1306
" estimated deployment time: [%f]\n " ,
1307
- response_json [" deployment_time" ].get <double >()
1307
+ result_json [" deployment_time" ].get <double >()
1308
1308
);
1309
1309
1310
1310
if (finish_state.time ().has_value ())
1311
1311
{
1312
- response_json [" finish_time" ] =
1312
+ result_json [" finish_time" ] =
1313
1313
to_millis (finish_state.time ().value ().time_since_epoch ()).count ();
1314
1314
1315
1315
RCLCPP_INFO (
1316
1316
_context->node ()->get_logger (),
1317
1317
" estimated finish time: [%f]\n " ,
1318
- response_json [" finish_time" ].get <double >()
1318
+ result_json [" finish_time" ].get <double >()
1319
1319
);
1320
1320
1321
1321
auto estimate_duration_rmf =
1322
1322
std::chrono::duration_cast<std::chrono::milliseconds>(
1323
1323
finish_state.time ().value () - deployment_time);
1324
- response_json [" duration" ] = estimate_duration_rmf.count ();
1324
+ result_json [" duration" ] = estimate_duration_rmf.count ();
1325
1325
1326
1326
RCLCPP_INFO (
1327
1327
_context->node ()->get_logger (),
1328
1328
" estimated duration: [%f] seconds\n " ,
1329
- response_json [" duration" ].get <double >()
1329
+ result_json [" duration" ].get <double >()
1330
1330
);
1331
1331
}
1332
1332
1333
1333
// Convert rmf_task::State into a JSON
1334
1334
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 ())
1345
1337
{
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" );
1361
1340
}
1362
1341
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;
1364
1367
return response_json;
1365
1368
}
1366
1369
0 commit comments