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.kinematics.struct;
006
007import edu.wpi.first.math.geometry.Translation2d;
008import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
009import edu.wpi.first.util.struct.Struct;
010import java.nio.ByteBuffer;
011
012public class MecanumDriveKinematicsStruct implements Struct<MecanumDriveKinematics> {
013  @Override
014  public Class<MecanumDriveKinematics> getTypeClass() {
015    return MecanumDriveKinematics.class;
016  }
017
018  @Override
019  public String getTypeString() {
020    return "struct:MecanumDriveKinematics";
021  }
022
023  @Override
024  public int getSize() {
025    return 4 * Translation2d.struct.getSize();
026  }
027
028  @Override
029  public String getSchema() {
030    return "Translation2d front_left;Translation2d front_right;Translation2d rear_left;"
031        + "Translation2d rear_right";
032  }
033
034  @Override
035  public Struct<?>[] getNested() {
036    return new Struct<?>[] {Translation2d.struct};
037  }
038
039  @Override
040  public MecanumDriveKinematics unpack(ByteBuffer bb) {
041    Translation2d frontLeft = Translation2d.struct.unpack(bb);
042    Translation2d frontRight = Translation2d.struct.unpack(bb);
043    Translation2d rearLeft = Translation2d.struct.unpack(bb);
044    Translation2d rearRight = Translation2d.struct.unpack(bb);
045    return new MecanumDriveKinematics(frontLeft, frontRight, rearLeft, rearRight);
046  }
047
048  @Override
049  public void pack(ByteBuffer bb, MecanumDriveKinematics value) {
050    Translation2d.struct.pack(bb, value.getFrontLeft());
051    Translation2d.struct.pack(bb, value.getFrontRight());
052    Translation2d.struct.pack(bb, value.getRearLeft());
053    Translation2d.struct.pack(bb, value.getRearRight());
054  }
055}