WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
SimpleMotorFeedforwardStruct.hpp
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
8#include "wpi/units/length.hpp"
10
11// Everything is converted into units for
12// wpi::math::SimpleMotorFeedforward<wpi::units::meters> or
13// wpi::math::SimpleMotorFeedforward<wpi::units::radians>
14
15template <class Distance>
16 requires wpi::units::length_unit<Distance> || wpi::units::angle_unit<Distance>
18 static constexpr std::string_view GetTypeName() {
19 return "SimpleMotorFeedforward";
20 }
21 static constexpr size_t GetSize() { return 32; }
22 static constexpr std::string_view GetSchema() {
23 return "double ks;double kv;double ka;double dt";
24 }
25
27 std::span<const uint8_t> data) {
28 using BaseUnit =
29 wpi::units::unit<std::ratio<1>,
30 wpi::units::traits::base_unit_of<Distance>>;
31 using BaseFeedforward = wpi::math::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 {
37 wpi::units::volt_t{wpi::util::UnpackStruct<double, kKsOff>(data)},
38 wpi::units::unit_t<typename BaseFeedforward::kv_unit>{
40 wpi::units::unit_t<typename BaseFeedforward::ka_unit>{
42 wpi::units::second_t{wpi::util::UnpackStruct<double, kDtOff>(data)}};
43 }
44
45 static void Pack(std::span<uint8_t> data,
47 using BaseUnit =
48 wpi::units::unit<std::ratio<1>,
49 wpi::units::traits::base_unit_of<Distance>>;
50 using BaseFeedforward = wpi::math::SimpleMotorFeedforward<BaseUnit>;
51 constexpr size_t kKsOff = 0;
52 constexpr size_t kKvOff = kKsOff + 8;
53 constexpr size_t kKaOff = kKvOff + 8;
54 constexpr size_t kDtOff = kKaOff + 8;
55 wpi::util::PackStruct<kKsOff>(data, value.GetKs().value());
57 data,
58 wpi::units::unit_t<typename BaseFeedforward::kv_unit>{value.GetKv()}
59 .value());
61 data,
62 wpi::units::unit_t<typename BaseFeedforward::ka_unit>{value.GetKa()}
63 .value());
65 wpi::units::second_t{value.GetDt()}.value());
66 }
67};
68
A helper class that computes feedforward voltages for a simple permanent-magnet DC motor.
Definition SimpleMotorFeedforward.hpp:24
constexpr wpi::units::second_t GetDt() const
Returns the period.
Definition SimpleMotorFeedforward.hpp:234
constexpr wpi::units::volt_t GetKs() const
Returns the static gain.
Definition SimpleMotorFeedforward.hpp:213
constexpr wpi::units::unit_t< kv_unit > GetKv() const
Returns the velocity gain.
Definition SimpleMotorFeedforward.hpp:220
constexpr wpi::units::unit_t< ka_unit > GetKa() const
Returns the acceleration gain.
Definition SimpleMotorFeedforward.hpp:227
Specifies that a type is capable of raw struct serialization and deserialization.
Definition Struct.hpp:69
void PackStruct(std::span< uint8_t > data, T &&value, const I &... info)
Pack a serialized struct.
Definition Struct.hpp:200
T UnpackStruct(std::span< const uint8_t > data, const I &... info)
Unpack a serialized struct.
Definition Struct.hpp:138
Definition CvSource.hpp:15
static wpi::math::SimpleMotorFeedforward< Distance > Unpack(std::span< const uint8_t > data)
Definition SimpleMotorFeedforwardStruct.hpp:26
static void Pack(std::span< uint8_t > data, const wpi::math::SimpleMotorFeedforward< Distance > &value)
Definition SimpleMotorFeedforwardStruct.hpp:45
static constexpr std::string_view GetTypeName()
Definition SimpleMotorFeedforwardStruct.hpp:18
static constexpr size_t GetSize()
Definition SimpleMotorFeedforwardStruct.hpp:21
static constexpr std::string_view GetSchema()
Definition SimpleMotorFeedforwardStruct.hpp:22
Struct serialization template.
Definition Struct.hpp:39