Skip to content

Commit e8fd2bb

Browse files
Add API. Fix scene builder and reparenting frame (#77)
* added moveit <-> dart state functions * remove dartsim from catkin includes, added rviz helper ptr * setting limits on joints * added options struct * new pick/place demo * removed goof * multi-robot tsr goals tested * update CO, setTF, fix scene builder * Clean up * update cmake * removed other planning functions * removed remaining master * robowflex robotpose consistency * using new functions * fixing goofs Co-authored-by: Zachary Kingston <zak@rice.edu> Co-authored-by: Zachary Kingston <kingston.zak@gmail.com>
1 parent 4d517fe commit e8fd2bb

File tree

10 files changed

+89
-23
lines changed

10 files changed

+89
-23
lines changed

robowflex_dart/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ if (DART_LIBRARIES)
4848
LIBRARIES ${LIBRARY_NAME}
4949
CATKIN_DEPENDS
5050
robowflex_library
51-
# dartsim
5251
DEPENDS
5352
ompl
5453
INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include

robowflex_dart/include/robowflex_dart/planning.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace robowflex
9090
struct
9191
{
9292
bool use_gradient{false};
93-
std::size_t max_samples{2};
93+
std::size_t max_samples{10};
9494
} options;
9595

9696
private:

robowflex_dart/include/robowflex_dart/structure.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <dart/dynamics/Skeleton.hpp>
1515

1616
#include <robowflex_library/class_forward.h>
17+
#include <robowflex_library/adapter.h>
18+
#include <robowflex_library/tf.h>
1719

1820
namespace robowflex
1921
{
@@ -159,6 +161,20 @@ namespace robowflex
159161
*/
160162
void reparentFreeFrame(dart::dynamics::BodyNode *child, const std::string &parent = "");
161163

164+
/** \brief Set the transform from a joint to its parent.
165+
* \param[in] name Name of joint to set transform of.
166+
* \param[in] tf Transform to set.
167+
*/
168+
void setJointParentTransform(const std::string &name, const RobotPose &tf);
169+
170+
/** \brief Update or add a collision object.
171+
* \param[in] name Name of object to add.
172+
* \param[in] geometry Geometry of object.
173+
* \param[in] pose Pose of object to set.
174+
*/
175+
void updateCollisionObject(const std::string &name, const GeometryPtr &geometry,
176+
const robowflex::RobotPose &pose);
177+
162178
/** \} */
163179

164180
/** \name Constructing Frames

robowflex_dart/scripts/fetch_ik.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,6 @@ int main(int argc, char **argv)
8585
builder.ss->clear();
8686
}
8787
});
88+
8889
return 0;
8990
}

robowflex_dart/scripts/fetch_pick.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ int main(int argc, char **argv)
6868
start_tsr.useGroup(GROUP);
6969
start_tsr.initialize();
7070
start_tsr.solveWorld();
71-
builder.setStartConfigurationFromWorld();
7271

72+
builder.setStartConfigurationFromWorld();
7373
builder.initialize();
7474

7575
darts::TSR::Specification goal_spec;
@@ -104,9 +104,7 @@ int main(int argc, char **argv)
104104
const auto &planToPlace = [&]() {
105105
darts::PlanBuilder builder(world);
106106
builder.addGroup(fetch_name, GROUP);
107-
108107
builder.setStartConfigurationFromWorld();
109-
110108
builder.initialize();
111109

112110
darts::TSR::Specification goal_spec;
@@ -147,6 +145,5 @@ int main(int argc, char **argv)
147145

148146
planToPlace();
149147
});
150-
151148
return 0;
152149
}

robowflex_dart/src/planning.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ bool TSRGoal::sample(const ompl::base::GoalLazySamples * /*gls*/, ompl::base::St
9090
si_->enforceBounds(state);
9191
}
9292

93-
return true;
93+
total_samples_++;
94+
return total_samples_ < options.max_samples;
9495
}
9596

9697
double TSRGoal::distanceGoal(const ompl::base::State *state) const

robowflex_dart/src/robot.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ bool Robot::loadSRDF(const std::string &srdf)
309309
const auto &value = js->Attribute("value");
310310
const auto &jname = js->Attribute("name");
311311

312-
auto values = robowflex::IO::tokenize(value, " ");
312+
auto values = robowflex::IO::tokenize<double>(value, " ");
313313
auto joint = getGroupJoint(group, jname);
314314
if (joint.second != nullptr)
315315
{
316316
for (std::size_t i = 0; i < values.size(); ++i)
317-
state[joint.first + i] = std::stod(values[i]);
317+
state[joint.first + i] = values[i];
318318
}
319319

320320
js = js->NextSiblingElement("joint");

robowflex_dart/src/structure.cpp

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ Structure::Structure(const std::string &name, const ScenePtr &scene) : Structure
3838

3939
dart::dynamics::FreeJoint::Properties joint;
4040
joint.mName = object;
41-
joint.mT_ParentBodyToJoint = pose;
41+
joint.mT_ParentBodyToJoint = robowflex::TF::identity();
4242

4343
auto shape = makeGeometry(geometry);
4444

4545
auto pair = addFreeFrame(joint, shape);
46+
setJointParentTransform(object, pose);
4647
setColor(pair.second, dart::Color::Blue(0.2));
4748
}
4849

@@ -117,6 +118,10 @@ void Structure::createShapeNode(dart::dynamics::BodyNode *body, const dart::dyna
117118
double mass = magic::DEFAULT_DENSITY * shape->getVolume();
118119
inertia.setMass(mass);
119120
inertia.setMoment(shape->computeInertia(mass));
121+
122+
if (not inertia.verify(false))
123+
inertia = dart::dynamics::Inertia();
124+
120125
body->setInertia(inertia);
121126
body->setRestitutionCoeff(magic::DEFAULT_RESTITUTION);
122127

@@ -233,16 +238,11 @@ dart::dynamics::BodyNode *Structure::getFrame(const std::string &name) const
233238
return skeleton_->getBodyNode(name);
234239
}
235240

236-
dart::dynamics::BodyNode *Structure::getRootFrame() const
237-
{
238-
return skeleton_->getRootBodyNode();
239-
}
240-
241241
void Structure::reparentFreeFrame(dart::dynamics::BodyNode *child, const std::string &parent)
242242
{
243243
auto frame = getFrame(parent);
244244

245-
Eigen::Isometry3d tf;
245+
RobotPose tf;
246246
if (frame)
247247
tf = child->getTransform(frame);
248248
else
@@ -253,6 +253,37 @@ void Structure::reparentFreeFrame(dart::dynamics::BodyNode *child, const std::st
253253
jt->setRelativeTransform(tf);
254254
}
255255

256+
void Structure::setJointParentTransform(const std::string &name, const RobotPose &tf)
257+
{
258+
auto joint = skeleton_->getJoint(name);
259+
joint->setTransformFromParentBodyNode(tf);
260+
}
261+
262+
void Structure::updateCollisionObject(const std::string &name, const GeometryPtr &geometry,
263+
const robowflex::RobotPose &pose)
264+
{
265+
auto nodes = skeleton_->getBodyNodes(name); // Get all nodes with this name
266+
if (nodes.size() != 0)
267+
setJointParentTransform(name, pose);
268+
else
269+
{
270+
dart::dynamics::FreeJoint::Properties joint;
271+
joint.mName = name;
272+
joint.mT_ParentBodyToJoint = robowflex::TF::identity();
273+
274+
auto shape = makeGeometry(geometry);
275+
276+
auto pair = addFreeFrame(joint, shape);
277+
setJointParentTransform(name, pose);
278+
setColor(pair.second, dart::Color::Blue(0.2));
279+
}
280+
}
281+
282+
dart::dynamics::BodyNode *Structure::getRootFrame() const
283+
{
284+
return skeleton_->getRootBodyNode();
285+
}
286+
256287
dart::dynamics::ShapePtr robowflex::darts::makeGeometry(const GeometryPtr &geometry)
257288
{
258289
const auto &dimensions = geometry->getDimensions();
@@ -297,16 +328,27 @@ std::shared_ptr<dart::dynamics::SphereShape> robowflex::darts::makeSphere(double
297328

298329
std::shared_ptr<dart::dynamics::MeshShape> robowflex::darts::makeMesh(const GeometryPtr &geometry)
299330
{
300-
static Assimp::Importer importer_;
331+
auto uri = geometry->getResource();
332+
if (uri.empty())
333+
{
334+
static Assimp::Importer importer_;
301335

302-
auto shape = std::dynamic_pointer_cast<shapes::Mesh>(geometry->getShape());
303-
std::vector<char> buffer;
304-
shapes::writeSTLBinary(shape.get(), buffer);
336+
auto shape = std::dynamic_pointer_cast<shapes::Mesh>(geometry->getShape());
337+
std::vector<char> buffer;
338+
shapes::writeSTLBinary(shape.get(), buffer);
305339

306-
auto aiscene = importer_.ReadFileFromMemory(buffer.data(), buffer.size(),
307-
aiProcessPreset_TargetRealtime_MaxQuality, "STOL");
340+
auto aiscene = importer_.ReadFileFromMemory(buffer.data(), buffer.size(),
341+
aiProcessPreset_TargetRealtime_MaxQuality, "STOL");
308342

309-
return std::make_shared<dart::dynamics::MeshShape>(geometry->getDimensions(), aiscene);
343+
auto mesh = std::make_shared<dart::dynamics::MeshShape>(geometry->getDimensions(), aiscene);
344+
return mesh;
345+
}
346+
else
347+
{
348+
auto aiscene = dart::dynamics::MeshShape::loadMesh(uri);
349+
auto mesh = std::make_shared<dart::dynamics::MeshShape>(geometry->getDimensions(), aiscene);
350+
return mesh;
351+
}
310352
}
311353

312354
std::shared_ptr<dart::dynamics::MeshShape> robowflex::darts::makeArcsegment(double low, double high,

robowflex_library/include/robowflex_library/tf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ namespace robowflex
2828
*/
2929
namespace TF
3030
{
31+
/** \brief Creates the Identity pose.
32+
* \return A new identity robot pose.
33+
*/
34+
RobotPose identity();
35+
3136
/** \brief Creates a robot pose from a linear component and XYZ convention Euler angles
3237
* \param[in] x X-axis translation
3338
* \param[in] y Y-ayis translation

robowflex_library/src/tf.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
using namespace robowflex;
1010

11+
RobotPose TF::identity()
12+
{
13+
return RobotPose::Identity();
14+
}
15+
1116
RobotPose TF::createPoseXYZ(double x, double y, double z, double X, double Y, double Z)
1217
{
1318
return createPoseQ(Eigen::Vector3d{x, y, z}, //

0 commit comments

Comments
 (0)