Skip to content
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

Eradicating memory leaks & making classes copy-safe and clonable #369

Merged
merged 154 commits into from Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from 152 commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
a629753
created Inertia class
mxgrey Mar 25, 2015
446014d
offloading data into property structs
mxgrey Mar 26, 2015
0658888
Merge branch 'master' into memory_management
mxgrey Mar 26, 2015
5e16a07
starting to change Shape ptrs to shared_ptrs
mxgrey Mar 26, 2015
98573eb
using shared_ptrs for Shapes
mxgrey Mar 26, 2015
4ba7e64
changed collision shapes to use shared_ptrs
mxgrey Mar 26, 2015
96769ee
need to fix collisions
mxgrey Mar 26, 2015
a38547e
the collision fix was obvious
mxgrey Mar 26, 2015
2f22467
fixed indexing issue for inertia
mxgrey Mar 26, 2015
b479c30
removed pointers from Properties
mxgrey Mar 26, 2015
e76fbe0
finished Properties for BodyNode
mxgrey Mar 26, 2015
e81642a
creating new constructor for BodyNode
mxgrey Mar 26, 2015
9dad4be
use std::array to work around VS2013 bug
mxgrey Mar 26, 2015
9704b68
creating Joint Properties struct
mxgrey Mar 26, 2015
64ade0a
adding Properties structs to Joint classes
mxgrey Mar 27, 2015
7e7c889
created Properties classes for all Joint types
mxgrey Mar 28, 2015
da507de
creating memory-safe pipeline for creating BodyNodes and Joints
mxgrey Mar 28, 2015
c8e7b6c
created SoftBodyNode::Properties and PointMass::Properties
mxgrey Mar 28, 2015
3d5881e
flipped faces for the sake of right-handedness
mxgrey Mar 28, 2015
56d2d33
modifying SoftBodyNodeHelper to fill in SoftBodyNode::Properties inst…
mxgrey Mar 28, 2015
b233ad2
finished makeBoxProperties
mxgrey Mar 28, 2015
a2a039f
debugging SoftBodies
mxgrey Mar 28, 2015
4fc9c94
fixed SoftBody bug
mxgrey Mar 28, 2015
6888893
created compatible constructors for all types
mxgrey Mar 29, 2015
ccd0602
using shared_ptrs for Skeletons and overhauling the sdf parsers -- no…
mxgrey Mar 29, 2015
58e97f7
major overhaul to SdfParser (practically a rewrite)
mxgrey Mar 30, 2015
449a0bb
overhauled URDF parsing
mxgrey Mar 30, 2015
7914df3
moved DOF names into Joint Properties
mxgrey Mar 31, 2015
17a32d7
overhauled SkelParser -- needs debugging
mxgrey Apr 2, 2015
1199d67
the new skeleton parsing will not necessarily order Joints according …
mxgrey Apr 2, 2015
e615aea
keeping the parsed file's joint order on a best-effort basis
mxgrey Apr 2, 2015
062a352
more warnings and cleaner template usage
mxgrey Apr 2, 2015
49b274e
resizing data structures add nodes are added
mxgrey Apr 2, 2015
526ca6f
print out which world and skeleton failed
mxgrey Apr 2, 2015
a011da1
bug fix: initializing data structures
mxgrey Apr 2, 2015
8e06164
fixed initialization of SoftBodyNodes
mxgrey Apr 2, 2015
e84797d
putting 'typename' in front of the typename to see if it helps VS com…
mxgrey Apr 3, 2015
c4971ff
attempting to make the code VS compatible
mxgrey Apr 3, 2015
69ff775
forgot about TranslationalJoint
mxgrey Apr 3, 2015
4432a95
using shared_ptr for World now
mxgrey Apr 6, 2015
23b9e61
merged in latest master
mxgrey Apr 6, 2015
440b7c3
allowing World to store SimpleFrames instead of arbitrary Entities, a…
mxgrey Apr 6, 2015
6f0c941
added properties and copying to SimpleFrames
mxgrey Apr 6, 2015
92fa931
created copy constructor for SimpleFrame
mxgrey Apr 6, 2015
c3faa2c
removed properties for SimpleFrame, because they were really state, n…
mxgrey Apr 6, 2015
1cd828c
created clone functions for BodyNodes and Joints
mxgrey Apr 7, 2015
c61dacd
implemented cloning for Skeletons
mxgrey Apr 7, 2015
fb142f1
implemented cloning of worlds and name management for Skeletons and S…
mxgrey Apr 8, 2015
fff1f9c
created Properties class for Skeleton
mxgrey Apr 8, 2015
f6cf921
fixed timestep cloning
mxgrey Apr 8, 2015
d0fe461
fixed SoftBodyNode cloning
mxgrey Apr 8, 2015
370a333
created test to ensure that World clones are deterministic
mxgrey Apr 9, 2015
bb9be3d
made test a bit shorter for debug mode
mxgrey Apr 9, 2015
5ee2403
removed final memory leaks from DART, according to valgrind
mxgrey Apr 9, 2015
efd4bd5
cleaning up deprecated functions
mxgrey Apr 9, 2015
34c5f3a
more cleanup -- I believe all uses of deprecated constructors have be…
mxgrey Apr 10, 2015
6fc059d
removed test that intentionally throws exception in debug mode
mxgrey Apr 10, 2015
c04faa1
unhid the GenCoordInfo deprecation and removed outdated mGravity member
mxgrey Apr 15, 2015
ed35861
Using shared_ptr for Shape in BulletCollisionNode
jslee02 Apr 23, 2015
1130d27
write API for BodyNode transfers
mxgrey Apr 24, 2015
d0764aa
implementing BodyNode transfer
mxgrey Apr 24, 2015
4f32765
implemented BodyNode transfer -- needs testing
mxgrey Apr 25, 2015
91ed8fc
made some adjustments and bug fixes
mxgrey Apr 28, 2015
2648d4a
minor efficiency adjustments
mxgrey Apr 28, 2015
b1066e2
implemented a variety of move and copy functions -- need testing
mxgrey Apr 29, 2015
536e777
did some debugging and wrote some tests -- could use more testing
mxgrey Apr 30, 2015
98d02de
debugged BodyNode transfer and wrote unit tests
mxgrey May 1, 2015
298450f
created factory for Skeletons
mxgrey May 4, 2015
1dbeafa
faster runtimes for unit tests in debug mode
mxgrey May 4, 2015
4ad76eb
removed raw Skeleton pointers from the BodyNode API
mxgrey May 4, 2015
046820d
removed raw Skeleton pointers from Joint API
mxgrey May 4, 2015
e09f223
reducing amplitude so results get within the tolerance
mxgrey May 4, 2015
8b87b1d
changed the behavior of BodyNode removal
mxgrey May 5, 2015
6d64995
created a BodyNodePtr that keeps BodyNodes alive
mxgrey May 5, 2015
d601569
handling edge case where a Skeleton is deleted while a BodyNodePtr is…
mxgrey May 5, 2015
c60baa5
creating thread safe strong and weak BodyNodePtrs with minimal overhead
mxgrey May 6, 2015
adf63f4
thread safe and efficient strong and weak ptrs for BodyNodes
mxgrey May 6, 2015
56e2c2a
short-circuting any unnecessary move attempts
mxgrey May 7, 2015
f5f81d9
abstracting out the Skeleton API
mxgrey May 11, 2015
f74a114
moved more into MetaSkeleton API -- not finished
mxgrey May 12, 2015
1d0c4e7
finished porting API to MetaSkeleton
mxgrey May 12, 2015
44fe5ab
fixed callback bug
mxgrey May 12, 2015
35725fc
offloaded some implementation into MetaSkeleton
mxgrey May 12, 2015
2f2c527
splitting Skeletons' caching into trees internally
mxgrey May 13, 2015
50dfc08
finished splitting the caches into trees -- needs debugging
mxgrey May 14, 2015
a1cac45
rigid body simulation working -- soft bodies need debugging
mxgrey May 14, 2015
60398f9
distinguishing generalized forces from internal forces
mxgrey May 14, 2015
266a0c9
merged in fixes for internal forces
mxgrey May 14, 2015
3b36db4
added reference-counting DegreeOfFreedomPtr
mxgrey May 16, 2015
32408ce
implemented JointPtr
mxgrey May 16, 2015
a37ce7e
implemented comparison functions for the custom smart pointers
mxgrey May 16, 2015
397c553
creating ReferentialSkeleton
mxgrey May 19, 2015
f61ba07
beginning implementation of Linkage::Criteria
mxgrey May 19, 2015
9671b0d
fixed copy constructor issue for BodyNodePtr and created test
mxgrey May 20, 2015
bb223d5
Merge branch 'memory_management' into grey/linkage
mxgrey May 20, 2015
c9aedfd
more information in split() documentation
mxgrey May 20, 2015
e3043e3
reporting errors when moving fails
mxgrey May 20, 2015
3e3bb1f
improved wording in comment
mxgrey May 20, 2015
802ec21
added warnings and asserts for requesting an invalid root BodyNode
mxgrey May 20, 2015
7aa1442
linkage almost finished with implementation
mxgrey May 21, 2015
dcd5b84
finished Linkage Criteria -- needs testing
mxgrey May 21, 2015
22aff66
fixed rendering for Skeletons with multiple trees
mxgrey May 21, 2015
f2ffefd
branch and chain implemented -- needs testing
mxgrey May 22, 2015
bea1eea
Fixed the range check in getRootBodyNode.
May 23, 2015
6c96391
Added virtual destructors to joint properties.
May 23, 2015
44c2998
Merge pull request #390 from personalrobotics/bugfix/getRootBodyNode
mxgrey May 23, 2015
974d7b0
Added getType and getStaticType functions to Joint
May 23, 2015
15e71d6
Merge pull request #391 from personalrobotics/bugfix/JointPropertiesV…
mxgrey May 24, 2015
fb0ce92
Removed getType from abstract joint types.
May 24, 2015
e94d6a3
beginning implementation of getJacobian for ReferentialSkeletons
mxgrey May 25, 2015
041969b
Merge branch 'memory_management' of http://github.com/dartsim/dart in…
mxgrey May 25, 2015
71cd7b3
Added missing 'virtual' on Joint getType methods.
May 25, 2015
15679cc
Store the path to the mesh in MeshShape.
May 25, 2015
5f3275e
finished implementation of all virtual functions of ReferentialSkelet…
mxgrey May 26, 2015
f63d0ff
change code to avoid internal compiler error for GCC
mxgrey May 26, 2015
47415ca
ReferentialSkeleton and Branch classes tested and working
mxgrey May 26, 2015
344e64f
testing Jacobian computation for ReferentialSkeletons
mxgrey May 26, 2015
2d9e06b
reserve space for dof caches before setting them
mxgrey May 26, 2015
54ae12f
added non-recursive copying and test for it
mxgrey May 26, 2015
15a0259
finished Linkage debugging and testing
mxgrey May 27, 2015
f7f7c28
removed deprecated public constructors
mxgrey May 27, 2015
169613c
cutting down on warnings
mxgrey May 27, 2015
8a58794
removing more warnings
mxgrey May 27, 2015
cbdb20d
finished merging the latest master
mxgrey May 27, 2015
a3945bc
changed finite difference API to be more intuitive
mxgrey May 27, 2015
a5039c9
merged in Joint::getType
mxgrey May 27, 2015
856b499
Removed duplicate code from the MeshShape.
mkoval May 27, 2015
bfff3c7
Add mesh path to MeshShapes created by DartLoader.
May 27, 2015
29ac9f5
Merge branch 'feature/MeshShapePaths' of https://github.com/personalr…
May 27, 2015
c127038
Merge pull request #397 from personalrobotics/feature/MeshShapePaths
mxgrey May 27, 2015
f2d9475
including path name of mesh for SDF
mxgrey May 27, 2015
1d066a2
loosened tolerance for impulse dynamics test
mxgrey May 28, 2015
876fbeb
last minute cleanup
mxgrey May 28, 2015
dd81f96
Use convertToPositions() instead of logMap()
jslee02 Jun 3, 2015
0e642f6
made changes based on pull request feedback
mxgrey Jun 3, 2015
3992a5a
switched assert.h to cassert
mxgrey Jun 3, 2015
2e4c7cc
BodyNodePtr no longer depends on a fully defined BodyNode class
mxgrey Jun 3, 2015
ef20002
refactored smart pointers to minimize header dependencies
mxgrey Jun 3, 2015
640d8a2
better usage of smart pointers
mxgrey Jun 4, 2015
7bfce91
changed INVALID_INDEX to constexpr
mxgrey Jun 4, 2015
ebde971
using const variable instead of constexpr for Visual Studio
mxgrey Jun 5, 2015
57cc22e
replace sub_ptr with custom weak pointers
mxgrey Jun 5, 2015
6f00f80
fixed indexing for atlasSimbicon app
mxgrey Jun 5, 2015
9b10c63
implemented Group and restricted all MetaSkeleton types to only be cr…
mxgrey Jun 7, 2015
11485ee
updated bipedStand to fix the indexing
mxgrey Jun 7, 2015
a4e011a
fixed silly Chain::create bug
mxgrey Jun 7, 2015
9c97ec6
bipedStand cleanup
mxgrey Jun 7, 2015
268245b
Test bullet collision detector with Travis-CI on OSX
jslee02 Jun 10, 2015
6094b77
Apply usage of cutomized smart pointers to BulletCollisionDetector.cpp
jslee02 Jun 10, 2015
06f137e
moved templated implementations into a detail directory
mxgrey Jun 11, 2015
67064eb
changed API in World from 'Frame' to 'SimpleFrame'
mxgrey Jun 11, 2015
2e29332
cleaned up the smart pointer header
mxgrey Jun 11, 2015
bc6dbb2
removed debug printout
mxgrey Jun 11, 2015
7e93e17
Fix indexing for hybridDynamics and jointConstraints apps
jslee02 Jun 11, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/addDeleteSkels/Main.cpp
Expand Up @@ -43,7 +43,7 @@

int main(int argc, char* argv[]) {
// create and initialize the world
dart::simulation::World *myWorld
dart::simulation::WorldPtr myWorld
= dart::utils::SkelParser::readWorld(
DART_DATA_PATH"/skel/ground.skel");
assert(myWorld != NULL);
Expand Down
38 changes: 19 additions & 19 deletions apps/addDeleteSkels/MyWindow.cpp
Expand Up @@ -86,25 +86,25 @@ void MyWindow::keyboard(unsigned char _key, int _x, int _y) {

void MyWindow::spawnCube(const Eigen::Vector3d& _position,
const Eigen::Vector3d& _size,
double _mass) {
dart::dynamics::Skeleton* newCubeSkeleton =
new dart::dynamics::Skeleton();
dart::dynamics::BodyNode* newBodyNode =
new dart::dynamics::BodyNode("cube_link");
dart::dynamics::FreeJoint* newFreeJoint =
new dart::dynamics::FreeJoint("cube_joint");
dart::dynamics::BoxShape* newBoxShape =
new dart::dynamics::BoxShape(_size);
double _mass)
{
dart::dynamics::SkeletonPtr newCubeSkeleton =
dart::dynamics::Skeleton::create();

dart::dynamics::BodyNode::Properties body;
body.mName = "cube_link";
body.mInertia.setMass(_mass);
dart::dynamics::ShapePtr newBoxShape(new dart::dynamics::BoxShape(_size));
body.mVizShapes.push_back(newBoxShape);
body.mColShapes.push_back(newBoxShape);
newBoxShape->setColor(dart::math::randomVector<3>(0.0, 1.0));

dart::dynamics::FreeJoint::Properties joint;
joint.mName = "cube_joint";
joint.mT_ParentBodyToJoint = Eigen::Translation3d(_position);

newCubeSkeleton->createJointAndBodyNodePair<dart::dynamics::FreeJoint>(
nullptr, joint, body);

newBodyNode->addVisualizationShape(newBoxShape);
newBodyNode->addCollisionShape(newBoxShape);
newBodyNode->setMass(_mass);
newBodyNode->setParentJoint(newFreeJoint);
newFreeJoint->setTransformFromParentBodyNode(
Eigen::Isometry3d(Eigen::Translation3d(_position)));
newBoxShape->setColor(Eigen::Vector3d(dart::math::random(0.0, 1.0),
dart::math::random(0.0, 1.0),
dart::math::random(0.0, 1.0)));
newCubeSkeleton->addBodyNode(newBodyNode);
mWorld->addSkeleton(newCubeSkeleton);
}
4 changes: 2 additions & 2 deletions apps/atlasSimbicon/Controller.cpp
Expand Up @@ -49,7 +49,7 @@ using namespace constraint;
using namespace dynamics;

//==============================================================================
Controller::Controller(Skeleton* _atlasRobot,
Controller::Controller(SkeletonPtr _atlasRobot,
ConstraintSolver* _collisionSolver)
: mAtlasRobot(_atlasRobot),
mConstratinSolver(_collisionSolver),
Expand Down Expand Up @@ -89,7 +89,7 @@ void Controller::update(double _currentTime)
}

//==============================================================================
Skeleton* Controller::getAtlasRobot()
SkeletonPtr Controller::getAtlasRobot()
{
return mAtlasRobot;
}
Expand Down
6 changes: 3 additions & 3 deletions apps/atlasSimbicon/Controller.h
Expand Up @@ -50,7 +50,7 @@ class Controller
{
public:
/// \brief Constructor
Controller(dart::dynamics::Skeleton* _atlasRobot,
Controller(dart::dynamics::SkeletonPtr _atlasRobot,
dart::constraint::ConstraintSolver* _collisionSolver);

/// \brief Destructor
Expand All @@ -61,7 +61,7 @@ class Controller
virtual void update(double _currentTime);

/// \brief
dart::dynamics::Skeleton* getAtlasRobot();
dart::dynamics::SkeletonPtr getAtlasRobot();

/// \brief Get current state machine
StateMachine* getCurrentState();
Expand Down Expand Up @@ -104,7 +104,7 @@ class Controller

protected:
/// \brief Atlas robot skeleton
dart::dynamics::Skeleton* mAtlasRobot;
dart::dynamics::SkeletonPtr mAtlasRobot;

/// \brief Conllision detector
dart::constraint::ConstraintSolver* mConstratinSolver;
Expand Down
9 changes: 5 additions & 4 deletions apps/atlasSimbicon/Main.cpp
Expand Up @@ -51,15 +51,15 @@ using namespace dart::utils;
int main(int argc, char* argv[])
{
// Create empty soft world
World* myWorld = new World;
WorldPtr myWorld(new World);

// Load ground and Atlas robot and add them to the world
DartLoader urdfLoader;
Skeleton* ground = urdfLoader.parseSkeleton(
SkeletonPtr ground = urdfLoader.parseSkeleton(
DART_DATA_PATH"sdf/atlas/ground.urdf");
// Skeleton* atlas = SoftSdfParser::readSkeleton(
// SkeletonPtr atlas = SoftSdfParser::readSkeleton(
// DART_DATA_PATH"sdf/atlas/atlas_v3_no_head.sdf");
Skeleton* atlas
SkeletonPtr atlas
= SoftSdfParser::readSkeleton(
DART_DATA_PATH"sdf/atlas/atlas_v3_no_head_soft_feet.sdf");
myWorld->addSkeleton(atlas);
Expand All @@ -69,6 +69,7 @@ int main(int argc, char* argv[])
VectorXd q = atlas->getPositions();
q[0] = -0.5 * DART_PI;
atlas->setPositions(q);

atlas->computeForwardKinematics(true, true, false);

// Set gravity of the world
Expand Down
48 changes: 43 additions & 5 deletions apps/atlasSimbicon/State.cpp
Expand Up @@ -51,7 +51,44 @@ using namespace dart::dynamics;
using namespace dart::constraint;

//==============================================================================
State::State(Skeleton* _skeleton, const std::string& _name)
void createIndexing(std::vector<size_t>&)
{
// Do nothing
}

//==============================================================================
template <typename ...Args>
void createIndexing(std::vector<size_t>& _indexing, size_t _name,
Args... args)
{
_indexing.push_back(_name);
createIndexing(_indexing, args...);
}

//==============================================================================
static std::vector<size_t> createIndexing()
{
// This app was made with dof indices hardcoded, but some internal DART
// development have changed the underlying indexing for the robot, so this
// map converts the old indexing into the new indexing as a temporary (or
// maybe permanent) workaround.

std::vector<size_t> indexing;
// 0 1 2 3 4 5 6
createIndexing(indexing, 0, 1, 2, 3, 4, 5, 6,
// 7 8 9 10 11 12 13
14, 26, 7, 15, 27, 8, 16,
// 14 15 16 17 18 19 20
28, 9, 21, 17, 29, 10, 22,
// 21 22 23 24 25 26 27
18, 30, 11, 23, 19, 31, 12,
// 28 29 30 31 32
24, 13, 25, 20, 32);
return indexing;
}

//==============================================================================
State::State(SkeletonPtr _skeleton, const std::string& _name)
: mName(_name),
mSkeleton(_skeleton),
mNextState(this),
Expand All @@ -62,7 +99,8 @@ State::State(Skeleton* _skeleton, const std::string& _name)
mDesiredGlobalSwingLegAngleOnSagital(0.0),
mDesiredGlobalSwingLegAngleOnCoronal(0.0),
mDesiredGlobalPelvisAngleOnSagital(0.0),
mDesiredGlobalPelvisAngleOnCoronal(0.0)
mDesiredGlobalPelvisAngleOnCoronal(0.0),
mDofMapping(createIndexing())
{
int dof = mSkeleton->getNumDofs();

Expand Down Expand Up @@ -145,8 +183,8 @@ void State::computeControlForce(double _timestep)
assert(mNextState != NULL && "Next state should be set.");

int dof = mSkeleton->getNumDofs();
VectorXd q = mSkeleton->getPositions();
VectorXd dq = mSkeleton->getVelocities();
VectorXd q = mSkeleton->getPositions(mDofMapping);
VectorXd dq = mSkeleton->getVelocities(mDofMapping);

// Compute relative joint angles from desired global angles of the pelvis and
// the swing leg
Expand Down Expand Up @@ -197,7 +235,7 @@ void State::computeControlForce(double _timestep)
_updateTorqueForStanceLeg();

// Apply control torque to the skeleton
mSkeleton->setForces(mTorque);
mSkeleton->setForces(mDofMapping, mTorque);

mElapsedTime += _timestep;
mFrame++;
Expand Down
8 changes: 6 additions & 2 deletions apps/atlasSimbicon/State.h
Expand Up @@ -73,7 +73,7 @@ class State
{
public:
/// \brief Constructor
explicit State(dart::dynamics::Skeleton* _skeleton, const std::string& _name);
explicit State(dart::dynamics::SkeletonPtr _skeleton, const std::string& _name);

/// \brief Destructor
virtual ~State();
Expand Down Expand Up @@ -238,7 +238,7 @@ class State
std::string mName;

/// \brief Target skeleton for control
dart::dynamics::Skeleton* mSkeleton;
dart::dynamics::SkeletonPtr mSkeleton;

/// \brief Next state. Default is myself.
State* mNextState;
Expand Down Expand Up @@ -297,6 +297,10 @@ class State
/// \brief Joint map
std::map<const std::string, int> mJointMap;

/// \brief Maps the dofs from the indexing expected by the controller to the
/// Skeleton's actual indexing
std::vector<size_t> mDofMapping;

private:
/// \brief Build joint map
void _buildJointMap();
Expand Down
77 changes: 65 additions & 12 deletions apps/bipedStand/Controller.cpp
Expand Up @@ -36,22 +36,71 @@
*/

#include "apps/bipedStand/Controller.h"
#include "dart/dynamics/Group.h"

Controller::Controller(dart::dynamics::Skeleton* _skel,
void createIndexing(std::vector<size_t>&)
{
// Do nothing
}

template <typename ...Args>
void createIndexing(std::vector<size_t>& _indexing, size_t _name,
Args... args)
{
_indexing.push_back(_name);
createIndexing(_indexing, args...);
}

static std::vector<size_t> createIndexing()
{
// This app was made with dof indices hardcoded, but some internal DART
// development have changed the underlying indexing for the robot, so this
// map converts the old indexing into the new indexing as a temporary (or
// maybe permanent) workaround.

std::vector<size_t> indexing;
// 0 1 2 3 4 5 6
createIndexing(indexing, 0, 1, 2, 3, 4, 5, 6,
// 7 8 9 10 11 12 13
7, 8, 13, 14, 15, 20, 21,
// 14 15 16 17 18 19 20
9, 16, 22, 10, 11, 17, 18,
// 21 22 23 24 25 26 27
23, 24, 25, 31, 12, 19, 26,
// 28 29 30 31 32 33 34
27, 28, 32, 33, 34, 29, 35,
// 35 36
30, 36);
return indexing;
}

static std::vector<dart::dynamics::DegreeOfFreedom*> getDofs(
const dart::dynamics::SkeletonPtr& _skel)
{
std::vector<dart::dynamics::DegreeOfFreedom*> dofs;
const std::vector<size_t>& indexing = createIndexing();
dofs.reserve(indexing.size());

for(size_t index : indexing)
dofs.push_back(_skel->getDof(index));

return dofs;
}

Controller::Controller(dart::dynamics::SkeletonPtr _skel,
double _t) {
mSkel = _skel;
mSkel = dart::dynamics::Group::create("Group", getDofs(_skel));
mLeftHeel = _skel->getBodyNode("h_heel_left");
mTimestep = _t;
mFrame = 0;
int nDof = mSkel->getNumDofs();
mKp = Eigen::MatrixXd::Identity(nDof, nDof);
mKd = Eigen::MatrixXd::Identity(nDof, nDof);

mTorques.resize(nDof);
mDesiredDofs.resize(nDof);
for (int i = 0; i < nDof; i++) {
mTorques[i] = 0.0;
mDesiredDofs[i] = mSkel->getPosition(i);
}
mTorques.setZero();

resetDesiredDofs();

// using SPD results in simple Kp coefficients
for (int i = 0; i < 6; i++) {
Expand Down Expand Up @@ -81,8 +130,13 @@ void Controller::setDesiredDof(int _index, double _val) {
mDesiredDofs[_index] = _val;
}

void Controller::computeTorques(const Eigen::VectorXd& _dof,
const Eigen::VectorXd& _dofVel) {
void Controller::resetDesiredDofs() {
mDesiredDofs = mSkel->getPositions();
}

void Controller::computeTorques() {
Eigen::VectorXd _dof = mSkel->getPositions();
Eigen::VectorXd _dofVel = mSkel->getVelocities();
Eigen::VectorXd constrForces = mSkel->getConstraintForces();

// SPD tracking
Expand All @@ -97,7 +151,7 @@ void Controller::computeTorques(const Eigen::VectorXd& _dof,

// ankle strategy for sagital plane
Eigen::Vector3d com = mSkel->getCOM();
Eigen::Vector3d cop = mSkel->getBodyNode("h_heel_left")->getTransform()
Eigen::Vector3d cop = mLeftHeel->getTransform()
* Eigen::Vector3d(0.05, 0, 0);
Eigen::Vector2d diff(com[0] - cop[0], com[2] - cop[2]);
double offset = com[0] - cop[0];
Expand Down Expand Up @@ -128,7 +182,7 @@ void Controller::computeTorques(const Eigen::VectorXd& _dof,
mFrame++;
}

dart::dynamics::Skeleton*Controller::getSkel() {
dart::dynamics::MetaSkeletonPtr Controller::getSkel() {
return mSkel;
}

Expand All @@ -143,4 +197,3 @@ Eigen::MatrixXd Controller::getKp() {
Eigen::MatrixXd Controller::getKd() {
return mKd;
}

11 changes: 6 additions & 5 deletions apps/bipedStand/Controller.h
Expand Up @@ -46,22 +46,23 @@

class Controller {
public:
Controller(dart::dynamics::Skeleton* _skel,
Controller(dart::dynamics::SkeletonPtr _skel,
double _t);
virtual ~Controller();

Eigen::VectorXd getTorques();
double getTorque(int _index);
void setDesiredDof(int _index, double _val);
void computeTorques(const Eigen::VectorXd& _dof,
const Eigen::VectorXd& _dofVel);
dart::dynamics::Skeleton* getSkel();
void resetDesiredDofs();
void computeTorques();
dart::dynamics::MetaSkeletonPtr getSkel();
Eigen::VectorXd getDesiredDofs();
Eigen::MatrixXd getKp();
Eigen::MatrixXd getKd();

protected:
dart::dynamics::Skeleton* mSkel;
dart::dynamics::MetaSkeletonPtr mSkel;
dart::dynamics::BodyNodePtr mLeftHeel;
Eigen::VectorXd mTorques;
Eigen::VectorXd mDesiredDofs;
Eigen::MatrixXd mKp;
Expand Down