run clang format

This commit is contained in:
Prateek Machiraju 2019-06-29 14:39:30 -04:00
parent ff9e83f445
commit 3f0dfe6bba
14 changed files with 89 additions and 92 deletions

View File

@ -24,8 +24,8 @@ struct ConstrainedPose {
} }
ConstrainedPose(ConstrainedPose& other) = default; ConstrainedPose(ConstrainedPose& other) = default;
ConstrainedPose& operator=(ConstrainedPose& other) { ConstrainedPose& operator =(ConstrainedPose& other) {
//std::cout << "Copy operator called"; // std::cout << "Copy operator called";
this->state = other.state; this->state = other.state;
this->distance = other.distance; this->distance = other.distance;
this->max_velocity = other.max_velocity; this->max_velocity = other.max_velocity;

View File

@ -13,9 +13,8 @@ TrajectoryTrackerOutput TrajectoryTracker::NextState(const Pose2d& curre
if (iterator_ == nullptr) throw std::exception("Iterator was nullptr."); if (iterator_ == nullptr) throw std::exception("Iterator was nullptr.");
auto& iterator = *iterator_; auto& iterator = *iterator_;
const auto dt = (units::unit_cast<double>(previous_time_) < 0.0) const auto dt =
? units::second_t{0.0} (units::unit_cast<double>(previous_time_) < 0.0) ? units::second_t{0.0} : current_time - previous_time_;
: current_time - previous_time_;
previous_time_ = current_time; previous_time_ = current_time;
iterator.Advance(dt); iterator.Advance(dt);
@ -34,8 +33,7 @@ TrajectoryTrackerOutput TrajectoryTracker::NextState(const Pose2d& curre
const TrajectoryTrackerOutput output{ const TrajectoryTrackerOutput output{
linear_velocity, (linear_velocity - previous_velocity_->linear_velocity) / _dt, angular_velocity, linear_velocity, (linear_velocity - previous_velocity_->linear_velocity) / _dt, angular_velocity,
(angular_velocity - previous_velocity_->angular_velocity) / _dt (angular_velocity - previous_velocity_->angular_velocity) / _dt};
};
previous_velocity_->linear_velocity = linear_velocity; previous_velocity_->linear_velocity = linear_velocity;
previous_velocity_->angular_velocity = angular_velocity; previous_velocity_->angular_velocity = angular_velocity;
@ -47,5 +45,7 @@ TrajectorySamplePoint<TimedEntry<Pose2dWithCurvature>> TrajectoryTracker::Refere
return iterator_->CurrentState(); return iterator_->CurrentState();
} }
bool TrajectoryTracker::IsFinished() const { return iterator_->IsDone(); } bool TrajectoryTracker::IsFinished() const {
return iterator_->IsDone();
} }
} // namespace fl

View File

@ -25,26 +25,38 @@ Rotation2d Rotation2d::FromDegrees(const double degrees) {
return Rotation2d(Deg2Rad(degrees)); return Rotation2d(Deg2Rad(degrees));
} }
Rotation2d Rotation2d::operator-(const Rotation2d& other) const { return *this + -other; } Rotation2d Rotation2d::operator-(const Rotation2d& other) const {
return *this + -other;
Rotation2d Rotation2d::operator-() const { return Rotation2d(-value_); }
Rotation2d Rotation2d::operator+(const Rotation2d& other) const {
return Rotation2d{
Cos() * other.Cos() - Sin() * other.Sin(), Cos() * other.Sin() + Sin() * other.Cos(),
true
};
} }
double Rotation2d::Radians() const { return value_; } Rotation2d Rotation2d::operator-() const {
return Rotation2d(-value_);
}
double Rotation2d::Degrees() const { return Rad2Deg(value_); } Rotation2d Rotation2d::operator+(const Rotation2d& other) const {
return Rotation2d{Cos() * other.Cos() - Sin() * other.Sin(), Cos() * other.Sin() + Sin() * other.Cos(),
true};
}
double Rotation2d::Cos() const { return cos_; } double Rotation2d::Radians() const {
return value_;
}
double Rotation2d::Sin() const { return sin_; } double Rotation2d::Degrees() const {
return Rad2Deg(value_);
}
double Rotation2d::Tan() const { return sin_ / cos_; } double Rotation2d::Cos() const {
return cos_;
}
double Rotation2d::Sin() const {
return sin_;
}
double Rotation2d::Tan() const {
return sin_ / cos_;
}
bool Rotation2d::IsParallel(const Rotation2d& other) const { bool Rotation2d::IsParallel(const Rotation2d& other) const {
return EpsilonEquals((*this - other).Radians(), 0.0); return EpsilonEquals((*this - other).Radians(), 0.0);

View File

@ -34,22 +34,27 @@ Translation2d Translation2d::operator*(const double scalar) const {
} }
Translation2d Translation2d::operator*(const Rotation2d& rotation) const { Translation2d Translation2d::operator*(const Rotation2d& rotation) const {
return Translation2d{ return Translation2d{x_ * rotation.Cos() - y_ * rotation.Sin(), x_ * rotation.Sin() + y_ * rotation.Cos()};
x_ * rotation.Cos() - y_ * rotation.Sin(),
x_ * rotation.Sin() + y_ * rotation.Cos()
};
} }
Translation2d Translation2d::operator/(const double scalar) const { Translation2d Translation2d::operator/(const double scalar) const {
return Translation2d{X() / scalar, Y() / scalar}; return Translation2d{X() / scalar, Y() / scalar};
} }
Translation2d Translation2d::operator-() const { return Translation2d{-X(), -Y()}; } Translation2d Translation2d::operator-() const {
return Translation2d{-X(), -Y()};
}
double Translation2d::X() const { return x_; } double Translation2d::X() const {
return x_;
}
double Translation2d::Y() const { return y_; } double Translation2d::Y() const {
return y_;
}
double Translation2d::Norm() const { return std::hypot(x_, y_); } double Translation2d::Norm() const {
return std::hypot(x_, y_);
}
} // namespace fl } // namespace fl

View File

@ -2,30 +2,28 @@
namespace fl { namespace fl {
Twist2d::Twist2d() Twist2d::Twist2d() : dx_(0.0), dy_(0.0), dtheta_(0.0) {}
: dx_(0.0),
dy_(0.0),
dtheta_(0.0) {
}
Twist2d::Twist2d(const double dx, const double dy, const double dtheta) Twist2d::Twist2d(const double dx, const double dy, const double dtheta) : dx_(dx), dy_(dy), dtheta_(dtheta) {}
: dx_(dx),
dy_(dy),
dtheta_(dtheta) {
}
Twist2d Twist2d::operator*(const double scalar) const { Twist2d Twist2d::operator*(const double scalar) const {
return {dx_ * scalar, dy_ * scalar, dtheta_ * scalar}; return {dx_ * scalar, dy_ * scalar, dtheta_ * scalar};
} }
double Twist2d::Dx() const { return dx_; } double Twist2d::Dx() const {
return dx_;
}
double Twist2d::Dy() const { return dy_; } double Twist2d::Dy() const {
return dy_;
}
double Twist2d::Dtheta() const { return dtheta_; } double Twist2d::Dtheta() const {
return dtheta_;
}
double Twist2d::Norm() const { double Twist2d::Norm() const {
if (dy_ == 0.0) return std::abs(dx_); if (dy_ == 0.0) return std::abs(dx_);
return std::hypot(dx_, dy_); return std::hypot(dx_, dy_);
} }
} } // namespace fl

View File

@ -1,14 +1,9 @@
#include "fl/mathematics/trajectory/TrajectoryGenerator.h" #include "fl/mathematics/trajectory/TrajectoryGenerator.h"
namespace fl { namespace fl {
TimedTrajectory<Pose2dWithCurvature> TrajectoryGenerator::GenerateTrajectory(std::vector<Pose2d> waypoints, TimedTrajectory<Pose2dWithCurvature> TrajectoryGenerator::GenerateTrajectory(
const Constraints& constraints, std::vector<Pose2d> waypoints, const Constraints& constraints, const double start_velocity,
const double const double end_velocity, const double max_velocity, const double max_acceleration,
start_velocity,
const double end_velocity,
const double max_velocity,
const double
max_acceleration,
const bool reversed) { const bool reversed) {
const auto flipped_position = Pose2d{Translation2d{}, Rotation2d::FromDegrees(180.0)}; const auto flipped_position = Pose2d{Translation2d{}, Rotation2d::FromDegrees(180.0)};
@ -45,4 +40,4 @@ IndexedTrajectory<Pose2dWithCurvature> TrajectoryGenerator::TrajectoryFromSpline
return trajectory; return trajectory;
} }
} } // namespace fl

View File

@ -8,9 +8,9 @@
#include "fl/mathematics/geometry/Translation2d.h" #include "fl/mathematics/geometry/Translation2d.h"
#include "fl/mathematics/geometry/Twist2d.h" #include "fl/mathematics/geometry/Twist2d.h"
#include "fl/mathematics/control/PurePursuitTracker.h"
#include "fl/mathematics/control/RamseteTracker.h" #include "fl/mathematics/control/RamseteTracker.h"
#include "fl/mathematics/control/TrajectoryTracker.h" #include "fl/mathematics/control/TrajectoryTracker.h"
#include "fl/mathematics/control/PurePursuitTracker.h"
#include "fl/mathematics/spline/ParametricQuinticHermiteSpline.h" #include "fl/mathematics/spline/ParametricQuinticHermiteSpline.h"
#include "fl/mathematics/spline/ParametricSpline.h" #include "fl/mathematics/spline/ParametricSpline.h"

View File

@ -11,8 +11,7 @@ class PurePursuitTracker : public TrajectoryTracker {
const double min_lookahead_distance); const double min_lookahead_distance);
TrajectoryTrackerVelocityOutput CalculateState(const TimedIterator<Pose2dWithCurvature>& iterator, TrajectoryTrackerVelocityOutput CalculateState(const TimedIterator<Pose2dWithCurvature>& iterator,
const Pose2d& robot_pose) const const Pose2d& robot_pose) const override;
override;
private: private:
double lat_; double lat_;

View File

@ -28,8 +28,7 @@ class TimedEntry final : public VaryInterpolatable<TimedEntry<S>> {
if (delta_t < 0_s) return end_value.Interpolate(*this, 1.0 - t); if (delta_t < 0_s) return end_value.Interpolate(*this, 1.0 - t);
auto reversing = velocity_ < 0_mps || auto reversing = velocity_ < 0_mps || EpsilonEquals(velocity_, 0_mps) && acceleration_ < 0_mps_sq;
EpsilonEquals(velocity_, 0_mps) && acceleration_ < 0_mps_sq;
units::meters_per_second_t new_v = velocity_ + acceleration_ * delta_t; units::meters_per_second_t new_v = velocity_ + acceleration_ * delta_t;
units::meter_t new_s = units::meter_t new_s =

View File

@ -9,7 +9,7 @@ class Interpolatable {
virtual ~Interpolatable() = default; virtual ~Interpolatable() = default;
virtual T Interpolate(const T& end_value, double t) const = 0; virtual T Interpolate(const T& end_value, double t) const = 0;
template<typename T> template <typename T>
static constexpr T Lerp(const T& start_value, const T& end_value, const double t) { static constexpr T Lerp(const T& start_value, const T& end_value, const double t) {
return start_value + (end_value - start_value) * Clamp(t, 0.0, 1.0); return start_value + (end_value - start_value) * Clamp(t, 0.0, 1.0);
} }

View File

@ -7,30 +7,20 @@ class TrajectoryTest : public ::testing::Test {
public: public:
TrajectoryTest() {} TrajectoryTest() {}
void Run(fl::Pose2d initial, void Run(fl::Pose2d initial, fl::Pose2d final, double max_velocity = 3, double max_acceleration = 2,
fl::Pose2d final,
double max_velocity = 3,
double max_acceleration = 2,
bool backwards = false) { bool backwards = false) {
auto trajectory = fl::TrajectoryGenerator::GenerateTrajectory( auto trajectory = fl::TrajectoryGenerator::GenerateTrajectory(
std::vector<fl::Pose2d>{initial, final}, std::vector<fl::Pose2d>{initial, final},
std::vector<fl::TimingConstraint<fl::Pose2dWithCurvature>*>{}, std::vector<fl::TimingConstraint<fl::Pose2dWithCurvature>*>{}, 0.0, 0.0, max_velocity,
0.0, max_acceleration, backwards);
0.0,
max_velocity,
max_acceleration,
backwards);
auto pose = trajectory.Sample(units::second_t(0.0)).state.State().Pose(); auto pose = trajectory.Sample(units::second_t(0.0)).state.State().Pose();
EXPECT_FALSE(false); EXPECT_FALSE(false);
EXPECT_NEAR( EXPECT_NEAR(pose.Translation().X(), initial.Translation().X(), kTestEpsilon);
pose.Translation().X(), initial.Translation().X(), kTestEpsilon); EXPECT_NEAR(pose.Translation().Y(), initial.Translation().Y(), kTestEpsilon);
EXPECT_NEAR( EXPECT_NEAR(pose.Rotation().Radians(), initial.Rotation().Radians(), kTestEpsilon);
pose.Translation().Y(), initial.Translation().Y(), kTestEpsilon);
EXPECT_NEAR(
pose.Rotation().Radians(), initial.Rotation().Radians(), kTestEpsilon);
const auto iterator = trajectory.Iterator(); const auto iterator = trajectory.Iterator();
@ -55,8 +45,7 @@ class TrajectoryTest : public ::testing::Test {
EXPECT_NEAR(pose1.Translation().X(), final.Translation().X(), kTestEpsilon); EXPECT_NEAR(pose1.Translation().X(), final.Translation().X(), kTestEpsilon);
EXPECT_NEAR(pose1.Translation().Y(), final.Translation().Y(), kTestEpsilon); EXPECT_NEAR(pose1.Translation().Y(), final.Translation().Y(), kTestEpsilon);
EXPECT_NEAR( EXPECT_NEAR(pose1.Rotation().Radians(), final.Rotation().Radians(), kTestEpsilon);
pose1.Rotation().Radians(), final.Rotation().Radians(), kTestEpsilon);
} }
}; };