Files
crosstyan 1005e50be0 feat(track-core): add portable training runtimes
Move scheme and PID training runtime behavior into the pure track_core layer and expose render sinks for injected strip application.

Add ESP compatibility adapters, Python bindings/test scaffolding, and in-memory render support so app_track_bt can consume core render and runtime logic without duplicating it.

Cover circular/linear rendering boundaries, all scheme runtime types, scheme render_to parity, PID sample de-duplication, speed suppression, and live tuning in track-core tests.
2026-05-18 16:15:45 +08:00

109 lines
2.5 KiB
C++

#pragma once
#include <cstddef>
#include <vector>
#include "track_core/model.hpp"
#include "track_core/render.hpp"
#include "track_core/scheme_decoder.hpp"
namespace track_core {
struct SchemeTrackState {
bool is_running{};
std::size_t primary_segment_index{};
std::size_t sub_segment_index{};
float mileage_m{};
float loop_mileage_m{};
float speed_m_s{};
float elapsed_s{};
};
struct SchemeTrackRuntime {
DecodedScheme scheme;
SchemeTrackState state;
};
[[nodiscard]]
DecodedScheme make_speed_mileage_scheme(
std::uint8_t id,
Color color,
AccelerationProfile acceleration_profile,
std::vector<SMSegment> segments);
[[nodiscard]]
DecodedScheme make_mileage_time_scheme(
std::uint8_t id,
Color color,
AccelerationProfile acceleration_profile,
std::vector<MTSegment> segments);
[[nodiscard]]
DecodedScheme make_speed_time_scheme(
std::uint8_t id,
Color color,
AccelerationProfile acceleration_profile,
std::vector<STSegment> segments);
[[nodiscard]]
DecodedScheme make_repeated_speed_mileage_time_scheme(
std::uint8_t id,
Color color,
AccelerationProfile acceleration_profile,
std::vector<RepeatedSMSegment> segments);
[[nodiscard]]
expected<SchemeTrackRuntime, TrackError> make_scheme_track_runtime(DecodedScheme scheme);
[[nodiscard]]
SchemeTrackRuntime start_scheme_track(SchemeTrackRuntime runtime);
[[nodiscard]]
SchemeTrackRuntime stop_scheme_track(SchemeTrackRuntime runtime);
[[nodiscard]]
SchemeTrackRuntime tick_scheme_track(
const TrackConfig &config,
SchemeTrackRuntime runtime,
float delta_s);
[[nodiscard]]
TrackInfo scheme_track_info(const SchemeTrackRuntime &runtime);
[[nodiscard]]
TrackReport scheme_track_report(const SchemeTrackRuntime &runtime);
class SchemeTrainingRuntime {
public:
[[nodiscard]]
bool has_program() const noexcept;
[[nodiscard]]
bool all_stopped() const noexcept;
[[nodiscard]]
expected<unit, TrackError> add_scheme(DecodedScheme scheme);
void clear();
void start();
void stop();
void tick(const TrackConfig &config, float delta_s);
[[nodiscard]]
TrackStateReportCollection state_collection() const;
[[nodiscard]]
TrackSchemeMgrRead scheme_status() const;
[[nodiscard]]
expected<unit, TrackError> render_to(const TrackConfig &config, TrackRenderSink sink) const;
[[nodiscard]]
expected<std::vector<Color>, TrackError> render_pixels(const TrackConfig &config) const;
private:
std::vector<SchemeTrackRuntime> tracks_;
};
} // namespace track_core