blob: c7d81c257a40e5fe71af643ced5ec846e2db0c7d [file] [log] [blame]
James Kuszmaul022d40e2020-02-11 17:06:18 -08001// This binary allows us to replay the drivetrain code over existing logfile,
2// primarily for use in testing changes to the localizer code.
3// When you run this code, it generates a new logfile with the data all
4// replayed, so that it can then be run through the plotting tool or analyzed
5// in some other way. The original drivetrain status data will be on the
6// /original/drivetrain channel.
7#include "aos/configuration.h"
8#include "aos/events/logging/logger.h"
9#include "aos/events/simulated_event_loop.h"
10#include "aos/init.h"
11#include "aos/json_to_flatbuffer.h"
12#include "aos/network/team_number.h"
13#include "frc971/control_loops/drivetrain/drivetrain.h"
14#include "gflags/gflags.h"
15#include "y2020/control_loops/drivetrain/drivetrain_base.h"
16
17DEFINE_string(logfile, "/tmp/logfile.bfbs",
18 "Name of the logfile to read from.");
19DEFINE_string(config, "y2020/config.json",
20 "Name of the config file to replay using.");
21DEFINE_string(output_file, "/tmp/replayed.bfbs",
22 "Name of the logfile to write replayed data to.");
23DEFINE_int32(team, 971, "Team number to use for logfile replay.");
24int main(int argc, char **argv) {
25 aos::InitGoogle(&argc, &argv);
26
27 aos::network::OverrideTeamNumber(FLAGS_team);
28
29 aos::InitCreate();
30
31 const aos::FlatbufferDetachedBuffer<aos::Configuration> config =
32 aos::configuration::ReadConfig(FLAGS_config);
33
34 aos::logger::LogReader reader(FLAGS_logfile, &config.message());
35 // TODO(james): Actually enforce not sending on the same buses as the logfile
36 // spews out.
37 reader.RemapLoggedChannel("/drivetrain",
38 "frc971.control_loops.drivetrain.Status");
39 reader.RemapLoggedChannel("/drivetrain",
40 "frc971.control_loops.drivetrain.Output");
41 reader.Register();
42
43 aos::logger::DetachedBufferWriter file_writer(FLAGS_output_file);
44 std::unique_ptr<aos::EventLoop> log_writer_event_loop =
45 reader.event_loop_factory()->MakeEventLoop("log_writer");
46 log_writer_event_loop->SkipTimingReport();
47 CHECK(nullptr == log_writer_event_loop->node());
48 aos::logger::Logger writer(&file_writer, log_writer_event_loop.get());
49
50 std::unique_ptr<aos::EventLoop> drivetrain_event_loop =
51 reader.event_loop_factory()->MakeEventLoop("drivetrain");
52 drivetrain_event_loop->SkipTimingReport();
53
54 frc971::control_loops::drivetrain::DeadReckonEkf localizer(
55 drivetrain_event_loop.get(),
56 y2020::control_loops::drivetrain::GetDrivetrainConfig());
57 frc971::control_loops::drivetrain::DrivetrainLoop drivetrain(
58 y2020::control_loops::drivetrain::GetDrivetrainConfig(),
59 drivetrain_event_loop.get(), &localizer);
60
61 reader.event_loop_factory()->Run();
62
63 aos::Cleanup();
64 return 0;
65}