This commit is contained in:
@@ -63,6 +63,10 @@ void RobotRuntime::ensureDefaultsUnlocked()
|
||||
state_["cmd_angular"] = 0.0;
|
||||
if (!state_.contains("updated_at"))
|
||||
state_["updated_at"] = IdUtil::nowIso8601();
|
||||
if (!state_.contains("active_map_id"))
|
||||
state_["active_map_id"] = nullptr;
|
||||
if (!state_.contains("pose") || !state_["pose"].is_object())
|
||||
state_["pose"] = {{"x", 0.0}, {"y", 0.0}, {"yaw", 0.0}};
|
||||
saveUnlocked();
|
||||
}
|
||||
|
||||
@@ -104,6 +108,8 @@ nlohmann::json RobotRuntime::buildStatusUnlocked() const
|
||||
{"joystick_speed", state_.value("joystick_speed", "fast")},
|
||||
{"cmd_linear", state_.value("cmd_linear", 0.0)},
|
||||
{"cmd_angular", state_.value("cmd_angular", 0.0)},
|
||||
{"active_map_id", state_.contains("active_map_id") ? state_["active_map_id"] : nullptr},
|
||||
{"pose", state_.contains("pose") ? state_["pose"] : nlohmann::json::object({{"x", 0.0}, {"y", 0.0}, {"yaw", 0.0}})},
|
||||
{"runner", runner},
|
||||
{"queue_pending", pending},
|
||||
{"updated_at", state_.value("updated_at", "")}};
|
||||
@@ -235,6 +241,27 @@ bool RobotRuntime::setJoystick(bool engaged, const std::string& speed, std::stri
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RobotRuntime::setActiveMap(const std::string& map_id, std::string& err)
|
||||
{
|
||||
(void)err;
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
state_["active_map_id"] = map_id;
|
||||
state_["updated_at"] = IdUtil::nowIso8601();
|
||||
saveUnlocked();
|
||||
return true;
|
||||
}
|
||||
|
||||
void RobotRuntime::clearActiveMapIf(const std::string& map_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
if (state_.value("active_map_id", "") == map_id)
|
||||
{
|
||||
state_["active_map_id"] = nullptr;
|
||||
state_["updated_at"] = IdUtil::nowIso8601();
|
||||
saveUnlocked();
|
||||
}
|
||||
}
|
||||
|
||||
void RobotRuntime::tick()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
|
||||
Reference in New Issue
Block a user