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-09-28 18:40:56 -04:00
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "frc/kinematics/DifferentialDriveKinematics.h"
|
|
|
|
|
#include "frc/trajectory/constraint/DifferentialDriveKinematicsConstraint.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "trajectory/TestTrajectory.h"
|
2020-08-06 23:57:39 -07:00
|
|
|
#include "units/time.h"
|
2019-09-28 18:40:56 -04:00
|
|
|
|
|
|
|
|
using namespace frc;
|
|
|
|
|
|
|
|
|
|
TEST(DifferentialDriveKinematicsConstraintTest, Constraint) {
|
|
|
|
|
const auto maxVelocity = 12_fps;
|
|
|
|
|
const DifferentialDriveKinematics kinematics{27_in};
|
|
|
|
|
|
2019-10-26 12:39:47 -04:00
|
|
|
auto config = TrajectoryConfig(12_fps, 12_fps_sq);
|
|
|
|
|
config.AddConstraint(
|
|
|
|
|
DifferentialDriveKinematicsConstraint(kinematics, maxVelocity));
|
2019-09-28 18:40:56 -04:00
|
|
|
|
2019-10-26 12:39:47 -04:00
|
|
|
auto trajectory = TestTrajectory::GetTrajectory(config);
|
2019-09-28 18:40:56 -04:00
|
|
|
|
|
|
|
|
units::second_t time = 0_s;
|
|
|
|
|
units::second_t dt = 20_ms;
|
|
|
|
|
units::second_t duration = trajectory.TotalTime();
|
|
|
|
|
|
|
|
|
|
while (time < duration) {
|
|
|
|
|
const Trajectory::State point = trajectory.Sample(time);
|
|
|
|
|
time += dt;
|
|
|
|
|
|
|
|
|
|
const ChassisSpeeds chassisSpeeds{point.velocity, 0_mps,
|
|
|
|
|
point.velocity * point.curvature};
|
|
|
|
|
|
|
|
|
|
auto [left, right] = kinematics.ToWheelSpeeds(chassisSpeeds);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(left < maxVelocity + 0.05_mps);
|
|
|
|
|
EXPECT_TRUE(right < maxVelocity + 0.05_mps);
|
|
|
|
|
}
|
|
|
|
|
}
|