2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2019-07-24 02:57:39 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "Translation2d.h"
|
|
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
|
|
|
|
|
class Pose2d;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents a transformation for a Pose2d.
|
|
|
|
|
*/
|
|
|
|
|
class Transform2d {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Constructs the transform that maps the initial pose to the final pose.
|
|
|
|
|
*
|
|
|
|
|
* @param initial The initial pose for the transformation.
|
|
|
|
|
* @param final The final pose for the transformation.
|
|
|
|
|
*/
|
|
|
|
|
Transform2d(Pose2d initial, Pose2d final);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs a transform with the given translation and rotation components.
|
|
|
|
|
*
|
|
|
|
|
* @param translation Translational component of the transform.
|
|
|
|
|
* @param rotation Rotational component of the transform.
|
|
|
|
|
*/
|
|
|
|
|
Transform2d(Translation2d translation, Rotation2d rotation);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs the identity transform -- maps an initial pose to itself.
|
|
|
|
|
*/
|
|
|
|
|
constexpr Transform2d() = default;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the translation component of the transformation.
|
|
|
|
|
*
|
|
|
|
|
* @return Reference to the translational component of the transform.
|
|
|
|
|
*/
|
|
|
|
|
const Translation2d& Translation() const { return m_translation; }
|
|
|
|
|
|
2020-07-02 18:09:36 -07:00
|
|
|
/**
|
|
|
|
|
* Returns the X component of the transformation's translation.
|
|
|
|
|
*
|
|
|
|
|
* @return The x component of the transformation's translation.
|
|
|
|
|
*/
|
|
|
|
|
units::meter_t X() const { return m_translation.X(); }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the Y component of the transformation's translation.
|
|
|
|
|
*
|
|
|
|
|
* @return The y component of the transformation's translation.
|
|
|
|
|
*/
|
|
|
|
|
units::meter_t Y() const { return m_translation.Y(); }
|
|
|
|
|
|
2019-07-24 02:57:39 -04:00
|
|
|
/**
|
|
|
|
|
* Returns the rotational component of the transformation.
|
|
|
|
|
*
|
|
|
|
|
* @return Reference to the rotational component of the transform.
|
|
|
|
|
*/
|
|
|
|
|
const Rotation2d& Rotation() const { return m_rotation; }
|
|
|
|
|
|
2020-03-14 22:01:52 -07:00
|
|
|
/**
|
|
|
|
|
* Invert the transformation. This is useful for undoing a transformation.
|
|
|
|
|
*
|
|
|
|
|
* @return The inverted transformation.
|
|
|
|
|
*/
|
|
|
|
|
Transform2d Inverse() const;
|
|
|
|
|
|
2019-09-28 18:40:56 -04:00
|
|
|
/**
|
|
|
|
|
* Scales the transform by the scalar.
|
|
|
|
|
*
|
|
|
|
|
* @param scalar The scalar.
|
|
|
|
|
* @return The scaled Transform2d.
|
|
|
|
|
*/
|
|
|
|
|
Transform2d operator*(double scalar) const {
|
|
|
|
|
return Transform2d(m_translation * scalar, m_rotation * scalar);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 20:22:48 -07:00
|
|
|
/**
|
|
|
|
|
* Composes two transformations.
|
|
|
|
|
*
|
|
|
|
|
* @param other The transform to compose with this one.
|
|
|
|
|
*/
|
|
|
|
|
Transform2d operator+(const Transform2d& other) const;
|
|
|
|
|
|
2019-09-08 14:20:26 -04:00
|
|
|
/**
|
|
|
|
|
* Checks equality between this Transform2d and another object.
|
|
|
|
|
*
|
|
|
|
|
* @param other The other object.
|
|
|
|
|
* @return Whether the two objects are equal.
|
|
|
|
|
*/
|
|
|
|
|
bool operator==(const Transform2d& other) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks inequality between this Transform2d and another object.
|
|
|
|
|
*
|
|
|
|
|
* @param other The other object.
|
|
|
|
|
* @return Whether the two objects are not equal.
|
|
|
|
|
*/
|
|
|
|
|
bool operator!=(const Transform2d& other) const;
|
|
|
|
|
|
2019-07-24 02:57:39 -04:00
|
|
|
private:
|
|
|
|
|
Translation2d m_translation;
|
|
|
|
|
Rotation2d m_rotation;
|
|
|
|
|
};
|
|
|
|
|
} // namespace frc
|