blob: 859b77efcc0de682ea61138299ebe978c03f505b [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001#include "gflags/gflags.h"
2
James Kuszmaul6e0d8652023-03-12 14:02:26 -07003#include "aos/configuration.h"
4#include "aos/events/logging/log_reader.h"
5#include "aos/events/logging/log_writer.h"
6#include "aos/events/simulated_event_loop.h"
7#include "aos/init.h"
8#include "aos/json_to_flatbuffer.h"
9#include "aos/network/team_number.h"
James Kuszmaule4853542023-05-15 20:35:48 -070010#include "aos/util/simulation_logger.h"
James Kuszmaul6e0d8652023-03-12 14:02:26 -070011#include "y2023/control_loops/drivetrain/drivetrain_base.h"
James Kuszmaule4853542023-05-15 20:35:48 -070012#include "y2023/localizer/localizer.h"
James Kuszmaul6e0d8652023-03-12 14:02:26 -070013
14DEFINE_string(config, "y2023/aos_config.json",
15 "Name of the config file to replay using.");
16DEFINE_int32(team, 9971, "Team number to use for logfile replay.");
17DEFINE_string(output_folder, "/tmp/replayed",
18 "Name of the folder to write replayed logs to.");
19
James Kuszmaul6e0d8652023-03-12 14:02:26 -070020int main(int argc, char **argv) {
21 aos::InitGoogle(&argc, &argv);
22
23 aos::network::OverrideTeamNumber(FLAGS_team);
24
25 const aos::FlatbufferDetachedBuffer<aos::Configuration> config =
26 aos::configuration::ReadConfig(FLAGS_config);
27
James Kuszmaul6e0d8652023-03-12 14:02:26 -070028 // sort logfiles
29 const std::vector<aos::logger::LogFile> logfiles =
Austin Schuhc1609732023-06-26 11:51:28 -070030 aos::logger::SortParts(aos::logger::FindLogs(argc, argv));
James Kuszmaul6e0d8652023-03-12 14:02:26 -070031
32 // open logfiles
33 aos::logger::LogReader reader(logfiles, &config.message());
34
Philipp Schrader790cb542023-07-05 21:06:52 -070035 reader.RemapLoggedChannel("/localizer", "y2023.localizer.Status");
James Kuszmaul6e0d8652023-03-12 14:02:26 -070036 for (const auto pi : {"pi1", "pi2", "pi3", "pi4"}) {
37 reader.RemapLoggedChannel(absl::StrCat("/", pi, "/camera"),
38 "y2023.localizer.Visualization");
39 }
Philipp Schrader790cb542023-07-05 21:06:52 -070040 reader.RemapLoggedChannel("/localizer", "frc971.controls.LocalizerOutput");
James Kuszmaul6e0d8652023-03-12 14:02:26 -070041
42 auto factory =
43 std::make_unique<aos::SimulatedEventLoopFactory>(reader.configuration());
44
45 reader.Register(factory.get());
46
James Kuszmaul6e0d8652023-03-12 14:02:26 -070047 // List of nodes to create loggers for (note: currently just roborio; this
48 // code was refactored to allow easily adding new loggers to accommodate
49 // debugging and potential future changes).
50 const std::vector<std::string> nodes_to_log = {"imu"};
James Kuszmaule4853542023-05-15 20:35:48 -070051 std::vector<std::unique_ptr<aos::util::LoggerState>> loggers =
52 aos::util::MakeLoggersForNodes(reader.event_loop_factory(), nodes_to_log,
53 FLAGS_output_folder);
James Kuszmaul6e0d8652023-03-12 14:02:26 -070054
55 const aos::Node *node = nullptr;
56 if (aos::configuration::MultiNode(reader.configuration())) {
57 node = aos::configuration::GetNode(reader.configuration(), "imu");
58 }
59
60 std::unique_ptr<aos::EventLoop> localizer_event_loop =
61 reader.event_loop_factory()->MakeEventLoop("localizer", node);
62 localizer_event_loop->SkipTimingReport();
63
64 y2023::localizer::Localizer localizer(
65 localizer_event_loop.get(),
66 y2023::control_loops::drivetrain::GetDrivetrainConfig());
67
68 reader.event_loop_factory()->Run();
69
70 reader.Deregister();
71
72 return 0;
73}