WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
LinearSystemStruct.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
13
14template <int States, int Inputs, int Outputs>
15struct wpi::Struct<frc::LinearSystem<States, Inputs, Outputs>> {
16 static constexpr ct_string kTypeName =
17 wpi::Concat("LinearSystem__"_ct_string, wpi::NumToCtString<States>(),
18 "_"_ct_string, wpi::NumToCtString<Inputs>(), "_"_ct_string,
20 static constexpr std::string_view GetTypeName() { return kTypeName; }
27 static constexpr ct_string kSchema = wpi::Concat(
28 wpi::Struct<frc::Matrixd<States, States>>::kTypeName, " a;"_ct_string,
29 wpi::Struct<frc::Matrixd<States, Inputs>>::kTypeName, " b;"_ct_string,
30 wpi::Struct<frc::Matrixd<Outputs, States>>::kTypeName, " c;"_ct_string,
31 wpi::Struct<frc::Matrixd<Outputs, Inputs>>::kTypeName, " d"_ct_string);
32 static constexpr std::string_view GetSchema() { return kSchema; }
33
35 std::span<const uint8_t> data) {
36 constexpr size_t kAOff = 0;
37 constexpr size_t kBOff =
39 constexpr size_t kCOff =
41 constexpr size_t kDOff =
48 }
49
50 static void Pack(std::span<uint8_t> data,
52 constexpr size_t kAOff = 0;
53 constexpr size_t kBOff =
55 constexpr size_t kCOff =
57 constexpr size_t kDOff =
59 wpi::PackStruct<kAOff>(data, value.A());
60 wpi::PackStruct<kBOff>(data, value.B());
61 wpi::PackStruct<kCOff>(data, value.C());
62 wpi::PackStruct<kDOff>(data, value.D());
63 }
64
72};
73
A plant defined using state-space notation.
Definition LinearSystem.h:35
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
Eigen::Matrix< double, Rows, Cols, Options, MaxRows, MaxCols > Matrixd
Definition EigenCore.h:21
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
T UnpackStruct(std::span< const uint8_t > data, const I &... info)
Unpack a serialized struct.
Definition Struct.h:138
constexpr size_t GetStructSize(const I &... info)
Get the size for a raw struct serializable type.
Definition Struct.h:337
void ForEachStructSchema(std::invocable< std::string_view, std::string_view > auto fn, const I &... info)
Definition Struct.h:424
void PackStruct(std::span< uint8_t > data, T &&value, const I &... info)
Pack a serialized struct.
Definition Struct.h:200
static constexpr size_t GetSize()
Definition LinearSystemStruct.h:21
static frc::LinearSystem< States, Inputs, Outputs > Unpack(std::span< const uint8_t > data)
Definition LinearSystemStruct.h:34
static constexpr std::string_view GetTypeName()
Definition LinearSystemStruct.h:20
static void Pack(std::span< uint8_t > data, const frc::LinearSystem< States, Inputs, Outputs > &value)
Definition LinearSystemStruct.h:50
static constexpr std::string_view GetSchema()
Definition LinearSystemStruct.h:32
static void ForEachNested(std::invocable< std::string_view, std::string_view > auto fn)
Definition LinearSystemStruct.h:65
Struct serialization template.
Definition Struct.h:39
Fixed length string (array of character) for compile time use.
Definition ct_string.h:29