Skip to content

Commit b2decac

Browse files
authored
Merge pull request #1 from MiRoboticsLab/v1.2.0.0
V1.2.0.0
2 parents 8c64735 + 5b042cb commit b2decac

13 files changed

Lines changed: 805 additions & 215 deletions

File tree

cyberdog_manager/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ endif()
1515

1616
find_package(ament_cmake REQUIRED)
1717
find_package(rclcpp REQUIRED)
18+
find_package(rclcpp_action REQUIRED)
1819
find_package(manager_base REQUIRED)
1920
find_package(protocol REQUIRED)
2021
find_package(cyberdog_system REQUIRED)
@@ -35,6 +36,7 @@ add_executable(${PROJECT_NAME} src/cyberdog_manager.cpp src/main.cpp)
3536

3637
ament_target_dependencies( ${PROJECT_NAME}
3738
rclcpp
39+
rclcpp_action
3840
protocol
3941
manager_base
4042
cyberdog_system

cyberdog_manager/include/cyberdog_manager/audio_info.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,6 @@ class AudioInfoNode final
9494
auto mcpim_iter = module_code_play_id_map.find(code);
9595
if (mcpim_iter != module_code_play_id_map.end()) {
9696
uint16_t play_id = mcpim_iter->second;
97-
bool is_self_check = ((code % 10) == 9) ? true : false;
98-
if (is_self_check) {
99-
std::chrono::seconds timeout(2);
100-
auto req = std::make_shared<protocol::srv::SdcardPlayIdQuery::Request>();
101-
req->play_id = play_id;
102-
auto future_result = sdcard_playid_query_client_->async_send_request(req);
103-
std::future_status status = future_result.wait_for(timeout);
104-
if (status == std::future_status::ready) {
105-
} else {
106-
play_id = protocol::msg::AudioPlay::PID_SELF_CHECK_FAILED;
107-
}
108-
}
10997
std::chrono::seconds timeout(6);
11098
auto req = std::make_shared<protocol::srv::AudioTextPlay::Request>();
11199
req->module_name = audio_info_node_->get_name();
@@ -140,6 +128,8 @@ class AudioInfoNode final
140128
{1609, 31013}, // Uwb自检失败
141129
{5109, 31014}, // Audio自检失败
142130
{3009, 31015}, // Motion自检失败
131+
// {4409, 31056}, // Realsense自检失败
132+
{5300, 31058}, // algorithm加载完成
143133
{2403, 31016}, // GPS切换工作模式失败
144134
{2103, 31017}, // 雷达切换工作模式失败
145135
{2203, 31018}, // TOF切换工作模式失败

cyberdog_manager/include/cyberdog_manager/battery_capacity_info.hpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class BatteryCapacityInfoNode final
5959
{
6060
bc_callback_group_ =
6161
battery_capacity_info_node_->create_callback_group(
62-
rclcpp::CallbackGroupType::MutuallyExclusive);
62+
rclcpp::CallbackGroupType::Reentrant);
6363
rclcpp::SubscriptionOptions sub_options;
6464
sub_options.callback_group = bc_callback_group_;
6565
bms_status_sub_ = battery_capacity_info_node_->create_subscription<protocol::msg::BmsStatus>(
@@ -94,51 +94,60 @@ class BatteryCapacityInfoNode final
9494
if (!is_soc_zero_) {
9595
is_soc_zero_ = true;
9696
// is_soc_five_ = false;
97-
PlayAudioService("电量为0,关机中!");
97+
PlayAudioService(protocol::msg::AudioPlay::PID_PERCENT_0);
9898
}
99-
} else if (bms_status_.batt_soc <= 5) {
99+
} else if (bms_status_.batt_soc < 5) {
100100
if (!is_soc_five_) {
101101
is_soc_five_ = true;
102102
is_soc_twenty_ = false;
103-
PlayAudio("电量低于5%,电池即将耗尽,请尽快充电!");
103+
PlayAudio(protocol::msg::AudioPlay::PID_PERCENT_5);
104104
}
105-
} else if (bms_status_.batt_soc <= 20) {
105+
} else if (bms_status_.batt_soc < 20) {
106106
if (!is_soc_twenty_) {
107107
is_soc_twenty_ = true;
108108
is_soc_five_ = false;
109109
is_soc_thirty_ = false;
110-
PlayAudio("电量低于20%,部分功能受限!");
110+
PlayAudio(protocol::msg::AudioPlay::PID_PERCENT_20);
111111
}
112-
} else if (bms_status_.batt_soc <= 30) {
112+
} else if (bms_status_.batt_soc < 30) {
113113
if (!is_soc_thirty_) {
114114
is_soc_thirty_ = true;
115115
is_soc_twenty_ = false;
116-
PlayAudio("电量低于30%,请尽快充电!");
116+
PlayAudio(protocol::msg::AudioPlay::PID_PERCENT_30);
117117
}
118118
}
119119
} else {
120120
is_soc_twenty_ = false;
121121
is_soc_thirty_ = false;
122122
is_soc_five_ = false;
123123
}
124+
125+
// 状态机切换过程中,不再重复请求切换
126+
if (!ms_switch_mutex_.try_lock()) {
127+
WARN_MILLSECONDS(
128+
5000, "The machine_state is switching..."
129+
);
130+
return;
131+
}
124132
batsoc_notify_handler(bms_status_.batt_soc, bms_status_.power_wired_charging);
133+
ms_switch_mutex_.unlock();
125134
}
126135

127-
void PlayAudio(const std::string & text)
136+
void PlayAudio(const uint16_t play_id)
128137
{
129138
protocol::msg::AudioPlayExtend msg;
130-
msg.is_online = true;
139+
msg.is_online = false;
131140
msg.module_name = battery_capacity_info_node_->get_name();
132-
msg.text = text;
141+
msg.speech.play_id = play_id;
133142
audio_play_extend_pub->publish(msg);
134143
}
135144

136-
void PlayAudioService(const std::string & text)
145+
void PlayAudioService(const uint16_t play_id)
137146
{
138147
auto request_audio = std::make_shared<protocol::srv::AudioTextPlay::Request>();
139148
request_audio->module_name = battery_capacity_info_node_->get_name();
140-
request_audio->is_online = true;
141-
request_audio->text = text;
149+
request_audio->is_online = false;
150+
request_audio->speech.play_id = play_id;
142151
auto callback = [](rclcpp::Client<protocol::srv::AudioTextPlay>::SharedFuture future) {
143152
INFO("Audio play result: %s", future.get()->status == 0 ? "success" : "failed");
144153
};
@@ -168,6 +177,7 @@ class BatteryCapacityInfoNode final
168177
protocol::msg::BmsStatus bms_status_;
169178
BCINSOC_CALLBACK batsoc_notify_handler;
170179
BCINBMS_CALLBACK bms_notify_handler;
180+
std::mutex ms_switch_mutex_;
171181
bool is_soc_zero_;
172182
bool is_soc_five_;
173183
bool is_soc_twenty_;

cyberdog_manager/include/cyberdog_manager/error_context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ErrorContext final
8888
}
8989
void Init()
9090
{
91-
INFO("arror context thread started.");
91+
INFO("error context thread started.");
9292
thread_ = std::thread(
9393
[this]() {
9494
while (rclcpp::ok() && !exit_) {

cyberdog_manager/include/cyberdog_manager/led_info.hpp

Lines changed: 93 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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

121168
private:
@@ -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

Comments
 (0)