first update
This commit is contained in:
87
src/robot_control_test.cpp
Normal file
87
src/robot_control_test.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <mission_adapters/mission_adapters.h>
|
||||
#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::MissionExecutor mission_executor_{mission_manager_};
|
||||
std::shared_ptr<Mission> mission_prev_ = nullptr;
|
||||
robot::move_base_core::State prev_state_ = PENDING;
|
||||
|
||||
public:
|
||||
RobotControlTest() = default;
|
||||
~RobotControlTest();
|
||||
void run();
|
||||
};
|
||||
|
||||
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_)
|
||||
{
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
rate.sleep();
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
RobotControlTest test;
|
||||
test.run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user