blob: ed979669bf4aae613b78353eaa9ae0d749dc87cd [file] [log] [blame]
Maxwell Hendersonad312342023-01-10 12:07:47 -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.
6#include "aos/events/logging/log_reader.h"
7#include "aos/events/logging/log_writer.h"
8#include "aos/events/simulated_event_loop.h"
9#include "aos/init.h"
10#include "aos/json_to_flatbuffer.h"
11#include "aos/logging/log_message_generated.h"
12#include "aos/network/team_number.h"
13#include "gflags/gflags.h"
14#include "y2023/constants.h"
15#include "y2023/control_loops/superstructure/superstructure.h"
16
17DEFINE_int32(team, 971, "Team number to use for logfile replay.");
18DEFINE_string(output_folder, "/tmp/superstructure_replay/",
19 "Logs all channels to the provided logfile.");
20
21int main(int argc, char **argv) {
22 aos::InitGoogle(&argc, &argv);
23
24 aos::network::OverrideTeamNumber(FLAGS_team);
25
26 // open logfiles
27 aos::logger::LogReader reader(
28 aos::logger::SortParts(aos::logger::FindLogs(argc, argv)));
29 // TODO(james): Actually enforce not sending on the same buses as the logfile
30 // spews out.
31 reader.RemapLoggedChannel("/superstructure",
32 "y2023.control_loops.superstructure.Status");
33 reader.RemapLoggedChannel("/superstructure",
34 "y2023.control_loops.superstructure.Output");
35
36 aos::SimulatedEventLoopFactory factory(reader.configuration());
37 reader.Register(&factory);
38
39 aos::NodeEventLoopFactory *roborio =
40 factory.GetNodeEventLoopFactory("roborio");
41
42 unlink(FLAGS_output_folder.c_str());
43 std::unique_ptr<aos::EventLoop> logger_event_loop =
44 roborio->MakeEventLoop("logger");
45 auto logger = std::make_unique<aos::logger::Logger>(logger_event_loop.get());
46 logger->StartLoggingOnRun(FLAGS_output_folder);
47
48 roborio->OnStartup([roborio]() {
49 roborio->AlwaysStart<y2023::control_loops::superstructure::Superstructure>(
50 "superstructure", std::make_shared<y2023::constants::Values>(
51 y2023::constants::MakeValues()));
52 });
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 y2023::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}