blob: 5579e1800327c62bbb460028e04c989a52bce2bd [file] [log] [blame]
James Kuszmaul18008f82023-02-23 20:52:50 -08001#ifndef Y2023_LOCALIZER_MAP_EXPANDER_LIB_H_
2#define Y2023_LOCALIZER_MAP_EXPANDER_LIB_H_
3
James Kuszmaul18008f82023-02-23 20:52:50 -08004#include <map>
5
Philipp Schrader790cb542023-07-05 21:06:52 -07006#include <Eigen/Dense>
7
James Kuszmaul18008f82023-02-23 20:52:50 -08008#include "aos/flatbuffers.h"
9#include "aos/json_to_flatbuffer.h"
10#include "frc971/vision/target_map_generated.h"
11#include "y2023/localizer/relative_scoring_map_generated.h"
12#include "y2023/localizer/scoring_map_generated.h"
13
14namespace y2023::localizer {
15
16// This function takes a RelativeScoringMap plus a TargetMap with april tag
17// locations and uses it to generate a map of the various scoring locations on
18// the field.
19// This allows us to use a condensed JSON file (the RelativeScoringMap) to
20// generate the more verbose ScoringMap, making it so that humans don't have to
21// modify every single location in the verbose ScoringMap should something
22// change. However, we do still want to have the full ScoringMap available
23// for modifications should we discover that, e.g., an individual field has
24// one individual pole or april tag or something out of aligment.
25aos::FlatbufferDetachedBuffer<ScoringMap> ExpandMap(
26 const RelativeScoringMap *relative_map,
27 const frc971::vision::TargetMap *target_map);
28
29inline aos::FlatbufferDetachedBuffer<ScoringMap> ExpandMap(
30 std::string_view relative_map_json, std::string_view target_map_json) {
31 aos::FlatbufferDetachedBuffer<RelativeScoringMap> relative =
32 aos::JsonToFlatbuffer<RelativeScoringMap>(relative_map_json);
33 aos::FlatbufferDetachedBuffer<frc971::vision::TargetMap> target_map =
34 aos::JsonToFlatbuffer<frc971::vision::TargetMap>(target_map_json);
35 return ExpandMap(&relative.message(), &target_map.message());
36}
37
38aos::FlatbufferDetachedBuffer<ScoringGrid> RelativeGridForTag(
39 const ScoringGrid *absolute_grid,
40 const frc971::vision::TargetMap *target_map, uint64_t tag);
41
42aos::FlatbufferDetachedBuffer<DoubleSubstation> RelativeSubstationForTag(
43 const DoubleSubstation *absolute_substation,
44 const frc971::vision::TargetMap *target_map, uint64_t tag);
45
46std::map<uint64_t, Eigen::Affine3d> AprilTagPoses(
47 const frc971::vision::TargetMap *map);
48
49} // namespace y2023::localizer
50#endif // Y2023_LOCALIZER_MAP_EXPANDER_LIB_H_