001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.math.geometry.struct; 006 007import edu.wpi.first.math.geometry.Pose2d; 008import edu.wpi.first.math.geometry.Rotation2d; 009import edu.wpi.first.math.geometry.Translation2d; 010import edu.wpi.first.util.struct.Struct; 011import java.nio.ByteBuffer; 012 013public class Pose2dStruct implements Struct<Pose2d> { 014 @Override 015 public Class<Pose2d> getTypeClass() { 016 return Pose2d.class; 017 } 018 019 @Override 020 public String getTypeString() { 021 return "struct:Pose2d"; 022 } 023 024 @Override 025 public int getSize() { 026 return Translation2d.struct.getSize() + Rotation2d.struct.getSize(); 027 } 028 029 @Override 030 public String getSchema() { 031 return "Translation2d translation;Rotation2d rotation"; 032 } 033 034 @Override 035 public Struct<?>[] getNested() { 036 return new Struct<?>[] {Translation2d.struct, Rotation2d.struct}; 037 } 038 039 @Override 040 public Pose2d unpack(ByteBuffer bb) { 041 Translation2d translation = Translation2d.struct.unpack(bb); 042 Rotation2d rotation = Rotation2d.struct.unpack(bb); 043 return new Pose2d(translation, rotation); 044 } 045 046 @Override 047 public void pack(ByteBuffer bb, Pose2d value) { 048 Translation2d.struct.pack(bb, value.getTranslation()); 049 Rotation2d.struct.pack(bb, value.getRotation()); 050 } 051}