WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
SimpleMotorFeedforwardStruct.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 <wpi/struct/Struct.h>
8
10#include "units/length.h"
11
12// Everything is converted into units for
13// frc::SimpleMotorFeedforward<units::meters> or
14// frc::SimpleMotorFeedforward<units::radians>
15
16template <class Distance>
17 requires units::length_unit<Distance> || units::angle_unit<Distance>
18struct wpi::Struct<frc::SimpleMotorFeedforward<Distance>> {
19 static constexpr std::string_view GetTypeName() {
20 return "SimpleMotorFeedforward";
21 }
22 static constexpr size_t GetSize() { return 32; }
23 static constexpr std::string_view GetSchema() {
24 return "double ks;double kv;double ka;double dt";
25 }
26
28 std::span<const uint8_t> data) {
29 using BaseUnit =
31 using BaseFeedforward = frc::SimpleMotorFeedforward<BaseUnit>;
32 constexpr size_t kKsOff = 0;
33 constexpr size_t kKvOff = kKsOff + 8;
34 constexpr size_t kKaOff = kKvOff + 8;
35 constexpr size_t kDtOff = kKaOff + 8;
36 return {units::volt_t{wpi::UnpackStruct<double, kKsOff>(data)},
41 units::second_t{wpi::UnpackStruct<double, kDtOff>(data)}};
42 }
43
44 static void Pack(std::span<uint8_t> data,
46 using BaseUnit =
48 using BaseFeedforward = frc::SimpleMotorFeedforward<BaseUnit>;
49 constexpr size_t kKsOff = 0;
50 constexpr size_t kKvOff = kKsOff + 8;
51 constexpr size_t kKaOff = kKvOff + 8;
52 constexpr size_t kDtOff = kKaOff + 8;
53 wpi::PackStruct<kKsOff>(data, value.GetKs().value());
56 .value());
59 .value());
60 wpi::PackStruct<kDtOff>(data, units::second_t{value.GetDt()}.value());
61 }
62};
63
64static_assert(
66static_assert(
68static_assert(
A helper class that computes feedforward voltages for a simple permanent-magnet DC motor.
Definition SimpleMotorFeedforward.h:24
Container for values which represent quantities of a given unit.
Definition base.h:1930
constexpr underlying_type value() const noexcept
unit value
Definition base.h:2111
Specifies that a type is capable of raw struct serialization and deserialization.
Definition Struct.h:69
Definition CAN.h:11
typename units::detail::base_unit_of_impl< U >::type base_unit_of
Trait which returns the base_unit type that a unit is originally derived from.
Definition base.h:936
T UnpackStruct(std::span< const uint8_t > data, const I &... info)
Unpack a serialized struct.
Definition Struct.h:138
void PackStruct(std::span< uint8_t > data, T &&value, const I &... info)
Pack a serialized struct.
Definition Struct.h:200
Type representing an arbitrary unit.
Definition base.h:888
static constexpr std::string_view GetSchema()
Definition SimpleMotorFeedforwardStruct.h:23
static void Pack(std::span< uint8_t > data, const frc::SimpleMotorFeedforward< Distance > &value)
Definition SimpleMotorFeedforwardStruct.h:44
static constexpr std::string_view GetTypeName()
Definition SimpleMotorFeedforwardStruct.h:19
static frc::SimpleMotorFeedforward< Distance > Unpack(std::span< const uint8_t > data)
Definition SimpleMotorFeedforwardStruct.h:27
static constexpr size_t GetSize()
Definition SimpleMotorFeedforwardStruct.h:22
Struct serialization template.
Definition Struct.h:39