Merge pull request 'Fix SEER AGV live map streaming and stop mapping' (#1) from codex/agv-live-map-debug into dev
Reviewed-on: http://192.168.28.10:18088/SmartBench/cmvr-es/pulls/1
This commit is contained in:
commit
acac902aff
@ -20,7 +20,7 @@ agv {
|
||||
port_push: 19301
|
||||
recv_timeout_ms: 1000
|
||||
control_nick_name: "cmvr-es"
|
||||
enable_state_push: true
|
||||
enable_state_push: false
|
||||
state_push_interval_ms: 200
|
||||
state_push_included_fields: "x"
|
||||
state_push_included_fields: "y"
|
||||
|
||||
@ -147,7 +147,7 @@ device_manager {
|
||||
id: "src1100"
|
||||
type: DEVICE_TYPE_AGV
|
||||
config_file: "devices/agv/agv.pb.txt"
|
||||
enable: false
|
||||
enable: true
|
||||
}
|
||||
|
||||
devices {
|
||||
|
||||
@ -5,7 +5,7 @@ task_manager {
|
||||
run_mode: TASK_RUN_MODE_PERIODIC_STEP
|
||||
control_period_s: 0.001
|
||||
config_file: "tasks/touch_screen_task/touch_screen_task.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
tasks {
|
||||
id: "grpc_server"
|
||||
@ -27,6 +27,6 @@ task_manager {
|
||||
type: TASK_TYPE_QUIC_EDGE
|
||||
run_mode: TASK_RUN_MODE_BLOCKING_SERVICE
|
||||
config_file: "tasks/quic_edge_task/quic_edge_task.pb.txt"
|
||||
enable: true
|
||||
enable: false
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
grpc_server {
|
||||
id: "grpc_server"
|
||||
host: "0.0.0.0"
|
||||
port: "50052"
|
||||
port: "50053"
|
||||
enable_reflection: true
|
||||
}
|
||||
|
||||
@ -31,6 +31,9 @@ constexpr std::uint16_t kRobotConfigUploadMap = 4010;
|
||||
constexpr std::uint16_t kRobotConfigDownloadMap = 4011;
|
||||
constexpr std::uint16_t kRobotOtherStartMapping = 6100;
|
||||
constexpr std::uint16_t kRobotOtherStopMapping = 6101;
|
||||
// The controller can emit this asynchronous mapping event on port 19210
|
||||
// while a mapping session is active. It is not the reply to the next command.
|
||||
constexpr std::uint16_t kRobotOtherMappingEventResponse = 17002;
|
||||
constexpr std::uint16_t kRobotPushConfigReq = 9300;
|
||||
constexpr std::uint16_t kRobotPushConfigRes = 19300;
|
||||
constexpr std::uint16_t kRobotPush = 19301;
|
||||
|
||||
@ -33,7 +33,31 @@ static inline const Json::Value* jsonFind(
|
||||
const Json::Value& value,
|
||||
const char* key)
|
||||
{
|
||||
return value.find(key, key + std::strlen(key));
|
||||
const auto* exact = value.find(key, key + std::strlen(key));
|
||||
if (exact) {
|
||||
return exact;
|
||||
}
|
||||
|
||||
std::string lower_camel;
|
||||
lower_camel.reserve(std::strlen(key));
|
||||
bool uppercase_next = false;
|
||||
for (const char* current = key; *current != '\0'; ++current) {
|
||||
if (*current == '_') {
|
||||
uppercase_next = true;
|
||||
continue;
|
||||
}
|
||||
char character = *current;
|
||||
if (uppercase_next && character >= 'a' && character <= 'z') {
|
||||
character = static_cast<char>(character - 'a' + 'A');
|
||||
}
|
||||
lower_camel.push_back(character);
|
||||
uppercase_next = false;
|
||||
}
|
||||
if (lower_camel == key) {
|
||||
return nullptr;
|
||||
}
|
||||
return value.find(lower_camel.data(),
|
||||
lower_camel.data() + lower_camel.size());
|
||||
}
|
||||
|
||||
static inline Json::Value jsonGet(
|
||||
|
||||
@ -715,6 +715,28 @@ AgvResult SeerRobokitAgv::parseSeerRobokitMap2D_(
|
||||
}
|
||||
}
|
||||
|
||||
const auto* occupied_points = jsonFind(root, "normal_pos_list");
|
||||
if (occupied_points && occupied_points->isArray()
|
||||
&& map.resolution > 0.0 && map.width > 0 && map.height > 0) {
|
||||
const auto cell_count = static_cast<std::size_t>(map.width) * map.height;
|
||||
map.data.assign(cell_count, 0);
|
||||
for (const auto& point : *occupied_points) {
|
||||
const auto grid_x = static_cast<int>(std::floor(
|
||||
(jsonGet(point, "x", 0.0).asDouble() - map.origin.x)
|
||||
/ map.resolution));
|
||||
const auto grid_y = static_cast<int>(std::floor(
|
||||
(jsonGet(point, "y", 0.0).asDouble() - map.origin.y)
|
||||
/ map.resolution));
|
||||
if (grid_x >= 0 && grid_y >= 0
|
||||
&& grid_x < static_cast<int>(map.width)
|
||||
&& grid_y < static_cast<int>(map.height)) {
|
||||
const auto index = static_cast<std::size_t>(grid_y) * map.width
|
||||
+ static_cast<std::size_t>(grid_x);
|
||||
map.data[index] = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto make_id = [](const Json::Value& value, const char* prefix, const int index) {
|
||||
std::string id = jsonGet(value, "instance_name", "").asString();
|
||||
if (id.empty()) id = jsonGet(value, "id", "").asString();
|
||||
@ -861,6 +883,17 @@ AgvResult SeerRobokitAgv::parseSeerRobokitMap2D_(
|
||||
if (map_id.empty()) map_id = jsonGet(header, "map_name", "").asString();
|
||||
if (map_id.empty()) map_id = file_name;
|
||||
|
||||
if (map.resolution <= 0.0 || map.width == 0 || map.height == 0) {
|
||||
return AgvResult::failure(
|
||||
AgvErrorCode::CommandFailed,
|
||||
"SEER Robokit 2D map has invalid resolution or bounds: " + file_name);
|
||||
}
|
||||
if (map.data.empty() && map.objects.empty()) {
|
||||
return AgvResult::failure(
|
||||
AgvErrorCode::CommandFailed,
|
||||
"SEER Robokit 2D map has no renderable data: " + file_name);
|
||||
}
|
||||
|
||||
update = {};
|
||||
update.map_id = map_id;
|
||||
update.dimension = AgvMapDimension::Map2D;
|
||||
|
||||
@ -133,25 +133,40 @@ AgvResult SeerRobokitAgv::sendCommandRaw_(
|
||||
"SEER Robokit send command failed: " + systemError());
|
||||
}
|
||||
|
||||
std::uint16_t response_command = 0;
|
||||
std::string payload_text_response;
|
||||
const auto result = receiveFrame_(sock, response_command, payload_text_response);
|
||||
if (!result.ok()) {
|
||||
return result;
|
||||
}
|
||||
const auto expected_response_command = static_cast<std::uint16_t>(
|
||||
command + 10000U);
|
||||
if (response_command != expected_response_command) {
|
||||
return AgvResult::failure(
|
||||
AgvErrorCode::CommandFailed,
|
||||
"SEER Robokit response command mismatch: expected="
|
||||
+ std::to_string(expected_response_command)
|
||||
+ ", actual=" + std::to_string(response_command));
|
||||
constexpr int kMaximumSkippedMappingEvents = 16;
|
||||
for (int attempt = 0; attempt <= kMaximumSkippedMappingEvents; ++attempt) {
|
||||
std::uint16_t response_command = 0;
|
||||
std::string payload_text_response;
|
||||
const auto result = receiveFrame_(
|
||||
sock, response_command, payload_text_response);
|
||||
if (!result.ok()) {
|
||||
return result;
|
||||
}
|
||||
if (response_command == expected_response_command) {
|
||||
if (response_payload) {
|
||||
*response_payload = std::move(payload_text_response);
|
||||
}
|
||||
return AgvResult::success();
|
||||
}
|
||||
|
||||
const bool is_mapping_event =
|
||||
sock == sock_other_
|
||||
&& response_command == kRobotOtherMappingEventResponse;
|
||||
if (!is_mapping_event) {
|
||||
return AgvResult::failure(
|
||||
AgvErrorCode::CommandFailed,
|
||||
"SEER Robokit response command mismatch: expected="
|
||||
+ std::to_string(expected_response_command)
|
||||
+ ", actual=" + std::to_string(response_command));
|
||||
}
|
||||
}
|
||||
if (response_payload) {
|
||||
*response_payload = std::move(payload_text_response);
|
||||
}
|
||||
return AgvResult::success();
|
||||
return AgvResult::failure(
|
||||
AgvErrorCode::Timeout,
|
||||
"SEER Robokit timed out waiting for response command "
|
||||
+ std::to_string(expected_response_command)
|
||||
+ " after repeated asynchronous mapping events");
|
||||
};
|
||||
const auto close_matching_socket_locked = [this, sock]() {
|
||||
if (sock == sock_status_) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user