change file readme
This commit is contained in:
@@ -19,11 +19,12 @@ namespace mission_adapters
|
||||
// ── Priority constants ────────────────────────────────────────────────────
|
||||
// Số càng nhỏ = ưu tiên càng cao (min-heap)
|
||||
static constexpr int PRIORITY_EMERGENCY = 0;
|
||||
static constexpr int PRIORITY_CANCEL = 1; // resume > pause
|
||||
static constexpr int PRIORITY_CANCEL = 1;
|
||||
static constexpr int PRIORITY_RESUME = 2;
|
||||
static constexpr int PRIORITY_PAUSE = 3;
|
||||
static constexpr int PRIORITY_NAV_DONE = 4;
|
||||
static constexpr int PRIORITY_ACT_DONE = 4;
|
||||
// FIX #4: Dedicated constant — same value as NAV_DONE but semantically correct name.
|
||||
static constexpr int PRIORITY_NAV_FAILED = 4;
|
||||
static constexpr int PRIORITY_ORDER = 5;
|
||||
|
||||
enum class MissionState
|
||||
@@ -66,7 +67,7 @@ namespace mission_adapters
|
||||
class Action
|
||||
{
|
||||
public:
|
||||
int sequenceId; //id này theo id của action trong node hoặc edge, để đảm bảo thứ tự thực hiện
|
||||
int sequenceId;
|
||||
ActionType type;
|
||||
robot_protocol_msgs::Action action;
|
||||
};
|
||||
@@ -75,28 +76,19 @@ namespace mission_adapters
|
||||
{
|
||||
public:
|
||||
int sequenceId;
|
||||
|
||||
MissionType type;
|
||||
|
||||
int priority;
|
||||
|
||||
robot_geometry_msgs::PoseStamped start;
|
||||
|
||||
robot_geometry_msgs::PoseStamped goal;
|
||||
|
||||
std::vector<robot_protocol_msgs::Node> nodes;
|
||||
|
||||
std::vector<robot_protocol_msgs::Edge> edges;
|
||||
|
||||
std::vector<Action> actions;
|
||||
};
|
||||
|
||||
struct Event
|
||||
{
|
||||
EventType type;
|
||||
|
||||
int priority;
|
||||
|
||||
std::vector<std::shared_ptr<Mission>> missions;
|
||||
};
|
||||
|
||||
@@ -112,36 +104,26 @@ namespace mission_adapters
|
||||
{
|
||||
private:
|
||||
mutable std::mutex mutex_;
|
||||
|
||||
std::priority_queue<Event, std::vector<Event>, EventCompare> queue_;
|
||||
std::condition_variable cv_;
|
||||
|
||||
bool stop_ = false;
|
||||
|
||||
public:
|
||||
void push(const Event& event);
|
||||
|
||||
bool pop(Event& event);
|
||||
|
||||
void stop();
|
||||
|
||||
void reset();
|
||||
|
||||
inline bool empty() const
|
||||
{
|
||||
inline bool empty() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
return queue_.empty();
|
||||
return queue_.empty();
|
||||
}
|
||||
|
||||
inline void clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
while(!queue_.empty())
|
||||
{
|
||||
queue_.pop();
|
||||
}
|
||||
while (!queue_.empty()) queue_.pop();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,35 +142,26 @@ namespace mission_adapters
|
||||
class MissionManager
|
||||
{
|
||||
public:
|
||||
|
||||
void submit(const std::vector<std::shared_ptr<Mission>>& missions);
|
||||
|
||||
std::shared_ptr<Mission> nextMission();
|
||||
|
||||
void onNavigationDone();
|
||||
|
||||
void onNavigationFailed();
|
||||
|
||||
void cancel();
|
||||
|
||||
void pause();
|
||||
|
||||
void resume();
|
||||
|
||||
void emergency();
|
||||
|
||||
MissionState state() const;
|
||||
|
||||
// FIX #3: Returns true if there is any pending work — queue OR active mission.
|
||||
bool hasMission() const;
|
||||
|
||||
private:
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
|
||||
MissionState state_ = MissionState::IDLE;
|
||||
|
||||
std::queue<std::shared_ptr<Mission>> mission_queue_;
|
||||
|
||||
std::shared_ptr<Mission> current_mission_;
|
||||
};
|
||||
|
||||
@@ -196,53 +169,37 @@ namespace mission_adapters
|
||||
{
|
||||
public:
|
||||
explicit EventProcessor(MissionManager& mission_manager);
|
||||
|
||||
~EventProcessor();
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
void goalEvent(const robot_geometry_msgs::PoseStamped& goal);
|
||||
|
||||
void orderEvent(const robot_protocol_msgs::Order& order);
|
||||
|
||||
void cancelEvent();
|
||||
|
||||
void pauseEvent();
|
||||
|
||||
void resumeEvent();
|
||||
|
||||
void navDoneEvent();
|
||||
|
||||
void navFailedEvent();
|
||||
|
||||
void emergencyEvent();
|
||||
|
||||
private:
|
||||
void spin();
|
||||
|
||||
void process(const Event& event);
|
||||
|
||||
private:
|
||||
EventBus event_bus_;
|
||||
|
||||
GoalAdapter goal_adapter_;
|
||||
|
||||
VDA5050Adapter vda5050_adapter_;
|
||||
|
||||
MissionManager& mission_manager_;
|
||||
|
||||
std::thread worker_;
|
||||
|
||||
std::atomic<bool> running_{false};
|
||||
};
|
||||
|
||||
|
||||
class MissionExecutor
|
||||
{
|
||||
public:
|
||||
using MissionCallback =
|
||||
std::function<void(const std::shared_ptr<Mission>&)>;
|
||||
using MissionCallback = std::function<void(const std::shared_ptr<Mission>&)>;
|
||||
|
||||
explicit MissionExecutor(MissionManager& manager);
|
||||
~MissionExecutor();
|
||||
@@ -250,6 +207,7 @@ namespace mission_adapters
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
// FIX #1: Must be called BEFORE start(), not inside the run loop.
|
||||
void setMissionCallback(MissionCallback cb)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -257,23 +215,20 @@ namespace mission_adapters
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Mission> mission_excute_;
|
||||
std::shared_ptr<Mission> mission_execute_;
|
||||
|
||||
// Mission cuối cùng đã dispatch
|
||||
// Last mission that was dispatched to the callback.
|
||||
std::shared_ptr<Mission> last_dispatched_mission_;
|
||||
|
||||
MissionCallback mission_callback_;
|
||||
|
||||
MissionManager& mission_manager_;
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
|
||||
std::thread worker_;
|
||||
|
||||
std::atomic<bool> running_{false};
|
||||
|
||||
void spin();
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace mission_adapters
|
||||
|
||||
#endif // MISSION_ADAPTERS_MISSION_ADAPTERS_H
|
||||
Reference in New Issue
Block a user