change file readme

This commit is contained in:
2026-06-06 10:34:18 +07:00
parent 5cdacdeebf
commit 1bd09d5e8e
4 changed files with 632 additions and 618 deletions

View File

@@ -2,86 +2,96 @@
#include <move_base_core/navigation.h>
using namespace mission_adapters;
class RobotControlTest
{
// Giả sử chúng ta có một implementation của BaseNavigation, ví dụ MoveBase và đã được load vào move_base_ptr_
robot::move_base_core::BaseNavigation::Ptr move_base_ptr_;
mission_adapters::MissionManager mission_manager_;
mission_adapters::EventProcessor event_processor_{mission_manager_};
mission_adapters::MissionManager mission_manager_;
mission_adapters::EventProcessor event_processor_{mission_manager_};
mission_adapters::MissionExecutor mission_executor_{mission_manager_};
std::shared_ptr<Mission> mission_prev_ = nullptr;
robot::move_base_core::State prev_state_ = PENDING;
// FIX #7: Fully qualified namespace for the initial value.
robot::move_base_core::State prev_nav_state_ = robot::move_base_core::State::PENDING;
// Tracks whether the actions of the current mission are complete.
// FIX #8: Stub — replace with real action-done check from your action executor.
bool areActionsDone() const
{
// TODO: query your action executor for completion status.
return true;
}
public:
RobotControlTest() = default;
RobotControlTest() = default;
~RobotControlTest();
void run();
private:
void executeMission(const Mission& mission);
};
RobotControlTest::~RobotControlTest()
{
event_processor_.stop();
mission_executor_.stop();
}
void RobotControlTest::run()
{
robot::Rate rate(50);
event_processor_.start();
mission_executor_.start();
while(true)
{
// chạy trong một luồng riêng
auto state = move_base_ptr_->getFeedback()->navigation_state;
bool action_done = true;
//kiểm tra acction done chưa
//thêm kiểm tra navDoneEvent state == robot::move_base_core::State::SUCCEEDED và action_done == true
if(state != prev_state_)
// FIX #1: Set the callback ONCE before starting the executor, not inside the loop.
mission_executor_.setMissionCallback(
[this](const std::shared_ptr<Mission>& mission)
{
if(state ==
robot::move_base_core::State::SUCCEEDED)
{
event_processor_.navDoneEvent();
}
if(state ==
robot::move_base_core::State::ABORTED)
{
event_processor_.navFailedEvent();
}
prev_state_ = state;
}
//nhận oder trong một luồng riêng
//ví dụ: robot_protocol_msgs::Order order;
if(/* có order mới */)
{
robot_protocol_msgs::Order order;
// ... nhận order từ đâu đó, ví dụ qua ROS topic hoặc service
event_processor_.orderEvent(order);
}
mission_executor_.setMissionCallback(
[&](const std::shared_ptr<Mission>& mission)
{
// ví dụ hàm executeMission đã có, nhận mission và đẩy dữ liệu goal sang move_base_ptr_
executeMission(*mission);
});
event_processor_.start();
mission_executor_.start();
while (true)
{
auto feedback = move_base_ptr_->getFeedback();
auto nav_state = feedback->navigation_state;
// FIX #8: navDoneEvent fires only when navigation AND actions are both done.
if (nav_state != prev_nav_state_)
{
if (nav_state == robot::move_base_core::State::SUCCEEDED && areActionsDone())
{
event_processor_.navDoneEvent();
}
else if (nav_state == robot::move_base_core::State::ABORTED)
{
event_processor_.navFailedEvent();
}
prev_nav_state_ = nav_state;
}
// Example: receive an order (replace condition with your real source)
if (/* new order available */ false)
{
robot_protocol_msgs::Order order;
// ... populate order ...
event_processor_.orderEvent(order);
}
rate.sleep();
}
}
}
void RobotControlTest::executeMission(const Mission& mission)
{
// TODO: send mission goal to move_base_ptr_
(void)mission;
}
int main()
{
RobotControlTest test;
test.run();
return 0;
}
}