提交 7a706633 编写于 作者: S siyangy 提交者: Jiangtao Hu

send route_path separately

上级 d5736eb4
......@@ -65,7 +65,12 @@ DEFINE_double(sim_map_radius, 300.0,
"elements around the car.");
DEFINE_int32(dreamview_worker_num, 3, "number of dreamview thread workers");
DEFINE_bool(enable_update_size_check, true,
"True to check if the update byte number is less than threshold");
DEFINE_uint32(max_update_size, 1000000,
"number of max update bytes allowed to push to dreamview FE");
"Number of max update bytes allowed to push to dreamview FE");
DEFINE_bool(sim_world_with_routing_path, false,
"Whether the routing_path is included in sim_world proto.");
......@@ -44,7 +44,11 @@ DECLARE_string(ssl_certificate);
DECLARE_double(sim_map_radius);
DECLARE_int32(dreamview_worker_num);
DECLARE_bool(enable_update_size_check);
DECLARE_uint32(max_update_size);
DECLARE_bool(sim_world_with_routing_path);
#endif // MODULES_DREAMVIEW_BACKEND_COMMON_DREAMVIEW_GFLAGS_H_
......@@ -116,6 +116,7 @@ bool WebSocketHandler::SendData(Connection *conn, const std::string &data,
}
}
}
// Note that while we are holding the connection lock, the connection won't be
// closed and removed.
int ret;
......
......@@ -192,9 +192,7 @@ void UpdateTurnSignal(const apollo::common::VehicleSignal &signal,
}
}
inline double SecToMs(const double sec) {
return sec * 1000.0;
}
inline double SecToMs(const double sec) { return sec * 1000.0; }
} // namespace
......@@ -234,6 +232,9 @@ void SimulationWorldService::Update() {
auto car = world_.auto_driving_car();
world_.Clear();
*world_.mutable_auto_driving_car() = car;
route_paths_.clear();
to_clear_ = false;
}
......@@ -303,7 +304,7 @@ Json SimulationWorldService::GetUpdateAsJson(double radius) const {
}
void SimulationWorldService::GetMapElementIds(double radius,
MapElementIds *ids) {
MapElementIds *ids) const {
// Gather required map element ids based on current location.
apollo::common::PointENU point;
const auto &adc = world_.auto_driving_car();
......@@ -850,6 +851,7 @@ void SimulationWorldService::UpdateSimulationWorld(
}
world_.clear_route_path();
route_paths_.clear();
world_.set_routing_time(header_time);
for (const Path &path : paths) {
......@@ -859,14 +861,38 @@ void SimulationWorldService::UpdateSimulationWorld(
std::vector<int> sampled_indices =
DownsampleByAngle(path.path_points(), angle_threshold);
RoutePath *route_path = world_.add_route_path();
route_paths_.emplace_back();
RoutePath *route_path = &route_paths_.back();
for (int index : sampled_indices) {
const auto &path_point = path.path_points()[index];
PolygonPoint *route_point = route_path->add_point();
route_point->set_x(path_point.x() + map_service_->GetXOffset());
route_point->set_y(path_point.y() + map_service_->GetYOffset());
}
// Populate route path
if (FLAGS_sim_world_with_routing_path) {
auto *new_path = world_.add_route_path();
*new_path = *route_path;
}
}
}
Json SimulationWorldService::GetRoutePathAsJson() const {
Json response;
response["routingTime"] = world_.routing_time();
response["routePath"] = Json::array();
for (const auto &route_path : route_paths_) {
Json path;
path["point"] = Json::array();
for (const auto &route_point : route_path.point()) {
path["point"].push_back({{"x", route_point.x()},
{"y", route_point.y()},
{"z", route_point.z()}});
}
response["routePath"].push_back(path);
}
return response;
}
void SimulationWorldService::ReadRoutingFromFile(
......
......@@ -134,7 +134,9 @@ class SimulationWorldService {
buffer.AddMonitorMsgItem(log_level, msg);
}
void GetMapElementIds(double radius, MapElementIds *ids);
void GetMapElementIds(double radius, MapElementIds *ids) const;
nlohmann::json GetRoutePathAsJson() const;
private:
/**
......@@ -199,6 +201,9 @@ class SimulationWorldService {
// SimulationWorldService instance.
SimulationWorld world_;
// Downsampled route paths to be rendered in frontend.
std::vector<RoutePath> route_paths_;
// The handle of MapService, not owned by SimulationWorldService.
const MapService *map_service_;
......
......@@ -43,8 +43,8 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
bool routing_from_file)
: sim_world_service_(map_service, routing_from_file),
map_service_(map_service),
map_ws_(map_ws),
websocket_(websocket),
map_ws_(map_ws),
sim_control_(sim_control) {
RegisterMessageHandlers();
}
......@@ -149,6 +149,14 @@ void SimulationWorldUpdater::RegisterMessageHandlers() {
websocket_->SendBinaryData(conn, to_send, true);
});
websocket_->RegisterMessageHandler(
"RequestRoutePath",
[this](const Json &json, WebSocketHandler::Connection *conn) {
Json response = sim_world_service_.GetRoutePathAsJson();
response["type"] = "RoutePath";
websocket_->SendData(conn, response.dump());
});
websocket_->RegisterMessageHandler(
"GetDefaultEndPoint",
[this](const Json &json, WebSocketHandler::Connection *conn) {
......
......@@ -332,7 +332,7 @@ class Renderer {
this.perceptionObstacles.update(world, this.coordinates, this.scene);
this.decision.update(world, this.coordinates, this.scene);
this.prediction.update(world, this.coordinates, this.scene);
this.routing.update(world, this.coordinates, this.scene);
this.updateRouting(world.routingTime, world.routePath);
this.gnss.update(world, this.coordinates, this.scene);
if (this.planningAdc &&
......@@ -341,6 +341,10 @@ class Renderer {
}
}
updateRouting(routingTime, routePath) {
this.routing.update(routingTime, routePath, this.coordinates, this.scene);
}
updateGroundImage(mapName) {
this.ground.updateImage(mapName);
}
......
......@@ -338,7 +338,7 @@ export default class Map {
return { "pos": position, "heading": heading };
} else {
console.error('Error loading traffic light. Unable to determine heading.');
console.error('Error loading stop sign. Unable to determine heading.');
return null;
}
}
......
......@@ -12,16 +12,16 @@ export default class Routing {
this.lastRoutingTime = -1;
}
update(world, coordinates, scene) {
update(routingTime, routePath, coordinates, scene) {
this.routePaths.forEach(path => {
path.visible = STORE.options.showRouting;
});
// There has not been a new routing published since last time.
if (this.lastRoutingTime === world.routingTime) {
if (this.lastRoutingTime === routingTime || routePath === undefined) {
return;
}
this.lastRoutingTime = world.routingTime;
this.lastRoutingTime = routingTime;
// Clear the old route paths
this.routePaths.forEach(path => {
......@@ -30,11 +30,7 @@ export default class Routing {
path.geometry.dispose();
});
if (world.routePath === undefined) {
return;
}
world.routePath.forEach(path => {
routePath.forEach(path => {
const points = coordinates.applyOffsetToArray(path.point);
const pathMesh = drawThickBandFromPoints(points, 0.3 /* width */,
0xFF0000 /* red */, 0.6, 5 /* z offset */);
......
......@@ -14,6 +14,7 @@ export default class RosWebSocketEndpoint {
this.lastSeqNum = -1;
this.currMapRadius = null;
this.updatePOI = true;
this.routingTime = -1;
}
initialize() {
......@@ -71,6 +72,11 @@ export default class RosWebSocketEndpoint {
RENDERER.updateMapIndex(message.mapHash,
message.mapElementIds, message.mapRadius);
}
if (this.routingTime !== message.routingTime) {
// A new routing needs to be fetched from backend.
this.requestRoutePath();
this.routingTime = message.routingTime;
}
this.counter += 1;
break;
case "MapElementIds":
......@@ -80,6 +86,9 @@ export default class RosWebSocketEndpoint {
case "DefaultEndPoint":
STORE.routeEditingManager.updateDefaultRoutingEndPoint(message);
break;
case "RoutePath":
RENDERER.updateRouting(message.routingTime, message.routePath);
break;
}
};
this.websocket.onclose = event => {
......@@ -221,4 +230,10 @@ export default class RosWebSocketEndpoint {
enable: enable,
}));
}
requestRoutePath() {
this.websocket.send(JSON.stringify({
type: "RequestRoutePath",
}));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册