diff --git a/src/lib/FlightTasks/tasks/Utility/Makefile b/src/lib/FlightTasks/tasks/Utility/Makefile new file mode 100644 index 0000000000..df018d73ab --- /dev/null +++ b/src/lib/FlightTasks/tasks/Utility/Makefile @@ -0,0 +1,12 @@ + +.PHONY: all tests clean +all: test_velocity_smoothing + +test_velocity_smoothing: test_velocity_smoothing.cpp VelocitySmoothing.cpp + @g++ $^ -std=c++11 -I ../../../ -o $@ + +tests: test_velocity_smoothing + @echo "Test velocity smoothing" + +clean: + @rm test_velocity_smoothing diff --git a/src/lib/FlightTasks/tasks/Utility/test_velocity_smoothing.cpp b/src/lib/FlightTasks/tasks/Utility/test_velocity_smoothing.cpp new file mode 100644 index 0000000000..de2d8f3ea3 --- /dev/null +++ b/src/lib/FlightTasks/tasks/Utility/test_velocity_smoothing.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** + * + * Copyright (c) 2018 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/** + * Test code for the Velocity Smoothing library + * Build and run using: make && ./test_velocity_smoothing + */ + +#include "VelocitySmoothing.hpp" +#include + +int main(int argc, char *argv[]) +{ + VelocitySmoothing trajectory[3]; + + float a0[3] = {0.22, 0.f, 0.22f}; + float v0[3] = {2.47f, -5.59e-6f, 2.47f}; + float x0[3] = {0.f, 0.f, 0.f}; + + float j_max = 55.2f; + float a_max = 6.f; + float v_max = 6.f; + + for (int i = 0; i < 3; i++) { + trajectory[i].setMaxJerk(j_max); + trajectory[i].setMaxAccel(a_max); + trajectory[i].setMaxVel(v_max); + trajectory[i].setCurrentAcceleration(a0[i]); + trajectory[i].setCurrentVelocity(v0[i]); + } + + float dt = 0.01f; + + float velocity_setpoint[3] = {0.f, 1.f, 0.f}; + + for (int i = 0; i < 3; i++) { + trajectory[i].updateDurations(dt, velocity_setpoint[i]); + } + + VelocitySmoothing::timeSynchronization(trajectory, 2); + + for (int i = 0; i < 3; i++) { + trajectory[i].integrate(a0[i], v0[i], x0[i]); + } + + for (int i = 0; i < 3; i++) { + printf("Traj[%d]\n", i); + printf("jerk = %.3f\taccel = %.3f\tvel = %.3f\n", trajectory[i].getCurrentJerk(), + trajectory[i].getCurrentAcceleration(), trajectory[i].getCurrentVelocity()); + printf("T1 = %.3f\tT2 = %.3f\tT3 = %.3f\n", trajectory[i].getT1(), trajectory[i].getT2(), trajectory[i].getT3()); + printf("\n"); + } + + return 0; +}