@@ -57,65 +57,112 @@ class LedInfoNode final
5757
5858 void BmsStatus (const protocol::msg::BmsStatus::SharedPtr msg)
5959 {
60+ power_charging_ = msg->power_wired_charging ;
6061 battery_soc_ = msg->batt_soc ;
61- bool power_wired_charging = msg->power_wired_charging ;
62- static bool is_set_led_zero = false ;
63- static bool is_set_led_twenty = false ;
64- static bool is_set_led_eigthy = false ;
65- static bool is_set_led_more_eigthy = false ;
66-
67- if (battery_soc_ <= 0 ) {
68- if (!power_wired_charging && !is_set_led_zero) {
69- is_set_led_zero = true ;
62+ static int start_battery_soc = battery_soc_;
63+ int charging_status_switch = false ;
64+
65+ // 充电状态切换flag
66+ if (pre_charging_status_ != power_charging_) {
67+ charging_status_switch = true ;
68+ }
69+ // 非充电状态,Bms释放灯效
70+ if (battery_soc_ > 20 ) {
71+ if (!power_charging_ && !bms_occupied_led_) {
72+ bms_occupied_led_ = true ;
73+ LedMode head{false , " bms" , 1 , 0x02 , 0x09 , 0xFF , 0x32 , 0x32 };
74+ LedMode tail{false , " bms" , 2 , 0x02 , 0x09 , 0xFF , 0x32 , 0x32 };
75+ LedMode mini{false , " bms" , 3 , 0x02 , 0x30 , 0xFF , 0x32 , 0x32 };
76+ bool result = ReqLedService (head, tail, mini);
77+ INFO (" Bms %s to release led occupation " , result ? " successed" : " failed" );
78+ }
79+ if (power_charging_) {
80+ bms_occupied_led_ = false ;
81+ }
82+ }
83+
84+ if ((pre_battery_soc_ == 1 && battery_soc_ == 0 ) || start_battery_soc == 0 ) {
85+ if (!power_charging_) {
7086 LedMode poweroff_head{true , " bms" , 1 , 0x01 , 0xA3 , 0x00 , 0x00 , 0x00 };
7187 LedMode poweroff_tail{true , " bms" , 2 , 0x01 , 0xA3 , 0x00 , 0x00 , 0x00 };
72- LedMode poweroff_mini{true , " bms" , 3 , 0x02 , 0x31 , 0xFF , 0x32 , 0x32 };
88+ LedMode poweroff_mini{true , " bms" , 3 , 0x02 , 0x31 , 0xFF , 0x00 , 0x00 };
7389 bool result = ReqLedService (poweroff_head, poweroff_tail, poweroff_mini);
7490 INFO (" %s set led when the soc is 0" , result ? " successed" : " failed" );
7591 }
76- } else if (battery_soc_ <= 20 ) {
77- if (!is_set_led_twenty) {
78- is_set_led_twenty = true ;
79- is_set_led_eigthy = false ;
80- LedMode bringup_head{true , " bms" , 1 , 0x02 , 0x09 , 0xFF , 0x32 , 0x32 };
81- LedMode bringup_tail{true , " bms" , 2 , 0x02 , 0x09 , 0xFF , 0x32 , 0x32 };
82- LedMode bringup_mini{true , " bms" , 3 , 0x02 , 0x30 , 0xFF , 0x32 , 0x32 };
83- bool result = ReqLedService (bringup_head, bringup_tail, bringup_mini);
92+ }
93+
94+ if ((pre_battery_soc_ == 21 && battery_soc_ == 20 ) ||
95+ (start_battery_soc > 0 && start_battery_soc <= 20 ) ||
96+ (charging_status_switch && battery_soc_ <= 20 ))
97+ {
98+ if (power_charging_) {
99+ LedMode head{true , " bms" , 1 , 0x02 , 0x06 , 0xFF , 0x32 , 0x32 };
100+ LedMode tail{true , " bms" , 2 , 0x02 , 0x06 , 0xFF , 0x32 , 0x32 };
101+ LedMode mini{true , " bms" , 3 , 0x02 , 0x30 , 0xFF , 0x00 , 0x00 };
102+ bool result = ReqLedService (head, tail, mini);
103+ INFO (" %s set the charging led when the soc less than 20" , result ? " successed" : " failed" );
104+ } else {
105+ LedMode head{true , " bms" , 1 , 0x02 , 0x09 , 0xFF , 0x32 , 0x32 };
106+ LedMode tail{true , " bms" , 2 , 0x02 , 0x09 , 0xFF , 0x32 , 0x32 };
107+ LedMode mini{true , " bms" , 3 , 0x02 , 0x30 , 0xFF , 0x00 , 0x00 };
108+ bool result = ReqLedService (head, tail, mini);
84109 INFO (" %s set led when the soc less than 20" , result ? " successed" : " failed" );
85110 }
86- } else if (battery_soc_ <= 80 ) {
87- if (!is_set_led_eigthy) {
88- is_set_led_eigthy = true ;
89- is_set_led_twenty = false ;
90- is_set_led_more_eigthy = false ;
111+ }
112+
113+ if ((pre_battery_soc_ == 20 && battery_soc_ == 21 ) ||
114+ (pre_battery_soc_ == 80 && battery_soc_ == 79 ) ||
115+ (start_battery_soc > 20 && start_battery_soc < 80 ) ||
116+ (charging_status_switch && battery_soc_ > 20 && battery_soc_ < 80 ))
117+ {
118+ if (power_charging_) {
119+ LedMode head{true , " bms" , 1 , 0x02 , 0x06 , 0x75 , 0xFC , 0xF6 };
120+ LedMode tail{true , " bms" , 2 , 0x02 , 0x06 , 0x75 , 0xFC , 0xF6 };
121+ LedMode mini{true , " bms" , 3 , 0x02 , 0x30 , 0x75 , 0xFC , 0xF6 };
122+ bool result = ReqLedService (head, tail, mini);
123+ INFO (
124+ " %s set the charging less, the soc more than 20 and less than 80 with charing" ,
125+ result ? " successed" : " failed" );
126+ } else {
91127 // 释放Bms灯效
92128 LedMode bringup_head{false , " bms" , 1 , 0x02 , 0x09 , 0xFF , 0x32 , 0x32 };
93129 LedMode bringup_tail{false , " bms" , 2 , 0x02 , 0x09 , 0xFF , 0x32 , 0x32 };
94130 LedMode bringup_mini{false , " bms" , 3 , 0x02 , 0x30 , 0xFF , 0x32 , 0x32 };
95131 bool result = ReqLedService (bringup_head, bringup_tail, bringup_mini);
96- INFO (" %s set led when the soc less than 20" , result ? " successed" : " failed" );
97-
98- // 更改系统灯效
99- LedMode sys_bringup_head{true , " system" , 1 , 0x02 , 0x09 , 0x75 , 0xFC , 0xF6 };
100- LedMode sys_bringup_tail{true , " system" , 2 , 0x02 , 0x09 , 0x75 , 0xFC , 0xF6 };
101- LedMode sys_bringup_mini{true , " system" , 3 , 0x02 , 0x30 , 0x75 , 0xFC , 0xF6 };
102- bool result2 = ReqLedService (sys_bringup_head, sys_bringup_tail, sys_bringup_mini);
103- INFO (
104- " %s set sys led, the soc more than 20 an less than 80" ,
105- result2 ? " successed" : " failed" );
132+ INFO (" bms %s release led when the soc less than 80" , result ? " successed" : " failed" );
106133 }
107- } else {
108- if (!is_set_led_more_eigthy) {
109- is_set_led_more_eigthy = true ;
110- is_set_led_eigthy = false ;
111- // 更改系统灯效
112- LedMode bringup_head{true , " system" , 1 , 0x02 , 0x09 , 0x06 , 0x21 , 0xE2 };
113- LedMode bringup_tail{true , " system" , 2 , 0x02 , 0x09 , 0x06 , 0x21 , 0xE2 };
114- LedMode bringup_mini{true , " system" , 3 , 0x02 , 0x30 , 0x06 , 0x21 , 0xE2 };
134+ // 更改系统灯效
135+ LedMode sys_bringup_head{true , " system" , 1 , 0x02 , 0x09 , 0x75 , 0xFC , 0xF6 };
136+ LedMode sys_bringup_tail{true , " system" , 2 , 0x02 , 0x09 , 0x75 , 0xFC , 0xF6 };
137+ LedMode sys_bringup_mini{true , " system" , 3 , 0x02 , 0x30 , 0x75 , 0xFC , 0xF6 };
138+ bool result2 = ReqLedService (sys_bringup_head, sys_bringup_tail, sys_bringup_mini);
139+ INFO (
140+ " %s set sys led, the soc more than 20 an less than 80" ,
141+ result2 ? " successed" : " failed" );
142+ }
143+
144+ if ((pre_battery_soc_ == 79 && battery_soc_ == 80 ) ||
145+ start_battery_soc >= 80 || (charging_status_switch && battery_soc_ >= 80 ))
146+ {
147+ // 更改系统灯效
148+ LedMode bringup_head{true , " system" , 1 , 0x02 , 0x09 , 0x06 , 0x21 , 0xE2 };
149+ LedMode bringup_tail{true , " system" , 2 , 0x02 , 0x09 , 0x06 , 0x21 , 0xE2 };
150+ LedMode bringup_mini{true , " system" , 3 , 0x02 , 0x30 , 0x06 , 0x21 , 0xE2 };
151+ bool result = ReqLedService (bringup_head, bringup_tail, bringup_mini);
152+ INFO (" %s set sys led, the soc more than 80" , result ? " successed" : " failed" );
153+ if (power_charging_) {
154+ LedMode bringup_head{true , " bms" , 1 , 0x02 , 0x06 , 0x06 , 0x21 , 0xE2 };
155+ LedMode bringup_tail{true , " bms" , 2 , 0x02 , 0x06 , 0x06 , 0x21 , 0xE2 };
156+ LedMode bringup_mini{true , " bms" , 3 , 0x02 , 0x30 , 0x06 , 0x21 , 0xE2 };
115157 bool result = ReqLedService (bringup_head, bringup_tail, bringup_mini);
116- INFO (" %s set sys led, the soc more than 80" , result ? " successed" : " failed" );
158+ INFO (
159+ " %s set the charging, the soc more than 80 with charing" ,
160+ result ? " successed" : " failed" );
117161 }
118162 }
163+ start_battery_soc = -1 ;
164+ pre_battery_soc_ = battery_soc_;
165+ pre_charging_status_ = power_charging_;
119166 }
120167
121168private:
@@ -208,7 +255,10 @@ class LedInfoNode final
208255 rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr wake_up_sub_ {nullptr };
209256 rclcpp::Client<protocol::srv::LedExecute>::SharedPtr led_excute_client_ {nullptr };
210257 uint8_t battery_soc_ {100 };
211- bool is_lowpower_ {false };
258+ uint8_t pre_battery_soc_ {0 };
259+ bool power_charging_ {false };
260+ bool pre_charging_status_ {false };
261+ bool bms_occupied_led_ {false };
212262};
213263} // namespace manager
214264} // namespace cyberdog
0 commit comments