Skip to content

Commit a44a646

Browse files
lyklingdaohu527
andauthored
15 feature add yunle chassis (#18)
* feat: add yunle chassis support * feat(canbus): update canbus from upstream and complete yunle vehicle Signed-off-by: Pride Leong <[email protected]> * fix(canbus/yunle): fix steer direction and add value limits Signed-off-by: Pride Leong <[email protected]> * fix(canbus/yunle): do not set position light Signed-off-by: Pride Leong <[email protected]> * chore(whl-can): do not set epb in emergency Signed-off-by: Pride Leong <[email protected]> * fix(canbus/yunle): add command exists check before setting turn signal Signed-off-by: Pride Leong <[email protected]> * fix: fix typo Signed-off-by: Pride Leong <[email protected]> * chore: delete unused code in yunle_controller.cc --------- Signed-off-by: Pride Leong <[email protected]> Co-authored-by: daohu527 <[email protected]>
1 parent 89bdda0 commit a44a646

39 files changed

+3968
-42
lines changed

modules/canbus/vehicle/BUILD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ cc_library(
1212
copts = CANBUS_COPTS,
1313
deps = [
1414
"//modules/canbus/proto:canbus_conf_cc_proto",
15-
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
1615
"//modules/canbus/proto:vehicle_parameter_cc_proto",
1716
"//modules/common/configs:vehicle_config_helper",
1817
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
18+
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
1919
"//modules/common_msgs/control_msgs:control_cmd_cc_proto",
2020
"//modules/drivers/canbus/can_client",
2121
"//modules/drivers/canbus/can_comm:can_sender",
@@ -30,8 +30,8 @@ cc_library(
3030
hdrs = ["abstract_vehicle_factory.h"],
3131
copts = CANBUS_COPTS,
3232
deps = [
33-
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
3433
"//modules/canbus/vehicle:vehicle_controller_base",
34+
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
3535
"//modules/drivers/canbus/can_comm:message_manager_base",
3636
"//modules/drivers/canbus/common:canbus_common",
3737
],
@@ -50,9 +50,11 @@ cc_library(
5050
"//modules/canbus/vehicle/gem:gem_vehicle_factory",
5151
"//modules/canbus/vehicle/lexus:lexus_vehicle_factory",
5252
"//modules/canbus/vehicle/lincoln:lincoln_vehicle_factory",
53+
"//modules/canbus/vehicle/mk_mini:mk_mini_vehicle_factory",
5354
"//modules/canbus/vehicle/neolix_edu:neolix_edu_vehicle_factory",
5455
"//modules/canbus/vehicle/transit:transit_vehicle_factory",
5556
"//modules/canbus/vehicle/wey:wey_vehicle_factory",
57+
"//modules/canbus/vehicle/yunle:yunle_vehicle_factory",
5658
"//modules/canbus/vehicle/zhongyun:zhongyun_vehicle_factory",
5759
"//modules/canbus/vehicle/mk_mini:mk_mini_vehicle_factory",
5860
"//modules/common/util:factory",

modules/canbus/vehicle/vehicle_controller.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ ErrorCode VehicleController::Update(const ControlCommand &control_command) {
127127
driving_mode() == Chassis::AUTO_SPEED_ONLY) {
128128
Gear(control_command.gear_location());
129129
Throttle(control_command.throttle());
130-
Speed(control_command.speed());
131130
Acceleration(control_command.acceleration());
131+
Speed(control_command.speed());
132132
Brake(control_command.brake());
133133
SetEpbBreak(control_command);
134134
SetLimits();

modules/canbus/vehicle/vehicle_controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
#include <unordered_map>
2525

2626
#include "modules/canbus/proto/canbus_conf.pb.h"
27+
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
2728
#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
2829
#include "modules/common_msgs/chassis_msgs/chassis_detail.pb.h"
2930
#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
3031

3132
#include "modules/common/configs/vehicle_config_helper.h"
32-
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
3333
#include "modules/drivers/canbus/can_comm/can_sender.h"
3434
#include "modules/drivers/canbus/can_comm/message_manager.h"
3535
#include "modules/drivers/canbus/can_comm/protocol_data.h"

modules/canbus/vehicle/vehicle_factory.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@
1515
*****************************************************************************/
1616

1717
#include "modules/canbus/vehicle/vehicle_factory.h"
18+
1819
#include "modules/canbus/proto/vehicle_parameter.pb.h"
20+
1921
#include "modules/canbus/vehicle/ch/ch_vehicle_factory.h"
2022
#include "modules/canbus/vehicle/devkit/devkit_vehicle_factory.h"
2123
#include "modules/canbus/vehicle/ge3/ge3_vehicle_factory.h"
2224
#include "modules/canbus/vehicle/gem/gem_vehicle_factory.h"
2325
#include "modules/canbus/vehicle/lexus/lexus_vehicle_factory.h"
2426
#include "modules/canbus/vehicle/lincoln/lincoln_vehicle_factory.h"
27+
#include "modules/canbus/vehicle/mk_mini/mk_mini_vehicle_factory.h"
2528
#include "modules/canbus/vehicle/neolix_edu/neolix_edu_vehicle_factory.h"
2629
#include "modules/canbus/vehicle/transit/transit_vehicle_factory.h"
2730
#include "modules/canbus/vehicle/wey/wey_vehicle_factory.h"
31+
#include "modules/canbus/vehicle/yunle/yunle_vehicle_factory.h"
2832
#include "modules/canbus/vehicle/zhongyun/zhongyun_vehicle_factory.h"
29-
#include "modules/canbus/vehicle/mk_mini/mk_mini_vehicle_factory.h"
3033
namespace apollo {
3134
namespace canbus {
3235

@@ -52,17 +55,19 @@ void VehicleFactory::RegisterVehicleFactory() {
5255
Register(apollo::common::ZHONGYUN, []() -> AbstractVehicleFactory * {
5356
return new ZhongyunVehicleFactory();
5457
});
55-
Register(apollo::common::CH, []() -> AbstractVehicleFactory * {
56-
return new ChVehicleFactory();
57-
});
58+
Register(apollo::common::CH,
59+
[]() -> AbstractVehicleFactory * { return new ChVehicleFactory(); });
5860
Register(apollo::common::DKIT, []() -> AbstractVehicleFactory * {
5961
return new DevkitVehicleFactory();
6062
});
6163
Register(apollo::common::NEOLIX, []() -> AbstractVehicleFactory * {
6264
return new Neolix_eduVehicleFactory();
6365
});
6466
Register(apollo::common::MK_MINI, []() -> AbstractVehicleFactory * {
65-
return new Mk_miniVehicleFactory();
67+
return new Mk_miniVehicleFactory();
68+
});
69+
Register(apollo::common::YUNLE, []() -> AbstractVehicleFactory * {
70+
return new YunleVehicleFactory();
6671
});
6772
}
6873

modules/canbus/vehicle/yunle/BUILD

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
load("//tools:cpplint.bzl", "cpplint")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
cc_library(
6+
name = "yunle_vehicle_factory",
7+
srcs = [
8+
"yunle_vehicle_factory.cc",
9+
],
10+
hdrs = [
11+
"yunle_vehicle_factory.h",
12+
],
13+
deps = [
14+
":yunle_controller",
15+
":yunle_message_manager",
16+
"//modules/canbus/vehicle:abstract_vehicle_factory",
17+
],
18+
)
19+
20+
cc_library(
21+
name = "yunle_message_manager",
22+
srcs = [
23+
"yunle_message_manager.cc",
24+
],
25+
hdrs = [
26+
"yunle_message_manager.h",
27+
],
28+
deps = [
29+
"//modules/drivers/canbus/common:canbus_common",
30+
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
31+
"//modules/drivers/canbus/can_comm:message_manager_base",
32+
"//modules/canbus/vehicle/yunle/protocol:canbus_yunle_protocol",
33+
],
34+
)
35+
36+
cc_library(
37+
name = "yunle_controller",
38+
srcs = [
39+
"yunle_controller.cc",
40+
],
41+
hdrs = [
42+
"yunle_controller.h",
43+
],
44+
deps = [
45+
":yunle_message_manager",
46+
"//modules/drivers/canbus/can_comm:can_sender",
47+
"//modules/drivers/canbus/common:canbus_common",
48+
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
49+
"//modules/drivers/canbus/can_comm:message_manager_base",
50+
"//modules/canbus/vehicle:vehicle_controller_base",
51+
"//modules/canbus/vehicle/yunle/protocol:canbus_yunle_protocol",
52+
],
53+
)
54+
55+
cpplint()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load("//tools:cpplint.bzl", "cpplint")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
cc_library(
6+
name = "canbus_yunle_protocol",
7+
srcs = glob([
8+
"*.cc",
9+
]),
10+
hdrs = glob([
11+
"*.h",
12+
]),
13+
deps = [
14+
"//modules/common_msgs/chassis_msgs:chassis_detail_cc_proto",
15+
"//modules/drivers/canbus/can_comm:message_manager_base",
16+
"//modules/drivers/canbus/common:canbus_common",
17+
],
18+
)
19+
20+
cpplint()
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/******************************************************************************
2+
* Copyright 2019 The Apollo Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*****************************************************************************/
16+
17+
#include "modules/canbus/vehicle/yunle/protocol/bms_rt_soc_17904001.h"
18+
19+
#include "glog/logging.h"
20+
21+
#include "modules/drivers/canbus/common/byte.h"
22+
#include "modules/drivers/canbus/common/canbus_consts.h"
23+
24+
namespace apollo {
25+
namespace canbus {
26+
namespace yunle {
27+
28+
using ::apollo::drivers::canbus::Byte;
29+
30+
Bmsrtsoc17904001::Bmsrtsoc17904001() {}
31+
const int32_t Bmsrtsoc17904001::ID = 0x97904001;
32+
33+
void Bmsrtsoc17904001::Parse(const std::uint8_t* bytes, int32_t length,
34+
ChassisDetail* chassis) const {
35+
chassis->mutable_yunle()->mutable_bms_rt_soc_17904001()->set_bms_current_cur(bms_current_cur(bytes, length));
36+
chassis->mutable_yunle()->mutable_bms_rt_soc_17904001()->set_bms_current_vol(bms_current_vol(bytes, length));
37+
chassis->mutable_yunle()->mutable_bms_rt_soc_17904001()->set_bms_total_volbat(bms_total_volbat(bytes, length));
38+
chassis->mutable_yunle()->mutable_bms_rt_soc_17904001()->set_bms_soc(bms_soc(bytes, length));
39+
}
40+
41+
// config detail: {'bit': 32, 'is_signed_var': False, 'len': 16, 'name': 'bms_current_cur', 'offset': -3000.0, 'order': 'intel', 'physical_range': '[3000|9553.5]', 'physical_unit': 'A', 'precision': 0.1, 'type': 'double'}
42+
double Bmsrtsoc17904001::bms_current_cur(const std::uint8_t* bytes, int32_t length) const {
43+
Byte t0(bytes + 5);
44+
int32_t x = t0.get_byte(0, 8);
45+
46+
Byte t1(bytes + 4);
47+
int32_t t = t1.get_byte(0, 8);
48+
x <<= 8;
49+
x |= t;
50+
51+
double ret = x * 0.100000 + -3000.000000;
52+
return ret;
53+
}
54+
55+
// config detail: {'bit': 16, 'is_signed_var': False, 'len': 16, 'name': 'bms_current_vol', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|6553.5]', 'physical_unit': 'V', 'precision': 0.1, 'type': 'double'}
56+
double Bmsrtsoc17904001::bms_current_vol(const std::uint8_t* bytes, int32_t length) const {
57+
Byte t0(bytes + 3);
58+
int32_t x = t0.get_byte(0, 8);
59+
60+
Byte t1(bytes + 2);
61+
int32_t t = t1.get_byte(0, 8);
62+
x <<= 8;
63+
x |= t;
64+
65+
double ret = x * 0.100000;
66+
return ret;
67+
}
68+
69+
// config detail: {'bit': 0, 'is_signed_var': False, 'len': 16, 'name': 'bms_total_volbat', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|6553.5]', 'physical_unit': 'V', 'precision': 0.1, 'type': 'double'}
70+
double Bmsrtsoc17904001::bms_total_volbat(const std::uint8_t* bytes, int32_t length) const {
71+
Byte t0(bytes + 1);
72+
int32_t x = t0.get_byte(0, 8);
73+
74+
Byte t1(bytes + 0);
75+
int32_t t = t1.get_byte(0, 8);
76+
x <<= 8;
77+
x |= t;
78+
79+
double ret = x * 0.100000;
80+
return ret;
81+
}
82+
83+
// config detail: {'bit': 48, 'description': '荷电状态', 'is_signed_var': False, 'len': 16, 'name': 'bms_soc', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|6553.5]', 'physical_unit': '%', 'precision': 0.1, 'type': 'double'}
84+
double Bmsrtsoc17904001::bms_soc(const std::uint8_t* bytes, int32_t length) const {
85+
Byte t0(bytes + 7);
86+
int32_t x = t0.get_byte(0, 8);
87+
88+
Byte t1(bytes + 6);
89+
int32_t t = t1.get_byte(0, 8);
90+
x <<= 8;
91+
x |= t;
92+
93+
double ret = x * 0.100000;
94+
return ret;
95+
}
96+
} // namespace yunle
97+
} // namespace canbus
98+
} // namespace apollo
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/******************************************************************************
2+
* Copyright 2019 The Apollo Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*****************************************************************************/
16+
17+
#pragma once
18+
19+
#include "modules/drivers/canbus/can_comm/protocol_data.h"
20+
#include "modules/common_msgs/chassis_msgs/chassis_detail.pb.h"
21+
22+
namespace apollo {
23+
namespace canbus {
24+
namespace yunle {
25+
26+
class Bmsrtsoc17904001 : public ::apollo::drivers::canbus::ProtocolData<
27+
::apollo::canbus::ChassisDetail> {
28+
public:
29+
static const int32_t ID;
30+
Bmsrtsoc17904001();
31+
void Parse(const std::uint8_t* bytes, int32_t length,
32+
ChassisDetail* chassis) const override;
33+
34+
private:
35+
36+
// config detail: {'bit': 32, 'is_signed_var': False, 'len': 16, 'name': 'BMS_current_Cur', 'offset': -3000.0, 'order': 'intel', 'physical_range': '[3000|9553.5]', 'physical_unit': 'A', 'precision': 0.1, 'type': 'double'}
37+
double bms_current_cur(const std::uint8_t* bytes, const int32_t length) const;
38+
39+
// config detail: {'bit': 16, 'is_signed_var': False, 'len': 16, 'name': 'BMS_current_Vol', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|6553.5]', 'physical_unit': 'V', 'precision': 0.1, 'type': 'double'}
40+
double bms_current_vol(const std::uint8_t* bytes, const int32_t length) const;
41+
42+
// config detail: {'bit': 0, 'is_signed_var': False, 'len': 16, 'name': 'BMS_Total_VolBat', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|6553.5]', 'physical_unit': 'V', 'precision': 0.1, 'type': 'double'}
43+
double bms_total_volbat(const std::uint8_t* bytes, const int32_t length) const;
44+
45+
// config detail: {'bit': 48, 'description': '荷电状态', 'is_signed_var': False, 'len': 16, 'name': 'BMS_SOC', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|6553.5]', 'physical_unit': '%', 'precision': 0.1, 'type': 'double'}
46+
double bms_soc(const std::uint8_t* bytes, const int32_t length) const;
47+
};
48+
49+
} // namespace yunle
50+
} // namespace canbus
51+
} // namespace apollo
52+
53+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/******************************************************************************
2+
* Copyright 2019 The Apollo Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*****************************************************************************/
16+
17+
#include "modules/canbus/vehicle/yunle/protocol/bms_soc_101.h"
18+
19+
#include "glog/logging.h"
20+
21+
#include "modules/drivers/canbus/common/byte.h"
22+
#include "modules/drivers/canbus/common/canbus_consts.h"
23+
24+
namespace apollo {
25+
namespace canbus {
26+
namespace yunle {
27+
28+
using ::apollo::drivers::canbus::Byte;
29+
30+
Bmssoc101::Bmssoc101() {}
31+
const int32_t Bmssoc101::ID = 0x101;
32+
33+
void Bmssoc101::Parse(const std::uint8_t* bytes, int32_t length,
34+
ChassisDetail* chassis) const {
35+
chassis->mutable_yunle()->mutable_bms_soc_101()->set_rsoc(rsoc(bytes, length));
36+
}
37+
38+
// config detail: {'bit': 39, 'is_signed_var': True, 'len': 16, 'name': 'rsoc', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
39+
int Bmssoc101::rsoc(const std::uint8_t* bytes, int32_t length) const {
40+
Byte t0(bytes + 4);
41+
int32_t x = t0.get_byte(0, 8);
42+
43+
Byte t1(bytes + 5);
44+
int32_t t = t1.get_byte(0, 8);
45+
x <<= 8;
46+
x |= t;
47+
48+
x <<= 16;
49+
x >>= 16;
50+
51+
int ret = x;
52+
return ret;
53+
}
54+
} // namespace yunle
55+
} // namespace canbus
56+
} // namespace apollo

0 commit comments

Comments
 (0)