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