EmbeddedSmoother_Test.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include "robodyn_mechanisms/EmbeddedSmoother.h"
00003 #include <auto_ptr.h>
00004 #include <fstream>
00005 
00006 class EmbeddedSmootherTest : public ::testing::Test
00007 {
00008 protected:
00009     virtual void SetUp()
00010     {
00011         settings.timestep = 0.03;
00012         settings.accGain  = 1000;
00013         settings.maxAcc   = 2;
00014         settings.minVel   = 0.01;
00015         smoother.reset(new EmbeddedSmoother(settings));
00016     }
00017 
00018     virtual void TearDown()
00019     {
00020     }
00021 
00022     std::auto_ptr<EmbeddedSmoother> smoother;
00023     EmbeddedSmoother::Settings settings;
00024 };
00025 
00026 TEST_F(EmbeddedSmootherTest, reset)
00027 {
00028     double ret;
00029     ret = smoother->reset(.5, 0.);
00030     EXPECT_EQ(.5, ret);
00031 
00032     ret = smoother->reset(1., 0.);
00033     EXPECT_EQ(1., ret);
00034 }
00035 
00036 TEST_F(EmbeddedSmootherTest, update)
00037 {
00038     double ret, ret2;
00039     ret = smoother->reset(.5, 0.);
00040     ret = smoother->update(1., 0.);
00041 
00042     // should be moving towards goal despite 0 velocity
00043     EXPECT_GT(ret, .5);
00044 
00045     // shouldn't be able to achieve a velocity of 1 in one timestep
00046     ret = smoother->reset(.5, 0.);
00047     ret = smoother->update(1., 1.);
00048     EXPECT_LT(ret, .5 + settings.timestep * 1.);
00049 
00050     // should continually make progress with minimal overshoot
00051     ret = smoother->reset(.5, 0.);
00052     unsigned int it = 0;
00053 
00054     do
00055     {
00056         ret2 = ret;
00057         ++it;
00058         ret = smoother->update(1., 1.);
00059         EXPECT_GE(ret, ret2);
00060 
00061     }
00062     while (ret2 != ret && it < 10000);
00063 
00064     EXPECT_LT(it, 10000);
00065     EXPECT_GE(ret, 1.);
00066     EXPECT_NEAR(ret - 1., 0.5 * 1. / settings.maxAcc, 0.01);
00067 }
00068 
00069 int main(int argc, char** argv)
00070 {
00071     testing::InitGoogleTest(&argc, argv);
00072     return RUN_ALL_TESTS();
00073 }


robodyn_mechanisms
Author(s):
autogenerated on Thu Jun 6 2019 21:22:48