blob: 97b4c2b0bbbd01af59ea3f297f923f9fd184b626 [file] [log] [blame]
James Kuszmaul314f1672020-01-03 20:02:08 -08001#include <iostream>
2
3#include "aos/configuration.h"
Austin Schuhb06f03b2021-02-17 22:00:37 -08004#include "aos/events/logging/log_writer.h"
5#include "aos/events/logging/log_reader.h"
James Kuszmaul314f1672020-01-03 20:02:08 -08006#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"
10#include "frc971/control_loops/drivetrain/drivetrain.h"
11#include "gflags/gflags.h"
12#include "y2019/control_loops/drivetrain/drivetrain_base.h"
13#include "y2019/control_loops/drivetrain/event_loop_localizer.h"
14
15DEFINE_string(logfile, "/tmp/logfile.bfbs",
16 "Name of the logfile to read from.");
17DEFINE_string(config, "y2019/config.json",
18 "Name of the config file to replay using.");
Austin Schuh2f8fd752020-09-01 22:38:28 -070019DEFINE_string(output_file, "/tmp/replayed",
James Kuszmaul314f1672020-01-03 20:02:08 -080020 "Name of the logfile to write replayed data to.");
21DEFINE_int32(team, 971, "Team number to use for logfile replay.");
22int main(int argc, char **argv) {
23 aos::InitGoogle(&argc, &argv);
24
25 aos::network::OverrideTeamNumber(FLAGS_team);
26
James Kuszmaul314f1672020-01-03 20:02:08 -080027 const aos::FlatbufferDetachedBuffer<aos::Configuration> config =
28 aos::configuration::ReadConfig(FLAGS_config);
29
30 aos::logger::LogReader reader(FLAGS_logfile, &config.message());
31 // TODO(james): Actually enforce not sending on the same buses as the logfile
32 // spews out.
33 reader.RemapLoggedChannel("/drivetrain",
34 "frc971.control_loops.drivetrain.Status");
35 reader.RemapLoggedChannel("/drivetrain",
36 "frc971.control_loops.drivetrain.Output");
37 reader.Register();
38
James Kuszmaul314f1672020-01-03 20:02:08 -080039 std::unique_ptr<aos::EventLoop> log_writer_event_loop =
40 reader.event_loop_factory()->MakeEventLoop("log_writer");
41 log_writer_event_loop->SkipTimingReport();
Tyler Chatow67ddb032020-01-12 14:30:04 -080042 log_writer_event_loop->SkipAosLog();
James Kuszmaul314f1672020-01-03 20:02:08 -080043 CHECK(nullptr == log_writer_event_loop->node());
Brian Silverman1f345222020-09-24 21:14:48 -070044 aos::logger::Logger writer(log_writer_event_loop.get());
45 writer.StartLoggingLocalNamerOnRun(FLAGS_output_file);
James Kuszmaul314f1672020-01-03 20:02:08 -080046
47 std::unique_ptr<aos::EventLoop> drivetrain_event_loop =
48 reader.event_loop_factory()->MakeEventLoop("drivetrain");
49 drivetrain_event_loop->SkipTimingReport();
50
51 y2019::control_loops::drivetrain::EventLoopLocalizer localizer(
52 drivetrain_event_loop.get(),
53 y2019::control_loops::drivetrain::GetDrivetrainConfig());
54 frc971::control_loops::drivetrain::DrivetrainLoop drivetrain(
55 y2019::control_loops::drivetrain::GetDrivetrainConfig(),
56 drivetrain_event_loop.get(), &localizer);
57
58 reader.event_loop_factory()->Run();
59
James Kuszmaul314f1672020-01-03 20:02:08 -080060 return 0;
61}