blob: d7f03e67efe5e3190b9acbe76b81a92654f3bee0 [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001// 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
Milind Upadhyay9d68b132022-04-01 10:58:18 -07003// 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.
Philipp Schrader790cb542023-07-05 21:06:52 -07006#include "gflags/gflags.h"
7
Milind Upadhyay9d68b132022-04-01 10:58:18 -07008#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"
Milind Upadhyay9d68b132022-04-01 10:58:18 -070015#include "y2022/constants.h"
16#include "y2022/control_loops/superstructure/superstructure.h"
17
18DEFINE_int32(team, 971, "Team number to use for logfile replay.");
19DEFINE_string(output_folder, "/tmp/superstructure_replay/",
20 "Logs all channels to the provided logfile.");
21
22int main(int argc, char **argv) {
23 aos::InitGoogle(&argc, &argv);
24
25 aos::network::OverrideTeamNumber(FLAGS_team);
26
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 "y2022.control_loops.superstructure.Status");
34 reader.RemapLoggedChannel("/superstructure",
35 "y2022.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
43 unlink(FLAGS_output_folder.c_str());
44 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());
47 logger->StartLoggingOnRun(FLAGS_output_folder);
48
49 roborio->OnStartup([roborio]() {
50 roborio->AlwaysStart<y2022::control_loops::superstructure::Superstructure>(
51 "superstructure", std::make_shared<y2022::constants::Values>(
52 y2022::constants::MakeValues()));
53 });
54
55 std::unique_ptr<aos::EventLoop> print_loop = roborio->MakeEventLoop("print");
56 print_loop->SkipAosLog();
57 print_loop->MakeWatcher(
58 "/aos", [&print_loop](const aos::logging::LogMessageFbs &msg) {
59 LOG(INFO) << print_loop->context().monotonic_event_time << " "
60 << aos::FlatbufferToJson(&msg);
61 });
62 print_loop->MakeWatcher(
63 "/superstructure",
64 [&](const y2022::control_loops::superstructure::Status &status) {
65 if (status.estopped()) {
66 LOG(ERROR) << "Estopped";
67 }
68 });
69
70 factory.Run();
71
72 reader.Deregister();
73
74 return 0;
75}