Skip to content

Commit b22d191

Browse files
authored
Merge pull request #2 from MiRoboticsLab/v1.3.0.0
V1.3.0.0
2 parents b2decac + 2e67377 commit b22d191

7 files changed

Lines changed: 334 additions & 24 deletions

File tree

cyberdog_manager/include/cyberdog_manager/cyberdog_manager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "cyberdog_manager/error_context.hpp"
4242
#include "cyberdog_manager/machine_state_switch_context.hpp"
4343
#include "cyberdog_manager/led_info.hpp"
44+
#include "cyberdog_manager/power_brd_info.hpp"
4445

4546
namespace cyberdog
4647
{
@@ -79,6 +80,7 @@ class CyberdogManager /* : public ManagerBase */
7980
std::unique_ptr<cyberdog::manager::ErrorContext> error_context_ptr_ {nullptr};
8081
std::shared_ptr<cyberdog::manager::MachineStateSwitchContext> mssc_context_ptr_ {nullptr};
8182
std::shared_ptr<BlackBox> black_box_ptr_ {nullptr};
83+
std::shared_ptr<cyberdog::manager::PowerboardIndoNode> power_brd_node_ptr_ {nullptr};
8284
}; // class CyberdogManager
8385
} // namespace manager
8486
} // namespace cyberdog

cyberdog_manager/include/cyberdog_manager/led_info.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ class LedInfoNode final
8383

8484
if ((pre_battery_soc_ == 1 && battery_soc_ == 0) || start_battery_soc == 0) {
8585
if (!power_charging_) {
86-
LedMode poweroff_head{true, "bms", 1, 0x01, 0xA3, 0x00, 0x00, 0x00};
87-
LedMode poweroff_tail{true, "bms", 2, 0x01, 0xA3, 0x00, 0x00, 0x00};
88-
LedMode poweroff_mini{true, "bms", 3, 0x02, 0x31, 0xFF, 0x00, 0x00};
89-
bool result = ReqLedService(poweroff_head, poweroff_tail, poweroff_mini);
86+
bool result = ShutdownLightEffect(true);
9087
INFO("%s set led when the soc is 0", result ? "successed" : "failed");
9188
}
9289
}
@@ -165,6 +162,15 @@ class LedInfoNode final
165162
pre_charging_status_ = power_charging_;
166163
}
167164

165+
bool ShutdownLightEffect(bool trigger)
166+
{
167+
WARN("watiting for shutdown light effect");
168+
LedMode poweroff_head{trigger, "bms", 1, 0x01, 0xA3, 0x00, 0x00, 0x00};
169+
LedMode poweroff_tail{trigger, "bms", 2, 0x01, 0xA3, 0x00, 0x00, 0x00};
170+
LedMode poweroff_mini{trigger, "bms", 3, 0x02, 0x31, 0xFF, 0x00, 0x00};
171+
return ReqLedService(poweroff_head, poweroff_tail, poweroff_mini);
172+
}
173+
168174
private:
169175
void ReqAssignment(std::shared_ptr<protocol::srv::LedExecute::Request> req, LedMode & data)
170176
{

cyberdog_manager/include/cyberdog_manager/machine_state_switch_context.hpp

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class MachineStateSwitchContext final
136136
using SHUTDOWN_REBOOT_CALLBACK = std::function<int (bool)>;
137137
using EXCEPTION_PLAYSOUND_CALLBACK = std::function<void (int32_t )>;
138138
using CONTROL_TAIL_LED_CALLBACK = std::function<void (bool, bool)>;
139+
using LED_SHUTDOWN_CALLBACK = std::function<bool (bool)>;
139140

140141
public:
141142
explicit MachineStateSwitchContext(rclcpp::Node::SharedPtr node_ptr)
@@ -306,6 +307,10 @@ class MachineStateSwitchContext final
306307
{
307308
control_tail_led = callback;
308309
}
310+
void SetControlLedShutdownCallback(LED_SHUTDOWN_CALLBACK callback)
311+
{
312+
control_led_shutdown = callback;
313+
}
309314
void DogWakeup(const std_msgs::msg::Bool::SharedPtr msg)
310315
{
311316
if (machine_state_keep_) {
@@ -434,7 +439,7 @@ class MachineStateSwitchContext final
434439
}
435440
machine_state_keep_ = true;
436441
prohibit_shutdown_ = true;
437-
INFO("[MachineState-Switch]: keep machine state to start");
442+
INFO("[MachineState-Switch]: keep machine state to start, duration is %ds", request->ticks);
438443
keep_timer_ = mssc_node_->create_wall_timer(
439444
std::chrono::seconds(request->ticks),
440445
std::bind(&MachineStateSwitchContext::KeepTimerCallback, this), timer_callback_group_);
@@ -445,6 +450,15 @@ class MachineStateSwitchContext final
445450
response->success = true;
446451
response->code = 0;
447452
} else {
453+
// 复用服务接口,强行退出状态保持
454+
if (request->ticks == 0) {
455+
machine_state_keep_ = false;
456+
prohibit_shutdown_ = false;
457+
INFO("[MachineState-Switch]: request received, keep machine state to stop");
458+
response->success = true;
459+
response->code = 0;
460+
return;
461+
}
448462
response->success = true;
449463
response->code = -1;
450464
}
@@ -661,23 +675,27 @@ class MachineStateSwitchContext final
661675
if (mssc_machine_state == MsscMachineState::MSSC_OTA) {
662676
return;
663677
}
664-
// 状态机切换超时强制关机
665-
std::thread t{[&]() {
666-
std::this_thread::sleep_for(std::chrono::seconds(5));
667-
shutdown_or_reboot(false);
668-
}
669-
};
670-
t.detach();
678+
// 展示关机灯效
679+
control_led_shutdown(true);
671680

672681
// 先返回关机结果,再执行关机
673682
std::thread t_shutdown{[&]() {
674-
std::this_thread::sleep_for(std::chrono::seconds(3));
683+
std::this_thread::sleep_for(std::chrono::seconds(2));
675684
std::lock_guard<std::mutex> lck(state_mtx_);
676685
machine_state_handler_map[MachineStateChild::MSC_TEARDOWN]();
677686
shutdown_or_reboot(false);
678687
}
679688
};
680689
t_shutdown.detach();
690+
691+
// 状态机切换超时强制关机
692+
std::thread t{[&]() {
693+
std::this_thread::sleep_for(std::chrono::seconds(15));
694+
WARN("[MachineState-Switch]: shutdown timeout, force shutdown");
695+
shutdown_or_reboot(false);
696+
}
697+
};
698+
t.detach();
681699
response->success = true;
682700
}
683701

@@ -691,23 +709,26 @@ class MachineStateSwitchContext final
691709
if (mssc_machine_state == MsscMachineState::MSSC_OTA) {
692710
return;
693711
}
694-
695-
// 状态机切换超时强制重启
696-
std::thread t{[&]() {
697-
std::this_thread::sleep_for(std::chrono::seconds(5));
698-
shutdown_or_reboot(true);
699-
}
700-
};
701-
t.detach();
712+
// 展示关机灯效
713+
control_led_shutdown(true);
702714

703715
std::thread t_reboot{[&]() {
704-
std::this_thread::sleep_for(std::chrono::seconds(3));
716+
std::this_thread::sleep_for(std::chrono::seconds(2));
705717
std::lock_guard<std::mutex> lck(state_mtx_);
706718
machine_state_handler_map[MachineStateChild::MSC_TEARDOWN]();
707719
shutdown_or_reboot(true);
708720
}
709721
};
710722
t_reboot.detach();
723+
724+
// 状态机切换超时强制重启
725+
std::thread t{[&]() {
726+
WARN("[MachineState-Switch]: reboot timeout, force reboot");
727+
std::this_thread::sleep_for(std::chrono::seconds(15));
728+
shutdown_or_reboot(true);
729+
}
730+
};
731+
t.detach();
711732
response->success = true;
712733
}
713734

@@ -877,6 +898,7 @@ class MachineStateSwitchContext final
877898
EXCEPTION_PLAYSOUND_CALLBACK play_sound {[](int32_t) {}};
878899
SHUTDOWN_REBOOT_CALLBACK shutdown_or_reboot {[](bool) {return 0;}};
879900
CONTROL_TAIL_LED_CALLBACK control_tail_led {[](bool, bool) {}};
901+
LED_SHUTDOWN_CALLBACK control_led_shutdown {[](bool) {return 0;}};
880902
std::unique_ptr<cyberdog::manager::StateContext> machine_state_ptr_ {nullptr};
881903
bool machine_state_keep_ {false};
882904
bool prohibit_shutdown_ {false};

0 commit comments

Comments
 (0)