WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
SwerveDriveKinematicsStruct.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <fmt/format.h>
8#include <wpi/ct_string.h>
9#include <wpi/struct/Struct.h>
10
12
13template <size_t NumModules>
14struct wpi::Struct<frc::SwerveDriveKinematics<NumModules>> {
15 static constexpr ct_string kTypeName = wpi::Concat(
16 "SwerveDriveKinematics__"_ct_string, wpi::NumToCtString<NumModules>());
17 static constexpr std::string_view GetTypeName() { return kTypeName; }
18 static constexpr size_t GetSize() {
19 return NumModules * wpi::Struct<frc::Translation2d>::GetSize();
20 }
21 static constexpr ct_string kSchema =
22 wpi::Concat("Translation2d modules["_ct_string,
23 wpi::NumToCtString<NumModules>(), "]"_ct_string);
24 static constexpr std::string_view GetSchema() { return kSchema; }
25
27 std::span<const uint8_t> data) {
28 constexpr size_t kModulesOff = 0;
31 data)};
32 }
33
34 static void Pack(std::span<uint8_t> data,
36 constexpr size_t kModulesOff = 0;
37 wpi::PackStructArray<kModulesOff, NumModules>(data, value.GetModules());
38 }
39
40 static void ForEachNested(
41 std::invocable<std::string_view, std::string_view> auto fn) {
43 }
44};
45
Helper class that converts a chassis velocity (dx, dy, and dtheta components) into individual module ...
Definition SwerveDriveKinematics.h:54
Specifies that a struct type has nested struct declarations.
Definition Struct.h:120
Specifies that a type is capable of raw struct serialization and deserialization.
Definition Struct.h:69
Definition CAN.h:11
constexpr auto NumToCtString()
Converts any integral to a ct_string at compile-time.
Definition ct_string.h:202
constexpr auto Concat(ct_string< Char, Traits, N1 > const &s1, ct_string< Char, Traits, N > const &... s)
Concatenates multiple fixed_strings into a larger fixed_string at compile time.
Definition ct_string.h:168
void PackStructArray(std::span< uint8_t > data, const wpi::array< T, N > &arr)
Pack a serialized struct array starting at a given offset within the data.
Definition Struct.h:234
void ForEachStructSchema(std::invocable< std::string_view, std::string_view > auto fn, const I &... info)
Definition Struct.h:424
wpi::array< T, N > UnpackStructArray(std::span< const uint8_t > data)
Unpack a serialized struct array starting at a given offset within the data.
Definition Struct.h:172
static constexpr std::string_view GetSchema()
Definition SwerveDriveKinematicsStruct.h:24
static void ForEachNested(std::invocable< std::string_view, std::string_view > auto fn)
Definition SwerveDriveKinematicsStruct.h:40
static frc::SwerveDriveKinematics< NumModules > Unpack(std::span< const uint8_t > data)
Definition SwerveDriveKinematicsStruct.h:26
static constexpr std::string_view GetTypeName()
Definition SwerveDriveKinematicsStruct.h:17
static void Pack(std::span< uint8_t > data, const frc::SwerveDriveKinematics< NumModules > &value)
Definition SwerveDriveKinematicsStruct.h:34
static constexpr size_t GetSize()
Definition SwerveDriveKinematicsStruct.h:18
Struct serialization template.
Definition Struct.h:39
Fixed length string (array of character) for compile time use.
Definition ct_string.h:29