Files
allwpilib/wpimath/src/test/native/cpp/system/struct/DCMotorStructTest.cpp

36 lines
1.3 KiB
C++
Raw Normal View History

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <gtest/gtest.h>
#include "wpi/math/system/DCMotor.hpp"
2025-11-07 20:00:05 -05:00
using namespace wpi::math;
2025-11-07 20:00:05 -05:00
using StructType = wpi::util::Struct<wpi::math::DCMotor>;
2024-08-14 10:44:00 -07:00
inline constexpr DCMotor kExpectedData =
DCMotor{1.91_V, 19.1_Nm, 1.74_A, 2.29_A, 2.2_rad_per_s, 2};
TEST(DCMotorStructTest, Roundtrip) {
2023-12-04 22:40:18 -08:00
uint8_t buffer[StructType::GetSize()];
std::memset(buffer, 0, StructType::GetSize());
StructType::Pack(buffer, kExpectedData);
DCMotor unpacked_data = StructType::Unpack(buffer);
EXPECT_EQ(kExpectedData.nominalVoltage.value(),
unpacked_data.nominalVoltage.value());
EXPECT_EQ(kExpectedData.stallTorque.value(),
unpacked_data.stallTorque.value());
EXPECT_EQ(kExpectedData.stallCurrent.value(),
unpacked_data.stallCurrent.value());
EXPECT_EQ(kExpectedData.freeCurrent.value(),
unpacked_data.freeCurrent.value());
EXPECT_EQ(kExpectedData.freeSpeed.value(), unpacked_data.freeSpeed.value());
EXPECT_EQ(kExpectedData.R.value(), unpacked_data.R.value());
EXPECT_EQ(kExpectedData.Kv.value(), unpacked_data.Kv.value());
EXPECT_EQ(kExpectedData.Kt.value(), unpacked_data.Kt.value());
}