DreamView界面修改

本文详细介绍了在DreamView中添加总里程和总时间的前后端实现过程。后端涉及canbus模块和DreamView模块,通过protobuf定义字段并进行通信。前端包括定义字节、数据接收与渲染,使用React组件更新界面。整个流程涵盖WebSock通信、STORE对象的更新以及React组件的交互。
摘要由CSDN通过智能技术生成

DreamView总里程时间添加过程

简介

这一节是关于dreamView的总里程和总时间以及单次里程和单次时间的添加和显示的问题.界面如下

在这里插入图片描述

过程

首先前后端通过WebSock进行通信,我们需要分别写好后端和前端才能完成这个过程

后端

canbus模块

首先定义protobuf的字段,这里我们需要定义总里程和总时间以及单次里程和单次时间,截取部分如下

 modules/canbus/proto/chassis.proto
 message Chassis {
         optional bool engine_started = 3;

          // Engine speed in RPM.
          optional float engine_rpm = 4 [default = nan];

          // Vehicle Speed in meters per second.
          optional float speed_mps = 5 [default = nan];
		===========================================
          // Vehicle total odometer in meters.
          optional float odometer_m = 6 [default = nan];
			
          // Vehicle A single odometer in meters.
          optional float single_odometer_m = 41 [default = nan];

          // Vehicle total auto_driver_time.
          optional float auto_driver_time = 42 [default = nan];

          // Vehicle  single auto_driver_time.
          optional float single_auto_driver_time = 43 [default = nan];
		===========================================
          // Fuel range in meters.
          optional int32 fuel_range_m = 7;

          // Real throttle location in [%], ranging from 0 to 100.
          optional float throttle_percentage = 8 [default = nan];

          // Real brake location in [%], ranging from 0 to 100.
          optional float brake_percentage = 9 [default = nan];
          }

定义好字节后,然后在canbus模块适当的位置给这些模块赋值,然后发出Chassis的channel供DreamView来reader.

DreamView模块

首先该模块也要定义好protobuf的字节,DreamView的字节如下

modules/dreamview/proto/simulation_world.proto
// Next-id: 35
message Object {
  // ID
  optional string id = 1;  // primary identifier for each object

  // Shape Info
  repeated PolygonPoint polygon_point = 2;  // corners of an object

  // Position Info
  optional double heading = 3;
  optional double latitude = 4;
  optional double longitude = 5;
  optional double position_x = 6;
  optional double position_y = 7;
  optional double length = 8 [default = 2.8];
  optional double width = 9 [default = 1.4];
  optional double height = 10 [default = 1.8];

  // Motion Info
  // For objects with motion info such as ADC.
  optional double speed = 11;               // in m/s, can be negative
  optional double speed_acceleration = 12;  // in m/s^2
  optional double speed_jerk = 13;
  optional double spin = 14;
  optional double spin_acceleration = 15;
  optional double spin_jerk = 16;
  optional double speed_heading = 17;
  optional double kappa = 18;

  // Signal Info
  // For objects with signals set and current signal such as Traffic Light,
  // Stop Sign, and Vehicle Signal.
  repeated string signal_set = 19;
  optional string current_signal = 20;

  // Time Info
  optional double timestamp_sec = 21;

  // Decision Info
  repeated Decision decision = 22;
  optional bool yielded_obstacle = 32 [default = false];

  // Chassis Info
  // For ADC
  optional double throttle_percentage = 23;
  optional double brake_percentage = 24;
  optional double steering_percentage = 25;
  optional double steering_angle = 26;
  optional double steering_ratio = 27;
  ===========================================
  // auto odometer
  optional float odometer_m = 35;
  // auto driver time
  optional float auto_driver_time = 36;
  // single auto odometer
  optional float single_odometer_m = 37;
  // single auto driver time
  optional float single_auto_driver_time = 38;
  ===========================================
  enum DisengageType {
    DISENGAGE_NONE = 0;
    DISENGAGE_UNKNOWN = 1;
    DISENGAGE_MANUAL = 2;
    DISENGAGE_EMERGENCY = 3;
    DISENGAGE_AUTO_STEER_ONLY = 4;
    DISENGAGE_AUTO_SPEED_ONLY = 5;
    DISENGAGE_CHASSIS_ERROR = 6;
  };

  optional DisengageType disengage_type = 28;

  enum Type {
    UNKNOWN = 0;
    UNKNOWN_MOVABLE = 1;
    UNKNOWN_UNMOVABLE = 2;
    PEDESTRIAN = 3;  // pedestrian, usually determined by moving behavior.
    BICYCLE = 4;     // bike, motor bike.
    VEHICLE = 5;     // passenger car or truck.
    VIRTUAL = 6;     // virtual object created by decision module.
    CIPV = 7;        // closest in-path vehicle determined by perception module.
  };

  optional Type type = 29;  // obstacle type
  optional apollo.perception.PerceptionObstacle.SubType sub_type = 34; // obstacle sub-type
  repeated Prediction prediction = 30;

  // perception confidence level. Range: [0,1]
  optional double confidence = 31 [default = 1];
  optional apollo.prediction.ObstaclePriority obstacle_priority = 33;
}

DreamView模块来接收canbus模块发布出来的chassis的topic,然后给定义好的字节来赋值.赋值如下:

modules/dreamview/backend/simulation_world/simulation_world_service.cc

template <>
void SimulationWorldService::UpdateSimulationWorld(const Chassis &chassis) {
  const auto &vehicle_param = VehicleConfigHelper::GetConfig().vehicle_param();
  Object *auto_driving_car = world_.mutable_auto_driving_car();

  double speed = chassis.speed_mps();
  if (chassis.gear_location() == Chassis::GEAR_REVERSE) {
    speed = -speed;
  }
  auto_driving_car->set_speed(speed);
  auto_driving_car->set_throttle_percentage(chassis.throttle_percentage());
  auto_driving_car->set_brake_percentage(chassis.brake_percentage());
     ===========================================
  // Set total odometer for autonomous driving
  auto_driving_car->set_odometer_m(chassis.odometer_m());
  auto_driving_car->set_auto_driver_time(chassis.auto_driver_time());
  AINFO << "chassis.auto_driver_time()" << chassis.auto_driver_time();
  // Set A single odometer for autonomous driving
  auto_driving_car->set_single_odometer_m(chassis.single_odometer_m());
  auto_driving_car->set_single_auto_driver_time(
      chassis.single_auto_driver_time());
  AINFO << "chassis.single_auto_driver_time()"
        << chassis.single_auto_driver_time();
     ===========================================
  // In case of out-of-range percentages, reduces it to zero.
  double angle_percentage = chassis.steering_percentage();
  if (angle_percentage > 100 || angle_percentage < -100) {
    angle_percentage = 0;
  }
  auto_driving_car->set_steering_percentage(angle_percentage);

  double steering_angle =
      angle_percentage / 100.0 * vehicle_param.max_steer_angle();
  auto_driving_car->set_steering_angle(steering_angle);

  double kappa = std::tan(steering_angle / vehicle_param.steer_ratio()) /
                 vehicle_param.length();
  auto_driving_car->set_kappa(kappa);

  UpdateTurnSignal(chassis.signal(), auto_driving_car);

  auto_driving_car->set_disengage_type(DeduceDisengageType(chassis));
}

这样后端就会把数据封装在auto_driving_car这个对象里面,然后通过WebSock发送给前端.

前端

定义字节

前端也一样,首先也要定义好要存放变量的字节,如下

modules/dreamview/frontend/proto_bundle/sim_world_proto_bundle.json
"Object": {
   
              "fields": {
   
                "id": {
   
                  "type": "string",
                  "id": 1
                },
                "polygonPoint": {
   
                  "rule": "repeated",
                  "type": "PolygonPoint",
                  "id": 2
                },
                "heading": {
   
                  "type": "double",
                  "id": 3
                },
                "latitude": {
   
                  "type": "double",
                  "id": 4
                },
                "longitude": {
   
                  "type": "double",
                  "id": 5
                },
                "positionX": {
   
                  "type": "double",
                  "id": 6
                },
                "positionY": {
   
                  "type": "double",
                  "id": 7
                },
                "length": {
   
                  "type": "double",
                  "id": 8,
                  "options": {
   
                    "default": 2.8
                  }
                },
                "width": {
   
                  "type": "double",
                  "id": 9,
                  "options": {
   
                    "default": 1.4
                  }
                },
                "height": {
   
                  "type": "double",
                  "id": 10,
                  "options": {
   
                    "default": 1.8
                  }
                },
                "speed": {
   
                  "type": "double",
                  "id": 11
                },
                "speedAcceleration": {
   
                  "type": "double",
                  "id": 12
                },
                "speedJerk": {
   
                  "type": "double",
                  "id": 13
                },
                "spin": {
   
                  "type": "double",
                  "id": 14
                },
                "spinAcceleration": {
   
                  "type": "double",
                  "id": 15
                },
                "spinJerk": {
   
                  "type": "double",
                  "id": 16
                },
                "speedHeading": {
   
                  "type": "double",
                  "id": 17
                },
                "kappa": {
   
                  "type": "double",
                  "id": 18
                },
                "signalSet": {
   
                  "rule": "repeated",
                  "type": "string",
                  "id": 19
                },
                "currentSignal": {
   
                  "type": "string",
                  "id": 20
                },
                "timestampSec": {
   
                  "type": "double",
                  "id": 21
                },
                "decision": {
   
                  "rule": "repeated",
                  "type": "Decision",
                  "id": 22
                },
                "yieldedObstacle": {
   
                  "type": "bool",
                  "id": 32,
                  "options": {
   
                    "default": false
                  }
                },
                "throttlePercentage": {
   
                  "type": "double",
                  "id": 23
                },
                "brakePercentage": {
   
                  "type": "double",
                  "id": 24
                },
                "steeringPercentage": {
   
                  "type": "double",
                  "id": 25
                },
                "steeringAngle": {
   
                  "type": "double",
                  "id": 26
                },
                "steeringRatio": {
   
                  "type": "double",
                  "id": 27
                },
                "disengageType": {
   
                  "type": "DisengageType",
                  "id": 28
                },
                "type": {
   
                  "type": "Type",
                  "id": 29
                },
                "subType": 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值