提交 dfad11dd 编写于 作者: V Vivian Lin 提交者: siyangy

dreamview: refactored map element request (#1718)

上级 94082fb9
......@@ -326,6 +326,15 @@ Json SimulationWorldService::GetUpdateAsJson(double radius) const {
std::string sim_world_json;
::google::protobuf::util::MessageToJsonString(world_, &sim_world_json);
Json update = GetMapElements(radius);
update["type"] = "sim_world_update";
update["timestamp"] = apollo::common::time::AsInt64<millis>(Clock::Now());
update["world"] = Json::parse(sim_world_json);
return update;
}
Json SimulationWorldService::GetMapElements(double radius) const {
// Gather required map element ids based on current location.
apollo::common::PointENU point;
point.set_x(world_.auto_driving_car().position_x());
......@@ -334,15 +343,12 @@ Json SimulationWorldService::GetUpdateAsJson(double radius) const {
MapElementIds map_element_ids =
map_service_->CollectMapElementIds(point, radius);
Json update;
update["type"] = "sim_world_update";
update["timestamp"] = apollo::common::time::AsInt64<millis>(Clock::Now());
update["world"] = Json::parse(sim_world_json);
update["mapElementIds"] = map_element_ids.Json();
update["mapHash"] = map_element_ids.Hash();
update["radius"] = radius;
Json map;
map["mapElementIds"] = map_element_ids.Json();
map["mapHash"] = map_element_ids.Hash();
map["mapRadius"] = radius;
return update;
return map;
}
template <>
......
......@@ -79,6 +79,14 @@ class SimulationWorldService {
*/
nlohmann::json GetUpdateAsJson(double radius) const;
/**
* @brief Returns the json representation of the map element Ids and hash
* within the given radious from the car.
* @param radius the search distance from the current car location
* @return Json object that contains mapElementIds and mapHash.
*/
nlohmann::json GetMapElements(double radius) const;
/**
* @brief The function Update() is periodically called to check for updates
* from the adapters. All the updates will be written to the SimulationWorld
......
......@@ -67,9 +67,11 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
auto radius = json.find("radius");
if (radius == json.end()) {
AERROR << "Cannot retrieve map elements with unknown radius.";
return;
}
auto response = sim_world_service_.GetUpdateAsJson(*radius);
Json response = sim_world_service_.GetMapElements(*radius);
response["type"] = "MapElements";
websocket_->SendData(conn, response.dump());
});
......@@ -87,8 +89,8 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
// Publish monitor message.
if (succeed) {
sim_world_service_.PublishMonitorMessage(MonitorMessageItem::INFO,
"Routing Request Sent");
sim_world_service_.PublishMonitorMessage(
MonitorMessageItem::INFO, "Routing Request Sent");
} else {
sim_world_service_.PublishMonitorMessage(
MonitorMessageItem::ERROR, "Failed to send routing request");
......@@ -117,6 +119,14 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
bool SimulationWorldUpdater::ConstructRoutingRequest(
const Json &json, RoutingRequest *routing_request) {
// Input validations
if (json.find("start") == json.end() ||
json.find("end") == json.end() ||
json.find("sendDefaultRoute") == json.end()) {
AERROR << "Cannot prepare a routing request: input validation failed.";
return false;
}
// Try to reload end point if it hasn't be loaded yet.
if (!default_end_point_.has_id() &&
!GetProtoFromASCIIFile(EndWayPointFile(), &default_end_point_)) {
......
......@@ -283,8 +283,6 @@ export default class Map {
// side. This also means that the server should maintain a state of
// (possibly) visible elements, presummably in the global store.
appendMapData(newData, coordinates, scene) {
const overlapMap = extractOverlaps(newData['overlap']);
for (const kind in newData) {
if (!this.data[kind]) {
this.data[kind] = [];
......@@ -305,6 +303,7 @@ export default class Map {
}));
break;
case "signal":
const overlapMap = extractOverlaps(newData['overlap']);
this.data[kind].push(Object.assign(newData[kind][i], {
drewObjects: addTrafficLight(newData[kind][i],
overlapMap, this.laneHeading, coordinates, scene)
......
......@@ -37,16 +37,19 @@ class WebSocketEndpoint {
RENDERER.updateWorld(message.world);
STORE.meters.update(message.world);
STORE.monitor.update(message.world);
if ((message.mapHash && (this.counter % 10 === 0)) ||
this.currMapRadius !== message.radius) {
if (message.mapHash && (this.counter % 10 === 0)) {
// NOTE: This is a hack to limit the rate of map updates.
this.counter = 0;
this.currMapRadius = message.radius;
this.currMapRadius = message.mapRadius;
RENDERER.updateMapIndex(message.mapHash,
message.mapElementIds, message.radius);
message.mapElementIds, message.mapRadius);
}
this.counter += 1;
break;
case "MapElements":
RENDERER.updateMapIndex(message.mapHash,
message.mapElementIds, message.mapRadius);
break;
case "MapData":
RENDERER.updateMap(message.data);
STORE.setInitializationStatus(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册