[roboptim-commit] [SCM] roboptim-trajectory branch, master, updated. v0.2-22-ga38a277
Status: Beta
Brought to you by:
flamiraux
From: Thomas M. <tho...@us...> - 2009-11-06 12:11:31
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "roboptim-trajectory". The branch, master has been updated via a38a277e6553f4ba509ca607863ad9f9ffdcc390 (commit) from 5203a96bf71f39bc3ada5b89b0c6b42e8726b405 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit a38a277e6553f4ba509ca607863ad9f9ffdcc390 Author: Thomas Moulard <tho...@gm...> Date: Fri Nov 6 13:11:12 2009 +0100 Check scaling functions in FreeTimeTrajectory test. * include/roboptim/trajectory/free-time-trajectory.hh: Make scaleTime and unscaleTime public. * tests/free-time-trajectory.cc: Check scaling functions. * tests/free-time-trajectory.stdout: Regenerate. Signed-off-by: Thomas Moulard <tho...@gm...> diff --git a/ChangeLog b/ChangeLog index 1e9ffb2..22bc76c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-11-06 Thomas Moulard <tho...@gm...> + + Check scaling functions in FreeTimeTrajectory test. + * include/roboptim/trajectory/free-time-trajectory.hh: + Make scaleTime and unscaleTime public. + * tests/free-time-trajectory.cc: Check scaling functions. + * tests/free-time-trajectory.stdout: Regenerate. + 2009-11-05 Thomas Moulard <tho...@gm...> Add missing semi-colon in Spline class. diff --git a/include/roboptim/trajectory/free-time-trajectory.hh b/include/roboptim/trajectory/free-time-trajectory.hh index f0d6ba5..28ee40e 100644 --- a/include/roboptim/trajectory/free-time-trajectory.hh +++ b/include/roboptim/trajectory/free-time-trajectory.hh @@ -136,12 +136,7 @@ namespace roboptim assert (trajectory_); return trajectory_->resize (this->timeRange ()); } - protected: - void impl_compute (result_t&, double) const throw (); - void impl_derivative (gradient_t& g, double x, size_type order) - const throw (); - private: /// \brief Scale input time argument. /// /// Scale input argument with the same factor that the input @@ -155,6 +150,12 @@ namespace roboptim double scaleTime (double t) const throw (); double unscaleTime (double t) const throw (); + protected: + void impl_compute (result_t&, double) const throw (); + void impl_derivative (gradient_t& g, double x, size_type order) + const throw (); + + private: /// \brief Input fixed time trajectory. Trajectory<DerivabilityOrder>* trajectory_; }; diff --git a/tests/free-time-trajectory.cc b/tests/free-time-trajectory.cc index 0750bf9..bee5619 100644 --- a/tests/free-time-trajectory.cc +++ b/tests/free-time-trajectory.cc @@ -38,6 +38,12 @@ using namespace roboptim; typedef FreeTimeTrajectory<Spline::derivabilityOrder> freeTime_t; +template <typename T> +bool isAlmostEqual (const T& x, const T& y, const T& epsilon = 1e10-8) +{ + return (x - y) * (x - y) < epsilon; +} + struct ConfigWrtParam : public DerivableFunction { ConfigWrtParam (const freeTime_t& traj, double t) throw () @@ -253,6 +259,7 @@ void printTable (const Spline& spline, const freeTime_t& freeTimeTraj) int run_test () { + typedef Spline::value_type value_type; Spline::vector_t params (5); // Scale. @@ -274,6 +281,61 @@ int run_test () assert (freeTimeTraj.inputSize () == 1); assert (freeTimeTraj.outputSize () == 1); + // Check scaling and unscaling. + { + params[0] = 3.14; + freeTimeTraj.setParameters (params); + value_type t = 0.32; + StableTimePoint stp (t / freeTimeTraj.length ()); + + std::cout << "Checking StableTimePoint scaling." << std::endl; + assert (isAlmostEqual + (stp.getTime (freeTimeTraj.timeRange ()), t)); + + std::cout << "Checking scale/unscale methods." << std::endl; + assert (isAlmostEqual + (freeTimeTraj.unscaleTime (freeTimeTraj.scaleTime (t)), t)); + + std::cout << "Checking scale using tmin/tmax." << std::endl; + value_type tMin = Function::getLowerBound (freeTimeTraj.timeRange ()); + value_type tMax = Function::getUpperBound (freeTimeTraj.timeRange ()); + + value_type tmin = Function::getLowerBound + (freeTimeTraj.getFixedTimeTrajectory ().timeRange ()); + value_type tmax = Function::getUpperBound + (freeTimeTraj.getFixedTimeTrajectory ().timeRange ()); + + assert (tmax != tMax); // Just to be sure a real scaling is done. + + assert (isAlmostEqual (freeTimeTraj.scaleTime (tMin), tmin)); + assert (isAlmostEqual (freeTimeTraj.scaleTime (tMax), tmax)); + + assert (isAlmostEqual (freeTimeTraj.unscaleTime (tmin), tMin)); + assert (isAlmostEqual (freeTimeTraj.unscaleTime (tmax), tMax)); + + assert (isAlmostEqual (freeTimeTraj.unscaleTime ((tmax - tmin) / 2.), + (tMax - tMin) / 2.)); + assert (isAlmostEqual (freeTimeTraj.unscaleTime ((tmax - tmin) / 4.), + (tMax - tMin) / 4.)); + + + std::cout << "Checking StableTimePoint scaling." << std::endl; + assert (isAlmostEqual + ((0. * roboptim::tMax).getTime (freeTimeTraj.timeRange ()), tmin)); + assert (isAlmostEqual + ((1. * roboptim::tMax).getTime (freeTimeTraj.timeRange ()), tmax)); + assert (isAlmostEqual + ((.5 * roboptim::tMax).getTime (freeTimeTraj.timeRange ()), + (tmax - tmin) / 2.)); + assert (isAlmostEqual + ((.25 * roboptim::tMax).getTime (freeTimeTraj.timeRange ()), + (tmax - tmin) / 4.)); + + } + + + params[0] = 1.; + freeTimeTraj.setParameters (params); printTable (spline, freeTimeTraj); params[0] = .5; diff --git a/tests/free-time-trajectory.stdout b/tests/free-time-trajectory.stdout index 5c55044..0c7ed72 100644 --- a/tests/free-time-trajectory.stdout +++ b/tests/free-time-trajectory.stdout @@ -1,3 +1,7 @@ +Checking StableTimePoint scaling. +Checking scale/unscale methods. +Checking scale using tmin/tmax. +Checking StableTimePoint scaling. Spline range: [0, 4] FTT range: [0, 4] /------------------------------------------------------------------------------\ ----------------------------------------------------------------------- Summary of changes: ChangeLog | 8 +++ .../roboptim/trajectory/free-time-trajectory.hh | 11 ++-- tests/free-time-trajectory.cc | 62 ++++++++++++++++++++ tests/free-time-trajectory.stdout | 4 + 4 files changed, 80 insertions(+), 5 deletions(-) hooks/post-receive -- roboptim-trajectory |