From 6069b0bbf6990ec156a9009a3ecdfc7df1072bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=94=B2?= <57082128+pkuwangjia@users.noreply.github.com> Date: Tue, 24 Nov 2020 10:47:15 +0800 Subject: [PATCH] canbus: neolix_edu add battery signals (#13044) --- modules/canbus/proto/neolix_edu.proto | 10 ++++- .../neolix_edu/neolix_edu_controller.cc | 14 ++++++- .../protocol/vcu_powerstatus_214.cc | 41 +++++++++++++++++++ .../neolix_edu/protocol/vcu_powerstatus_214.h | 21 ++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/modules/canbus/proto/neolix_edu.proto b/modules/canbus/proto/neolix_edu.proto index 63ac8b0ef14..00681d9aed9 100644 --- a/modules/canbus/proto/neolix_edu.proto +++ b/modules/canbus/proto/neolix_edu.proto @@ -86,10 +86,16 @@ message Vcu_powerstatus_214 { optional int32 vcu_powermodevalid = 2; // 0x0:NotActivate;0x1:Activate [bit] [0|1] optional bool replacebatterystateindication = 3; + // 0x0:Normal AEB;0x1:Forbidden [bit] [0|1] + optional bool forbidden_aeb_signal = 4; + // [A] [-400|910.68] + optional double bcu_chargedischargecurrent = 5; + // [V] [0|655.35] + optional double bcu_batt_internalvoltage = 6; // [bit] [0|15] - optional int32 vcu_driverinfo_alivecounter = 4; + optional int32 vcu_driverinfo_alivecounter = 7; // [bit] [0|255] - optional int32 vcu_driverinfo_checksum = 5; + optional int32 vcu_driverinfo_checksum = 8; } message Ads_light_horn_command_310 { diff --git a/modules/canbus/vehicle/neolix_edu/neolix_edu_controller.cc b/modules/canbus/vehicle/neolix_edu/neolix_edu_controller.cc index 101e20ba559..47e524d2a78 100644 --- a/modules/canbus/vehicle/neolix_edu/neolix_edu_controller.cc +++ b/modules/canbus/vehicle/neolix_edu/neolix_edu_controller.cc @@ -164,7 +164,7 @@ Chassis Neolix_eduController::chassis() { // 3 chassis_.set_engine_started(true); - // 4 speed_mps + // 3 speed_mps if (chassis_detail.neolix_edu().has_aeb_frontwheelspeed_353() && chassis_detail.neolix_edu().has_aeb_rearwheelspeed_354()) { auto wheelspeed = chassis_.mutable_wheel_speed(); @@ -185,7 +185,17 @@ Chassis Neolix_eduController::chassis() { } else { chassis_.set_speed_mps(0); } - + // 4 SOC + if (chassis_detail.neolix_edu().has_vcu_vehicle_status_report_101() && + chassis_detail.neolix_edu() + .vcu_vehicle_status_report_101() + .has_vcu_display_soc()) { + chassis_.set_battery_soc_percentage(chassis_detail.neolix_edu() + .vcu_vehicle_status_report_101() + .vcu_display_soc()); + } else { + chassis_.set_battery_soc_percentage(0); + } // 5 steering if (chassis_detail.neolix_edu().has_vcu_eps_report_57() && chassis_detail.neolix_edu().vcu_eps_report_57().has_vcu_real_angle()) { diff --git a/modules/canbus/vehicle/neolix_edu/protocol/vcu_powerstatus_214.cc b/modules/canbus/vehicle/neolix_edu/protocol/vcu_powerstatus_214.cc index c1e1533b635..2e0a6fe69e4 100644 --- a/modules/canbus/vehicle/neolix_edu/protocol/vcu_powerstatus_214.cc +++ b/modules/canbus/vehicle/neolix_edu/protocol/vcu_powerstatus_214.cc @@ -42,6 +42,16 @@ void Vcupowerstatus214::Parse(const std::uint8_t* bytes, int32_t length, ->mutable_vcu_powerstatus_214() ->set_replacebatterystateindication( replacebatterystateindication(bytes, length)); + chassis->mutable_neolix_edu() + ->mutable_vcu_powerstatus_214() + ->set_forbidden_aeb_signal(forbidden_aeb_signal(bytes, length)); + chassis->mutable_neolix_edu() + ->mutable_vcu_powerstatus_214() + ->set_bcu_chargedischargecurrent( + bcu_chargedischargecurrent(bytes, length)); + chassis->mutable_neolix_edu() + ->mutable_vcu_powerstatus_214() + ->set_bcu_batt_internalvoltage(bcu_batt_internalvoltage(bytes, length)); chassis->mutable_neolix_edu() ->mutable_vcu_powerstatus_214() ->set_vcu_driverinfo_alivecounter( @@ -92,6 +102,37 @@ bool Vcupowerstatus214::replacebatterystateindication(const std::uint8_t* bytes, return ret; } +bool Vcupowerstatus214::forbidden_aeb_signal(const std::uint8_t* bytes, + const int32_t length) const { + Byte t0(bytes + 1); + int32_t x = t0.get_byte(7, 1); + + bool ret = x; + return ret; +} + +float Vcupowerstatus214::bcu_chargedischargecurrent( + const std::uint8_t* bytes, const int32_t length) const { + Byte t0(bytes + 2); + Byte t1(bytes + 3); + int32_t x1 = t0.get_byte(0, 8); + int32_t x2 = t1.get_byte(0, 8); + + int ret = (x1 << 8 | x2) * 0.02 - 400; + return ret; +} + +float Vcupowerstatus214::bcu_batt_internalvoltage(const std::uint8_t* bytes, + const int32_t length) const { + Byte t0(bytes + 4); + Byte t1(bytes + 5); + int32_t x1 = t0.get_byte(0, 8); + int32_t x2 = t1.get_byte(0, 8); + + int ret = (x1 << 8 | x2) * 0.01; + return ret; +} + // config detail: {'name': 'vcu_driverinfo_alivecounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|15]', 'bit': 55, 'type': 'int', 'order': 'motorola', 'physical_unit': diff --git a/modules/canbus/vehicle/neolix_edu/protocol/vcu_powerstatus_214.h b/modules/canbus/vehicle/neolix_edu/protocol/vcu_powerstatus_214.h index 7a9a5062b65..0b8aaa51d35 100644 --- a/modules/canbus/vehicle/neolix_edu/protocol/vcu_powerstatus_214.h +++ b/modules/canbus/vehicle/neolix_edu/protocol/vcu_powerstatus_214.h @@ -53,6 +53,27 @@ class Vcupowerstatus214 : public ::apollo::drivers::canbus::ProtocolData< bool replacebatterystateindication(const std::uint8_t* bytes, const int32_t length) const; + // config detail: {'description': '0x0:Normal AEB;0x1:Forbidden', 'offset': + // 0.0, 'precision': 1.0, 'len': 1, 'name': 'forbidden_aeb_signal', + // 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 15, 'type': + // 'bool', 'order': 'motorola', 'physical_unit': 'bit'} + bool forbidden_aeb_signal(const std::uint8_t* bytes, + const int32_t length) const; + + // config detail: {'description': ';', 'offset': -400, 'precision': 0.02, + // 'len': 16, 'name': 'chargedischargecurrent', 'is_signed_var': False, + // 'physical_range': '[-400|910.68]', 'bit': 40, 'type': 'double', 'order': + // 'motorola', 'physical_unit': ''} + float bcu_chargedischargecurrent(const std::uint8_t* bytes, + const int32_t length) const; + + // config detail: {'description': ';', 'offset': 0, 'precision': 0.01, + // 'len': 16, 'name': 'batt_internalvoltage', 'is_signed_var': False, + // 'physical_range': '[0|655.35]', 'bit': 54, 'type': 'double', 'order': + // 'motorola', 'physical_unit': ''} + float bcu_batt_internalvoltage(const std::uint8_t* bytes, + const int32_t length) const; + // config detail: {'name': 'VCU_DriverInfo_AliveCounter', 'offset': 0.0, // 'precision': 1.0, 'len': 4, 'is_signed_var': False, 'physical_range': // '[0|15]', 'bit': 55, 'type': 'int', 'order': 'motorola', 'physical_unit':