Skip to content

Commit

Permalink
Merge branch 'master' of git.lcsr.jhu.edu:mkobila1/gcop
Browse files Browse the repository at this point in the history
  • Loading branch information
marinkobi committed Jul 6, 2015
2 parents 60f785d + ac63468 commit 493b2f4
Show file tree
Hide file tree
Showing 18 changed files with 258 additions and 68 deletions.
4 changes: 2 additions & 2 deletions bin/BulletVehicleEstimation/VehicleDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class btCollisionShape;
#include <stdlib.h>

#include "point3dgps.h"
#include "gndoepv2.h"
#include "deterministicgndoep.h"
#include "params.h"
#include "lqsensorcost.h"
#include "utils.h"
Expand All @@ -41,7 +41,7 @@ using namespace Eigen;
class VehicleDemo : public GlutDemoApplication
{
typedef LqSensorCost<Vector4d, 4, 2, Dynamic, Dynamic, Vector3d, 3> RccarCost;
typedef GnDoep1<Vector4d, 4, 2, Dynamic, Dynamic, Vector3d, 3, Point3dState, 6> RccarDoep;
typedef GnDoep<Vector4d, 4, 2, Dynamic, Dynamic, Vector3d, 3, Point3dState, 6> RccarDoep;

protected:
int iters; //Number of iterations
Expand Down
4 changes: 2 additions & 2 deletions bin/BulletZVehicleTest/VehicleDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class btCollisionShape;
#include <stdlib.h>

#include "point3dgps.h"
#include "gndoepv2.h"
#include "deterministicgndoep.h"
#include "params.h"
#include "lqsensorcost.h"
#include "utils.h"
Expand All @@ -41,7 +41,7 @@ using namespace Eigen;
class VehicleDemo : public GlutDemoApplication
{
typedef LqSensorCost<Vector4d, 4, 2, Dynamic, 10, Vector3d, 3> RccarCost;
typedef GnDoep1<Vector4d, 4, 2, Dynamic, 10, Vector3d, 3, Point3dState, 6> RccarDoep;
typedef GnDoep<Vector4d, 4, 2, Dynamic, 10, Vector3d, 3, Point3dState, 6> RccarDoep;

protected:
int iters; //Number of iterations
Expand Down
9 changes: 8 additions & 1 deletion bin/body3dforceest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
#include "utils.h"
#include "so3.h"
#include "params.h"
#include "gndoep.h"
#include "sensor.h"
#include "insmanifold.h"

//#define USE_STOCHASTIC_DYNAMICS

#ifdef USE_STOCHASTIC_DYNAMICS
#include "gndoep.h"
#else
#include "deterministicgndoep.h"
#endif

using namespace std;
using namespace Eigen;
using namespace gcop;
Expand Down
4 changes: 2 additions & 2 deletions lib/algos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(headers
doep.h
gndocp.h
gndoep.h
gndoepv2.h
deterministicgndoep.h
pddp.h
ba.h
body2dslam.h
Expand Down Expand Up @@ -41,4 +41,4 @@ set(headers
${headers}
body3ddemcontroller.h
)
ENDIF (DSL_FOUND AND PQP_FOUND)
ENDIF (DSL_FOUND AND PQP_FOUND)
27 changes: 18 additions & 9 deletions lib/algos/gndoepv2.h → lib/algos/deterministicgndoep.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include <unsupported/Eigen/NonLinearOptimization>

/** GnDoep with deterministic dynamics
*/

namespace gcop {


Expand All @@ -32,7 +35,7 @@ namespace gcop {
int _nz = Dynamic,
typename T1 = T,
int _nx1 = _nx>
class GnDoep1 : public Doep<T, _nx, _nu, _np, Tz, _nz, T1, _nx1> {
class GnDoep : public Doep<T, _nx, _nu, _np, Tz, _nz, T1, _nx1> {

typedef Matrix<double, _ng, 1> Vectorgd;
typedef Matrix<double, _ng, _nx> Matrixgxd;
Expand Down Expand Up @@ -90,12 +93,12 @@ namespace gcop {
*/


GnDoep1(System<T, _nx, _nu, _np> &sys, Sensor<T1, _nx1, _nu, _np, Tz, _nz> &sensor,
GnDoep(System<T, _nx, _nu, _np> &sys, Sensor<T1, _nx1, _nu, _np, Tz, _nz> &sensor,
LqSensorCost<T, _nx, _nu, _np, _ng, Tz, _nz> &cost,
vector<double> &ts, vector<T> &xs, vector<Vectorcd> &us, Vectormd &p,
vector<double> &ts1, Func_type _project=NULL, bool update = true);

virtual ~GnDoep1();
virtual ~GnDoep();

/**
* Perform one DOCP iteration. Internally calls:
Expand Down Expand Up @@ -155,7 +158,7 @@ struct Functor
struct GnCost : Functor<double> {
GnCost<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1>(int inputs, int values) : Functor<double>(inputs, values) {};

GnDoep1<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1> *doep;
GnDoep<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1> *doep;

typedef Matrix<double, _nx, 1> Vectornd;
typedef Matrix<double, _np, 1> Vectormd;
Expand Down Expand Up @@ -212,9 +215,11 @@ struct Functor
{
std::cout<<"Input: "<<s.transpose()<<endl;
std::cout<<"Fvec: "<<fvec.transpose()<<endl;
std::cout<<"Cost: "<<0.5*(fvec.transpose()*fvec)<<endl;
//std::cout<<"Resp: "<<fvec.tail(np).transpose()<<"\t"<<doep->p<<endl;
}
std::cout<<"Cost: "<<0.5*(fvec.transpose()*fvec)<<endl;
doep->J = 0.5*(fvec.squaredNorm());//#TODO Directly from LevinBergMarquadt if possible
//getchar();
return 0;
}
};
Expand All @@ -223,7 +228,7 @@ struct Functor
using namespace Eigen;

template <typename T, int _nx, int _nu, int _np, int _ng, typename Tz, int _nz, typename T1, int _nx1>
GnDoep1<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1>::GnDoep1(System<T, _nx, _nu, _np> &sys, Sensor<T1, _nx1, _nu, _np, Tz, _nz> &sensor,
GnDoep<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1>::GnDoep(System<T, _nx, _nu, _np> &sys, Sensor<T1, _nx1, _nu, _np, Tz, _nz> &sensor,
LqSensorCost<T, _nx, _nu, _np, _ng, Tz, _nz> &cost,
vector<double> &ts,
vector<T> &xs,
Expand All @@ -245,15 +250,15 @@ struct Functor
}

template <typename T, int _nx, int _nu, int _np, int _ng, typename Tz, int _nz, typename T1, int _nx1>
GnDoep1<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1>::~GnDoep1()
GnDoep<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1>::~GnDoep()
{
delete lm;
delete numDiff;
delete functor;
}

template <typename T, int _nx, int _nu, int _np, int _ng, typename Tz, int _nz, typename T1, int _nx1>
void GnDoep1<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1>::Iterate() {
void GnDoep<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1>::Iterate() {

if (!lm) {
functor = new GnCost<T, _nx, _nu, _np, _ng, Tz, _nz, T1, _nx1>(inputs, values);
Expand All @@ -267,6 +272,10 @@ struct Functor

const int &np = this->sys.P.n;
s = this->p;//Set the system parameters to initial guess

lm->parameters.maxfev = 1e6;//Maximum nof evaluations is very high
info = lm->minimizeInit(s);
cout <<"info="<<info <<endl;
}

/*
Expand All @@ -277,7 +286,7 @@ struct Functor
*/

// lm.parameters.maxfev=10000;
info = lm->minimize(s);
info = lm->minimizeOneStep(s);

cout <<"info="<<info <<endl;
// check return values
Expand Down
18 changes: 14 additions & 4 deletions lib/algos/gndocp.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ using ceres::Solve;
* are updated.
*/
void Iterate();

void Reset();
Tparam<T, _nx, _nu, _np, _ntp> &tparam;

int info;
Expand Down Expand Up @@ -300,11 +302,11 @@ struct Functor
inputs(tparam.ntp),
values(cost.ng*xs.size()), s(inputs),
functor(0), numDiff(0), lm(0),
#ifndef USE_SAMPLE_NUMERICAL_DIFF
//#ifndef USE_SAMPLE_NUMERICAL_DIFF
numdiff_stepsize(1e-8)
#else
numdiff_stepsize(1e-4)
#endif
//#else
//numdiff_stepsize(1e-4)
//#endif
{
if(update)
this->Update(false);//No need of derivatives
Expand All @@ -323,6 +325,13 @@ struct Functor
delete numDiff;
delete functor;
}

template <typename T, int _nx, int _nu, int _np, int _ng, int _ntp>
void GnDocp<T, _nx, _nu, _np, _ng, _ntp>::Reset() {
delete lm;
lm = NULL;
return;
}

template <typename T, int _nx, int _nu, int _np, int _ng, int _ntp>
void GnDocp<T, _nx, _nu, _np, _ng, _ntp>::Iterate() {
Expand All @@ -339,6 +348,7 @@ struct Functor
#endif
*/
lm->parameters.maxfev = 1e6;//Maximum nof evaluations is very high
cout<<"Initializing..."<<endl;
info = lm->minimizeInit(s);
cout <<"info="<<info <<endl;
}
Expand Down
8 changes: 6 additions & 2 deletions lib/algos/gndoep.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,19 @@ struct Functor
vector<T> &xs,
vector<Vectorcd > &us,
Vectormd &p,
vector<double> &ts1,
vector<double> &ts1,
Func_type _project,
bool update) :
Doep<T, _nx, _nu, _np, Tz, _nz, T1, _nx1>(sys, sensor, cost, ts, xs, us, p, ts1, _project, update),
Doep<T, _nx, _nu, _np, Tz, _nz, T1, _nx1>(sys, sensor, cost, ts, xs, us, p, ts1, _project, false),
inputs(us.size()*sys.X.n + sys.P.n),
values((sys.X.n)*us.size()+(sensor.Z.n)*ts1.size()+sys.P.n), s(inputs),
functor(0), numDiff(0), lm(0)
{
cout <<"inputs=" <<inputs<<" values= "<<values<< endl;
if(update)
{
this->Update(false);
}
}

template <typename T, int _nx, int _nu, int _np, int _ng, typename Tz, int _nz, typename T1, int _nx1>
Expand Down
1 change: 1 addition & 0 deletions lib/systems/costs/lqsensorcost.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ namespace gcop {
Psqrt.resize(sys.P.n, sys.P.n);

dp.resize(sys.P.n);
dz.resize(Z.n);
}

R.setIdentity();
Expand Down
1 change: 1 addition & 0 deletions lib/systems/manifolds/mbsmanifold.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void MbsManifold::Lift(VectorXd &v,
assert(!std::isnan(xa.gs[0](0,0)));

int nb = xa.r.size() + 1;
assert(xb.r.size() == xa.r.size());

if (xa.fixed) {
v.head(nb - 1) = xb.r - xa.r;
Expand Down
19 changes: 19 additions & 0 deletions lib/systems/manifolds/mbsstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ namespace gcop {
r(x.r), dr(x.dr), ub(x.ub), lb(x.lb),
zl(x.zl), zu(x.zu), fixed(x.fixed) {
}

/*MbsState& operator = (const MbsState &x)
{
if(this != &x)
{
this->gs = x.gs;
this->vs = x.vs;
this->dgs = x.dgs;
this->r = x.r;
this->dr = x.dr;
this->ub = x.ub;
this->lb = x.lb;
this->zl = x.zl;
this->zu = x.zu;
this->fixed = x.fixed;
}
return *this;
}
*/

vector<Matrix4d> gs; ///< configurations
vector<Vector6d> vs; ///< body-fixed velocities
Expand Down
Loading

0 comments on commit 493b2f4

Please sign in to comment.