WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
SimpleMotorFeedforwardProto.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
8
10#include "pb.h"
11#include "units/length.h"
13
14// Everything is converted into units for
15// frc::SimpleMotorFeedforward<units::meters> or
16// frc::SimpleMotorFeedforward<units::radians>
17
18template <class Distance>
19 requires units::length_unit<Distance> || units::angle_unit<Distance>
20struct wpi::Protobuf<frc::SimpleMotorFeedforward<Distance>> {
26
27 static std::optional<frc::SimpleMotorFeedforward<Distance>> Unpack(
28 InputStream& stream) {
29 using BaseUnit =
30 units::unit<std::ratio<1>, units::traits::base_unit_of<Distance>>;
31 using BaseFeedforward = frc::SimpleMotorFeedforward<BaseUnit>;
33 if (!stream.Decode(msg)) {
34 return {};
35 }
36
38 units::volt_t{msg.ks},
39 units::unit_t<typename BaseFeedforward::kv_unit>{msg.kv},
40 units::unit_t<typename BaseFeedforward::ka_unit>{msg.ka},
41 units::second_t{msg.dt},
42 };
43 }
44
45 static bool Pack(OutputStream& stream,
47 using BaseUnit =
48 units::unit<std::ratio<1>, units::traits::base_unit_of<Distance>>;
49 using BaseFeedforward = frc::SimpleMotorFeedforward<BaseUnit>;
51 .ks = value.GetKs().value(),
52 .kv = units::unit_t<typename BaseFeedforward::kv_unit>{value.GetKv()}
53 .value(),
54 .ka = units::unit_t<typename BaseFeedforward::ka_unit>{value.GetKa()}
55 .value(),
56 .dt = units::second_t{value.GetDt()}.value(),
57 };
58 return stream.Encode(msg);
59 }
60};
A helper class that computes feedforward voltages for a simple permanent-magnet DC motor.
Definition SimpleMotorFeedforward.h:24
constexpr units::unit_t< ka_unit > GetKa() const
Returns the acceleration gain.
Definition SimpleMotorFeedforward.h:221
constexpr units::volt_t GetKs() const
Returns the static gain.
Definition SimpleMotorFeedforward.h:207
constexpr units::unit_t< kv_unit > GetKv() const
Returns the velocity gain.
Definition SimpleMotorFeedforward.h:214
constexpr units::second_t GetDt() const
Returns the period.
Definition SimpleMotorFeedforward.h:228
Class for wrapping a nanopb istream.
Definition Protobuf.h:55
bool Decode(typename Protobuf< std::remove_cvref_t< T > >::MessageStruct &msg, unsigned int flags=0)
Decodes a protobuf.
Definition Protobuf.h:104
Class for wrapping a nanopb ostream.
Definition Protobuf.h:119
bool Encode(const typename Protobuf< std::remove_cvref_t< T > >::MessageStruct &msg)
Decodes a protobuf.
Definition Protobuf.h:211
struct _wpi_proto_ProtobufSimpleMotorFeedforward wpi_proto_ProtobufSimpleMotorFeedforward
Definition SystemServer.h:9
Definition controller.npb.h:53
double kv
Definition controller.npb.h:59
double ks
Definition controller.npb.h:58
double ka
Definition controller.npb.h:60
double dt
Definition controller.npb.h:61
static bool Pack(OutputStream &stream, const frc::SimpleMotorFeedforward< Distance > &value)
Definition SimpleMotorFeedforwardProto.h:45
static std::optional< frc::SimpleMotorFeedforward< Distance > > Unpack(InputStream &stream)
Definition SimpleMotorFeedforwardProto.h:27
Protobuf serialization template.
Definition Protobuf.h:36