WPILibC++ 2025.1.1
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 =
31 using BaseFeedforward = frc::SimpleMotorFeedforward<BaseUnit>;
33 if (!stream.Decode(msg)) {
34 return {};
35 }
36
38 units::volt_t{msg.ks},
41 units::second_t{msg.dt},
42 };
43 }
44
45 static bool Pack(OutputStream& stream,
47 using BaseUnit =
49 using BaseFeedforward = frc::SimpleMotorFeedforward<BaseUnit>;
51 .ks = value.GetKs().value(),
53 .value(),
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
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
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 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
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
Type representing an arbitrary unit.
Definition base.h:888
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