blob: 37ab08f9d1431c4f23536bb5f9c737a0ea35074f [file] [log] [blame]
Niko Sohmers3860f8a2024-01-12 21:05:19 -08001// This binary allows us to replay the superstructure code over existing
2// logfile. When you run this code, it generates a new logfile with the data all
3// replayed, so that it can then be run through the plotting tool or analyzed
4// in some other way. The original superstructure status data will be on the
5// /original/superstructure channel.
Austin Schuh99f7c6a2024-06-25 22:07:44 -07006#include "absl/flags/flag.h"
Niko Sohmers3860f8a2024-01-12 21:05:19 -08007
8#include "aos/events/logging/log_reader.h"
9#include "aos/events/logging/log_writer.h"
10#include "aos/events/simulated_event_loop.h"
11#include "aos/init.h"
12#include "aos/json_to_flatbuffer.h"
13#include "aos/logging/log_message_generated.h"
14#include "aos/network/team_number.h"
15#include "y2024/constants.h"
16#include "y2024/control_loops/superstructure/superstructure.h"
17
Austin Schuh99f7c6a2024-06-25 22:07:44 -070018ABSL_FLAG(int32_t, team, 971, "Team number to use for logfile replay.");
19ABSL_FLAG(std::string, output_folder, "/tmp/superstructure_replay/",
20 "Logs all channels to the provided logfile.");
Niko Sohmers3860f8a2024-01-12 21:05:19 -080021
22int main(int argc, char **argv) {
23 aos::InitGoogle(&argc, &argv);
24
Austin Schuh99f7c6a2024-06-25 22:07:44 -070025 aos::network::OverrideTeamNumber(absl::GetFlag(FLAGS_team));
Niko Sohmers3860f8a2024-01-12 21:05:19 -080026
27 // open logfiles
28 aos::logger::LogReader reader(
29 aos::logger::SortParts(aos::logger::FindLogs(argc, argv)));
30 // TODO(james): Actually enforce not sending on the same buses as the logfile
31 // spews out.
32 reader.RemapLoggedChannel("/superstructure",
33 "y2024.control_loops.superstructure.Status");
34 reader.RemapLoggedChannel("/superstructure",
35 "y2024.control_loops.superstructure.Output");
36
37 aos::SimulatedEventLoopFactory factory(reader.configuration());
38 reader.Register(&factory);
39
40 aos::NodeEventLoopFactory *roborio =
41 factory.GetNodeEventLoopFactory("roborio");
42
Austin Schuh99f7c6a2024-06-25 22:07:44 -070043 unlink(absl::GetFlag(FLAGS_output_folder).c_str());
Niko Sohmers3860f8a2024-01-12 21:05:19 -080044 std::unique_ptr<aos::EventLoop> logger_event_loop =
45 roborio->MakeEventLoop("logger");
46 auto logger = std::make_unique<aos::logger::Logger>(logger_event_loop.get());
Austin Schuh99f7c6a2024-06-25 22:07:44 -070047 logger->StartLoggingOnRun(absl::GetFlag(FLAGS_output_folder));
Niko Sohmers3860f8a2024-01-12 21:05:19 -080048
49 roborio->OnStartup([roborio]() {
50 roborio->AlwaysStart<y2024::control_loops::superstructure::Superstructure>(
Filip Kujawa7a799602024-02-23 12:27:47 -080051 "superstructure");
Niko Sohmers3860f8a2024-01-12 21:05:19 -080052 });
53
54 std::unique_ptr<aos::EventLoop> print_loop = roborio->MakeEventLoop("print");
55 print_loop->SkipAosLog();
56 print_loop->MakeWatcher(
57 "/aos", [&print_loop](const aos::logging::LogMessageFbs &msg) {
58 LOG(INFO) << print_loop->context().monotonic_event_time << " "
59 << aos::FlatbufferToJson(&msg);
60 });
61 print_loop->MakeWatcher(
62 "/superstructure",
63 [&](const y2024::control_loops::superstructure::Status &status) {
64 if (status.estopped()) {
65 LOG(ERROR) << "Estopped";
66 }
67 });
68
69 factory.Run();
70
71 reader.Deregister();
72
73 return 0;
74}