Loading...
Searching...
No Matches
dipla_worker.cpp
Go to the documentation of this file.
72/** @brief Monotonic time keeps clock synchronization or wall-clock edits from renewing stale data. */
118 Configuration(const std::string& filename, const std::string& default_model, const std::string& default_metadata)
169 throw std::runtime_error("Invalid diplacam configuration: required field, unique known keys, maximum 8192 bytes");
179 ((flight_height_m - flight_height_tolerance_m) * DIPLA_FIELD_EXTENT_M / field_size_m < DIPLA_MODEL_Z_MIN_M ||
180 (flight_height_m + flight_height_tolerance_m) * DIPLA_FIELD_EXTENT_M / field_size_m > DIPLA_MODEL_Z_MAX_M))
181 throw std::runtime_error("Rescaled flight height interval must remain within the model's 10..40 m domain");
203 /** @brief Map a pose into the centred field. @param request Geographic pose. @return XYZ in metres. */
286 bool enqueue(const dipla_request& request, const std::array<double, 3>& position, Clock::time_point received) {
296 observations[(first + count) % observations.size()] = {request, position, received, survey_epoch};
309bool valid_pose(const dipla_request& request, const std::array<double, 3>& position, const Configuration& config) {
315 std::abs(request.agl_q8 / DIPLA_AGL_UNITS_PER_M - config.flight_height_m) <= config.flight_height_tolerance_m;
337void plan(int descriptor, Shared& shared, const Configuration& config, bool cmaes, const CmaesOptions& comparison,
343 if (!cmaes) network = std::make_unique<Network>(config.model, config.metadata, network_options);
344 std::cerr << "diplacam planner=" << (cmaes ? "cmaes comparison_only=true onnx=false" : "diffusion onnx=true") << '\n';
392 if (observation_number == UINT32_MAX) throw std::runtime_error("Observation sequence exhausted");
401 do { sent = send(descriptor, &acknowledgement, sizeof(acknowledgement), MSG_NOSIGNAL | MSG_DONTWAIT); }
403 if (sent != sizeof(acknowledgement)) throw std::runtime_error("Observation acknowledgement failed");
407 << std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - update_started).count() << '\n';
449 if (session == shared.session && survey_epoch == shared.survey_epoch && !shared.stopping && !shared.failed) {
453 if (shared.generation == DIPLA_MAX_GENERATION) throw std::runtime_error("Plan generation exhausted");
459 << " inference_ms=" << std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - inference_started).count() << '\n';
491int serve(int descriptor, const std::string& config_path, const std::string& model, const std::string& metadata,
499 throw std::runtime_error("Resized or nondefault-height worker profiles require the diffusion planner");
503 std::thread worker(plan, descriptor, std::ref(shared), std::cref(config), cmaes, std::cref(comparison),
514 const auto admit = [&](const dipla_request& request, const std::array<double, 3>& position, Clock::time_point received) {
520 << " field_size_m=" << config.field_size_m << " field_rotation_deg=" << config.field_rotation_deg
577 if (request.operation == DIPLA_IPC_PLAN && request.session == shared.session && request.number) {
595 if (shared.generation && now - shared.plan_time <= std::chrono::milliseconds(DIPLA_POINT_MAX_AGE_MS)) {
617 reply.points[index].height_mm = static_cast<int32_t>(std::llround(config.flight_height_m * DIPLA_MM_PER_M));
630 do { sent = send(descriptor, &reply, sizeof(reply), MSG_NOSIGNAL | MSG_DONTWAIT); } while (sent < 0 && errno == EINTR);
648 if (shared.failed || now - pinned_time > std::chrono::milliseconds(DIPLA_POINT_MAX_AGE_MS)) reply.valid = 0;
655 if (!slot && shared.generation && now - shared.plan_time <= std::chrono::milliseconds(DIPLA_POINT_MAX_AGE_MS)) {
663 if (!shared.failed && generation && now - pinned_time <= std::chrono::milliseconds(DIPLA_POINT_MAX_AGE_MS)) {
695 do { sent = send(descriptor, &reply, sizeof(reply), MSG_NOSIGNAL | MSG_DONTWAIT); } while (sent < 0 && errno == EINTR);
700 do { sent = send(descriptor, &acknowledgement, sizeof(acknowledgement), MSG_NOSIGNAL | MSG_DONTWAIT); }
Allocation-free flat key=value mechanics; callers own schemas and storage.
static bool ini_uint(const char *text, uint64_t *number)
Parse digits-only uint64; overflow and signs are rejected.
Definition bounded_ini.h:52
static bool ini_real(const char *text, double *number)
Parse finite decimal/exponent notation, rejecting range errors and suffixes.
Definition bounded_ini.h:67
static bool ini_read_file(const char *filename, char *buffer, size_t capacity, size_t *length)
Read a nonempty regular file smaller than capacity and append NUL.
Definition bounded_ini.h:98
static bool ini_parse(char *buffer, size_t length, ini_field_handler handler, void *context)
Destructively parse flat fields with blank lines and #/; comment lines.
Definition bounded_ini.h:132
Private local worker messages; not a flight-controller wire protocol.
Public planning, synthetic-survey, and comparison APIs for Diplacam.
Public entry point for Diplacam's bounded local IPC worker.
std::vector< Point > plan(const Grid &grid, const Vector &mean, const Matrix &covariance, const Point &start, const PlannerOptions &options)
Run greedy route selection followed by optional CMA-ES refinement.
Definition cmaes_optimizer.cpp:114
Definition aigenlib.cpp:42
void apply_flight_margin(Waypoints &route, unsigned margin_cells)
Apply the configured horizontal flight margin.
Definition dipla_planner.cpp:599
int serve(int descriptor, const std::string &config_path, const std::string &model, const std::string &metadata, bool cmaes, const CmaesOptions &comparison, const NetworkOptions &network_options, const ExperimentOptions &experiment)
Serve a Diplacam session over an already-connected IPC descriptor.
Definition dipla_worker.cpp:491
std::array< double, DIPLA_COORDINATE_COUNT *points > Noise
Definition dipla_planner.hpp:48
std::array< std::array< double, DIPLA_COORDINATE_COUNT >, points > Waypoints
Definition dipla_planner.hpp:50
constexpr unsigned int sensor_height
Sensor-space height, separate from model and encoded-image dimensions.
Definition spotter_cam.cpp:58
Bounded parameters for the comparison-only CMA-ES planner.
Definition dipla_planner.hpp:117
void validate() const
Validate the complete comparison policy before planning.
Definition dipla_planner.cpp:585
Startup-only synthetic experiment settings shared by both planners.
Definition dipla_planner.hpp:53
void validate() const
Reject nonfinite values and incompatible margins before allocation.
Definition dipla_planner.cpp:576
Model identity and execution limits for a diffusion network.
Definition dipla_planner.hpp:144
int32_t east_mm
Flight-padded model X times 1000; default bounds 4000..96000.
Definition dipla_ipc.h:104
int32_t north_mm
Flight-padded model Y times 1000; default bounds 4000..96000.
Definition dipla_ipc.h:104
Complete immutable route reply on the local worker socket, not the FC bus.
Definition dipla_ipc.h:81
uint32_t generation
Monotonically increasing completed-route identity within this session.
Definition dipla_ipc.h:94
struct dipla_plan_reply::dipla_plan_point points[DIPLA_WAYPOINT_COUNT]
uint32_t valid
One only for an entire fresh, bounded route; zero authorizes no points.
Definition dipla_ipc.h:94
uint32_t age_ms
Milliseconds since the latest assimilated active-chunk pose was received.
Definition dipla_ipc.h:94
uint32_t number
Exact request echo; route data may originate from an earlier admitted pose.
Definition dipla_ipc.h:94
Legacy one-point retrieval from a generation pinned across eight slots.
Definition dipla_ipc.h:59
uint32_t number
Exact observation echo; a retry must not consume another slot.
Definition dipla_ipc.h:66
int32_t agl_mm
Configured physical flight height in millimetres; default 2000.
Definition dipla_ipc.h:75
int32_t alt_mm
Unchanged owner-supplied FC altitude in millimetres, not predicted model Z.
Definition dipla_ipc.h:75
uint32_t session
Exact session echo; prevents accepting a previous sortie's completion.
Definition dipla_ipc.h:66
Pose/control request; session and observation number have separate lifetimes.
Definition dipla_ipc.h:42
One timestamped geographic position for a replay annotation.
Definition ear_heatmap_overlay.c:79