Skip to content

Merge my project: Real time iLQR control and SysID code into main branch #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c69805d
most updated version
Ericcsr Nov 4, 2021
f33f77f
Merge branch 'master' into ericcsr/ssid_dev
Ericcsr Nov 8, 2021
3751080
Implemented iLQR currently the TrajOpt is working
Ericcsr Nov 18, 2021
1e8e2d5
Cartpole is working
Ericcsr Nov 25, 2021
f0e8ec6
fixed issues in iLQR
Ericcsr Dec 6, 2021
a298f70
Add API of get contact free jacobian
Ericcsr Dec 10, 2021
038d7bc
add new file
Ericcsr Dec 10, 2021
3b0f6bd
add new file
Ericcsr Dec 10, 2021
3ffda57
Add new API
Ericcsr Dec 13, 2021
a85ea00
Add multi-link ssid
Ericcsr Dec 20, 2021
a972ee2
Fix merge problem
Ericcsr Dec 20, 2021
d665a71
Add new examples
Ericcsr Jan 2, 2022
a8fd28f
Enabled iLQR using cartesian loss
Ericcsr Jan 7, 2022
5496c0b
Cartpole Finished
Ericcsr Jan 19, 2022
c0b61c7
Enabled Inverted Double Pendulum experiment
Ericcsr Jan 19, 2022
ddf42df
Enabled Robotic Arm
Ericcsr Jan 22, 2022
7e9de01
Enabled elastic rod
Ericcsr Jan 24, 2022
3bc97ea
Added Active SysID control
Ericcsr Jan 25, 2022
e405408
Add Heuristic Control
Ericcsr Jan 26, 2022
3b5f676
Add heuristic for COM
Ericcsr Jan 26, 2022
3a92a98
Finalize Cartpole
Ericcsr Jan 27, 2022
298d9c7
Finalize Robot Arm
Ericcsr Jan 27, 2022
2d8d502
Finalize elastic rod
Ericcsr Jan 29, 2022
625fe67
Fix math error
Ericcsr Feb 5, 2022
d5dcf95
Fix merge confilct with elastic rod
Ericcsr Feb 5, 2022
d969468
Checkout for debug
Ericcsr Feb 5, 2022
6edad71
Merge local branch
Ericcsr Feb 5, 2022
fedbe3b
Merge branch 'master' into robot_arm
Ericcsr Feb 5, 2022
6b5360a
Fixed blocking issue of realtime test cases
Ericcsr Feb 5, 2022
ebb3780
Fix CI issue in world cloning
Ericcsr Feb 5, 2022
7c96f2e
Merge branch 'master' into robot_arm
Ericcsr Feb 5, 2022
97c6999
add unittest for all ssid
Ericcsr Feb 14, 2022
007fc18
Merge branch 'robot_arm' of https://github.com/keenon/nimblephysics i…
Ericcsr Feb 14, 2022
2aed6f9
Fix merge problem
Ericcsr Feb 14, 2022
8aaa300
Fixed issue related to PR
Ericcsr Feb 18, 2022
8007fd5
Better API for realrobot experiment
Ericcsr Sep 30, 2022
57ad0ed
Adding new experiments
Ericcsr Nov 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion dart/dynamics/Skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3159,7 +3159,7 @@ Eigen::VectorXs Skeleton::getLinkMOIs()
return inertias;
}

// TODO: Check The Sign of MOI
//==============================================================================
Eigen::Matrix3s Skeleton::getMOIMatrix(Eigen::Vector6s moi_vector)
{
Eigen::Matrix3s MOI = moi_vector.segment(0,3).asDiagonal();
Expand All @@ -3172,6 +3172,7 @@ Eigen::Matrix3s Skeleton::getMOIMatrix(Eigen::Vector6s moi_vector)
return MOI;
}

//==============================================================================
Eigen::Vector6s Skeleton::getLinkMOIIndex(size_t index)
{
Eigen::Vector6s inertia = Eigen::Vector6s::Zero();
Expand Down
20 changes: 17 additions & 3 deletions dart/dynamics/Skeleton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,21 +862,29 @@ class Skeleton : public virtual common::VersionCounter,
// This get particular moment of inertia of a body node
Eigen::Vector6s getLinkMOIIndex(size_t index);

// This get all body nodes' moment of inertia in a matrix
Eigen::Matrix3s getMOIMatrix(Eigen::Vector6s moi_vector);

// This returns a vector of all the link masses for all the links in this
// skeleton concatenated into a flat vector.
Eigen::VectorXs getLinkMasses();

// This returns a matrix of A_k as describe in Karen's paper
// This returns a matrix of A_k as describe in paper
// https://arxiv.org/pdf/1907.03964.pdf
// You can see detailed description of this matrix in the last appendix
// section of this paper.
Eigen::MatrixXs getLinkAkMatrixIndex(size_t index);

// This returns a jacobian matrix of velocity connect between world and joint coordinate
Eigen::MatrixXs getLinkJvkMatrixIndex(size_t index);

// This returns a jacobian matrix of angular velocity connect between world and joint coordinate
Eigen::MatrixXs getLinkJwkMatrixIndex(size_t index);

// This returns a rotation matrix of body node wrt to world coordinate
Eigen::Matrix3s getLinkRMatrixIndex(size_t index);

// This returns a jacobian matrix of angular velocity connect between world and joint coordiante
Eigen::MatrixXs getLinkLocalJwkMatrixIndex(size_t index);

// Sets the upper limits of all the joints from a single vector
Expand Down Expand Up @@ -905,20 +913,26 @@ class Skeleton : public virtual common::VersionCounter,

void setLinkBetas(Eigen::VectorXs betas);

// This sets all the inertia center-of-mass vectors for all the links in this
// This sets all the COM vectors for all the links in this
// skeleton concatenated together
void setLinkCOMs(Eigen::VectorXs coms);

// This set COM of a particular body node specified by index.
void setLinkCOMIndex(Eigen::Vector3s com, size_t index);

void setLinkDiagIs(Eigen::VectorXs coms);
// This set all the diagonal term of moment of inertias.
void setLinkDiagIs(Eigen::VectorXs mois);

// This set diagonal term of moment of inertia of a particular
// body node specified by index
void setLinkDiagIIndex(Eigen::Vector3s com, size_t index);

// This sets all the inertia moment-of-inertia paremeters for all the links in
// this skeleton concatenated together
void setLinkMOIs(Eigen::VectorXs mois);

// This set moment of inertia of a particular body node specified
// by index.
void setLinkMOIIndex(Eigen::Vector6s moi, size_t index);

// This returns a vector of all the link masses for all the links in this
Expand Down
83 changes: 0 additions & 83 deletions dart/neural/BackpropSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,89 +1027,6 @@ const Eigen::MatrixXs& BackpropSnapshot::getContactFreeVelVelJacobian(
return mCachedContactFreeVelVel;
}

//==============================================================================
/*
const Eigen::MatrixXs& BackpropSnapshot::getContactReducedVelVelJacobian(
WorldPtr world, Eigen::VectorXs index, PerformanceLog* perfLog)
{
#ifndef NDEBUG
assert(
world->getPositions() == mPreStepPosition
&& world->getVelocities() == mPreStepVelocity);
#endif

PerformanceLog* thisLog = nullptr;
#ifdef LOG_PERFORMANCE_BACKPROP_SNAPSHOT
if (perfLog != nullptr)
{
thisLog = perfLog->startRun("BackpropSnapshot.getVelVelJacobian");
}
#endif

if (mCachedVelVelDirty)
{
PerformanceLog* refreshLog = nullptr;
#ifdef LOG_PERFORMANCE_BACKPROP_SNAPSHOT
if (thisLog != nullptr)
{
refreshLog = thisLog->startRun(
"BackpropSnapshot.getVelVelJacobian#refreshCache");
}
#endif

if (mUseFDOverride)
{
mCachedVelVel = finiteDifferenceVelVelJacobian(world);
}
else
{
Eigen::VectorXs ddamp = getDampingVector(world);
Eigen::VectorXs spring_stiffs = getSpringStiffVector(world);
Eigen::MatrixXs Minv = getInvMassMatrix(world);
s_t dt = world->getTimeStep();
Eigen::MatrixXs A_c = getClampingConstraintMatrix(world);

// If there are no clamping constraints, then vel-vel is just the identity
if (A_c.size() == 0)
{
mCachedVelVel = Eigen::MatrixXs::Identity(mNumDOFs, mNumDOFs)
- dt * Minv * ddamp.asDiagonal()
- dt * dt * Minv * spring_stiffs.asDiagonal()
- dt * Minv * getVelCJacobian(world);
}
else
{

mCachedVelVel = getVelJacobianWrt(world, WithRespectTo::VELOCITY)
- dt * Minv * ddamp.asDiagonal()
- dt * dt * Minv * spring_stiffs.asDiagonal();
}
}

if (mSlowDebugResultsAgainstFD)
{
Eigen::MatrixXs bruteForce = finiteDifferenceVelVelJacobian(world);
equalsOrCrash(world, mCachedVelVel, bruteForce, "vel-vel");
}

mCachedVelVelDirty = false;
#ifdef LOG_PERFORMANCE_BACKPROP_SNAPSHOT
if (refreshLog != nullptr)
{
refreshLog->end();
}
#endif
}

#ifdef LOG_PERFORMANCE_BACKPROP_SNAPSHOT
if (thisLog != nullptr)
{
thisLog->end();
}
#endif
return mCachedVelVel;
}
*/
//==============================================================================
const Eigen::MatrixXs& BackpropSnapshot::getPosVelJacobian(
WorldPtr world, PerformanceLog* perfLog)
Expand Down
50 changes: 26 additions & 24 deletions dart/neural/BackpropSnapshot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,39 @@ class BackpropSnapshot
const Eigen::MatrixXs& getVelVelJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

/// This computes and returns the whole vel-vel jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
/// This assume all contact constraints are separating.
const Eigen::MatrixXs& getContactFreeVelVelJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

/// Index should specify which contact will be kept
const Eigen::MatrixXs& getContactReducedVelVelJacobian(
simulation::WorldPtr world, Eigen::VectorXs indexs, PerformanceLog* perfLog = nullptr);

/// This computes and returns the whole pos-vel jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
const Eigen::MatrixXs& getPosVelJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

/// This computes and returns the whole pos-vel jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
/// This assume all contact constraints are separating.
const Eigen::MatrixXs& getContactFreePosVelJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

const Eigen::MatrixXs& getContactReducedPosVelJacobian(
simulation::WorldPtr world, Eigen::VectorXs indexs, PerformanceLog* perfLog = nullptr);

/// This computes and returns the whole force-vel jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
const Eigen::MatrixXs& getControlForceVelJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

/// This computes and returns the whole force-vel jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
/// This assume all contact constraints are separating.
const Eigen::MatrixXs& getContactFreeControlForceVelJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

const Eigen::MatrixXs& getContactReducedCControlForceVelJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

/// This computes and returns the whole mass-vel jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
Expand All @@ -125,6 +127,10 @@ class BackpropSnapshot
const Eigen::MatrixXs& getPosPosJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

/// This computes and returns the whole pos-pos jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
/// This assume all contact constraints are separating.
const Eigen::MatrixXs& getContactFreePosPosJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

Expand All @@ -134,6 +140,11 @@ class BackpropSnapshot
const Eigen::MatrixXs& getVelPosJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);


/// This computes and returns the whole pos-pos jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
/// This assume all contact constraints are separating
const Eigen::MatrixXs& getContactFreeVelPosJacobian(
simulation::WorldPtr world, PerformanceLog* perfLog = nullptr);

Expand All @@ -147,20 +158,17 @@ class BackpropSnapshot
/// This returns the Jacobian for state_t -> state_{t+1}.
Eigen::MatrixXs getStateJacobian(simulation::WorldPtr world);

/// This returns the Jacobian for state_t -> state_{t+1}
/// This assume all contact constraints are separating.
Eigen::MatrixXs getContactFreeStateJacobian(simulation::WorldPtr world);

Eigen::MatrixXs getContactReducedStateJacobian(
simulation::WorldPtr world,
Eigen::VectorXs indexs);

/// This returns the Jacobian for action_t -> state_{t+1}.
Eigen::MatrixXs getActionJacobian(simulation::WorldPtr world);


/// This returns the Jacobian for action_t -> state_{t+1}.
/// This assume all contact constraints are separating.
Eigen::MatrixXs getContactFreeActionJacobian(simulation::WorldPtr world);

Eigen::MatrixXs getContactReducedActionJacobian(
simulation::WorldPtr world,
Eigen::VectorXs indexs);
/// Returns a concatenated vector of all the Skeletons' position()'s in the
/// World, in order in which the Skeletons appear in the World's
/// getSkeleton(i) returns them, BEFORE the timestep.
Expand Down Expand Up @@ -347,12 +355,6 @@ class BackpropSnapshot
Eigen::MatrixXs getVelJacobianWrt(
simulation::WorldPtr world, WithRespectTo* wrt);

/// This computes and returns the whole wrt-vel jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason
Eigen::MatrixXs getContactReducedVelJacobianWrt(
simulation::WorldPtr world, WithRespectTo* wrt, Eigen::VectorXs index);

/// This computes and returns the whole wrt-pos jacobian. For backprop, you
/// don't actually need this matrix, you can compute backprop directly. This
/// is here if you want access to the full Jacobian for some reason.
Expand Down
12 changes: 6 additions & 6 deletions dart/realtime/RealTimeControlBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ class RealTimeControlBuffer
/// This is the B buffer of forces
Eigen::MatrixXs mBufB;

// This is the A buffer of k
// This is the A buffer of k, which is feed forward gain in iLQR
Eigen::MatrixXs mkBufA;

// This is the B buffer of k
// This is the B buffer of k, which is feed forward gain in iLQR
Eigen::MatrixXs mkBufB;

// This is the A buffer of K
// This is the A buffer of K, which is feedback gain in iLQR
std::vector<Eigen::MatrixXs> mKBufA;

// This is the B buffer of K
// This is the B buffer of K, which is feedback gain in iLQR
std::vector<Eigen::MatrixXs> mKBufB;

// This is the A buffer of State
Expand All @@ -150,10 +150,10 @@ class RealTimeControlBuffer

Eigen::MatrixXs mxBufB;

// This is the A buffer of Alpha
// This is the A buffer of Alpha, which is line search learning rate in iLQR
Eigen::VectorXs mAlphaBufA;

// This is the B buffer of Alpha
// This is the B buffer of Alpha, , which is line search learning rate in iLQR
Eigen::VectorXs mAlphaBufB;

/// This is the time when the last buffer was written to
Expand Down
2 changes: 2 additions & 0 deletions unittests/comprehensive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ if(TARGET dart-utils)
target_link_libraries(test_cartpoleRealtime dart-utils-urdf)
target_link_libraries(test_iLQRRealtime dart-utils)
target_link_libraries(test_iLQRRealtime dart-utils-urdf)
target_link_libraries(test_iLQR dart-utils)
target_link_libraries(test_iLQR dart-utils-urdf)

dart_add_test("comprehensive" test_Gradients)
target_link_libraries(test_Gradients dart-utils-urdf)
Expand Down
Loading