blob: 27816ce629120c0b6cb5389079922fb2519c398c [file] [log] [blame]
Austin Schuhf213a072021-10-17 23:42:50 -07001// 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.
Austin Schuh99f7c6a2024-06-25 22:07:44 -07007#include "absl/flags/flag.h"
Philipp Schrader790cb542023-07-05 21:06:52 -07008
Austin Schuhf213a072021-10-17 23:42:50 -07009#include "aos/events/logging/log_reader.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"
Austin Schuhf213a072021-10-17 23:42:50 -070015#include "y2020/constants.h"
16#include "y2020/control_loops/superstructure/superstructure.h"
17
Austin Schuh99f7c6a2024-06-25 22:07:44 -070018ABSL_FLAG(int32_t, team, 971, "Team number to use for logfile replay.");
Austin Schuhf213a072021-10-17 23:42:50 -070019
20int main(int argc, char **argv) {
21 aos::InitGoogle(&argc, &argv);
22
Austin Schuh99f7c6a2024-06-25 22:07:44 -070023 aos::network::OverrideTeamNumber(absl::GetFlag(FLAGS_team));
Austin Schuhf213a072021-10-17 23:42:50 -070024 y2020::constants::InitValues();
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 "y2020.control_loops.superstructure.Status");
33 reader.RemapLoggedChannel("/superstructure",
34 "y2020.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 roborio->OnStartup([roborio]() {
43 roborio->AlwaysStart<y2020::control_loops::superstructure::Superstructure>(
44 "superstructure");
45 });
46
47 std::unique_ptr<aos::EventLoop> print_loop = roborio->MakeEventLoop("print");
48 print_loop->SkipAosLog();
49 print_loop->MakeWatcher(
50 "/aos", [&print_loop](const aos::logging::LogMessageFbs &msg) {
51 LOG(INFO) << print_loop->context().monotonic_event_time << " "
52 << aos::FlatbufferToJson(&msg);
53 });
54 print_loop->MakeWatcher(
55 "/superstructure",
56 [&print_loop](
57 const y2020::control_loops::superstructure::Position &position) {
58 LOG(INFO) << print_loop->context().monotonic_event_time << " "
59 << aos::FlatbufferToJson(position.hood());
60 });
61 print_loop->MakeWatcher(
62 "/superstructure",
63 [&print_loop](
64 const y2020::control_loops::superstructure::Status &status) {
65 if (status.estopped()) {
66 LOG(INFO) << "Estopped";
67 }
68 LOG(INFO) << print_loop->context().monotonic_event_time << " "
69 << aos::FlatbufferToJson(status.hood());
70 });
71
72 factory.Run();
73
74 reader.Deregister();
75
76 return 0;
77}