Skip to content

Commit 7273811

Browse files
authored
Merge pull request #96 from resibots/robot_reset
Robot reset
2 parents e395a88 + 443c848 commit 7273811

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

src/python/robot.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ namespace robot_dart {
6161
.def("free", &Robot::free)
6262

6363
.def("reset", &Robot::reset)
64+
.def("clear_external_forces", &Robot::clear_external_forces)
65+
.def("clear_internal_forces", &Robot::clear_internal_forces)
66+
.def("reset_commands", &Robot::reset_commands)
6467

6568
.def("set_actuator_types", &Robot::set_actuator_types,
6669
py::arg("type"),
@@ -237,8 +240,6 @@ namespace robot_dart {
237240
py::arg("torque"),
238241
py::arg("local") = false)
239242

240-
.def("clear_external_forces", &Robot::clear_external_forces)
241-
242243
.def("external_forces", (Eigen::Vector6d(Robot::*)(const std::string& body_name) const) & Robot::external_forces)
243244
.def("external_forces", (Eigen::Vector6d(Robot::*)(size_t body_index) const) & Robot::external_forces)
244245

src/robot_dart/robot.cpp

+23-7
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ namespace robot_dart {
288288
ROBOT_DART_EXCEPTION_INTERNAL_ASSERT(_skeleton != nullptr);
289289
_skeleton->setName(robot_name);
290290
_set_damages(damages);
291+
reset();
291292
}
292293

293294
std::shared_ptr<Robot> Robot::clone() const
@@ -488,9 +489,22 @@ namespace robot_dart {
488489
_skeleton->resetPositions();
489490
_skeleton->resetVelocities();
490491
_skeleton->resetAccelerations();
491-
this->clear_external_forces();
492+
493+
clear_internal_forces();
494+
reset_commands();
495+
clear_external_forces();
492496
}
493497

498+
void Robot::clear_external_forces() { _skeleton->clearExternalForces(); }
499+
500+
void Robot::clear_internal_forces()
501+
{
502+
_skeleton->clearInternalForces();
503+
_skeleton->clearConstraintImpulses();
504+
}
505+
506+
void Robot::reset_commands() { _skeleton->resetCommands(); }
507+
494508
void Robot::set_actuator_types(const std::string& type, const std::vector<std::string>& joint_names, bool override_mimic, bool override_base)
495509
{
496510
// Set all dofs to same actuator type
@@ -1003,8 +1017,6 @@ namespace robot_dart {
10031017
bd->addExtTorque(torque, local);
10041018
}
10051019

1006-
void Robot::clear_external_forces() { _skeleton->clearExternalForces(); }
1007-
10081020
Eigen::Vector6d Robot::external_forces(const std::string& body_name) const
10091021
{
10101022
auto bd = _skeleton->getBodyNode(body_name);
@@ -1718,8 +1730,10 @@ namespace robot_dart {
17181730
body->setInertia(inertia);
17191731

17201732
// Put the body into position
1733+
auto robot = std::make_shared<Robot>(box_skel, box_name);
1734+
17211735
if (type == "free") // free floating
1722-
box_skel->setPositions(pose);
1736+
robot->set_positions(pose);
17231737
else // fixed
17241738
{
17251739
Eigen::Isometry3d T;
@@ -1728,7 +1742,7 @@ namespace robot_dart {
17281742
body->getParentJoint()->setTransformFromParentBodyNode(T);
17291743
}
17301744

1731-
return std::make_shared<Robot>(box_skel, box_name);
1745+
return robot;
17321746
}
17331747

17341748
std::shared_ptr<Robot> Robot::create_ellipsoid(const Eigen::Vector3d& dims,
@@ -1759,9 +1773,11 @@ namespace robot_dart {
17591773
inertia.setMoment(ellipsoid->computeInertia(mass));
17601774
body->setInertia(inertia);
17611775

1776+
auto robot = std::make_shared<Robot>(ellipsoid_skel, ellipsoid_name);
1777+
17621778
// Put the body into position
17631779
if (type == "free") // free floating
1764-
ellipsoid_skel->setPositions(pose);
1780+
robot->set_positions(pose);
17651781
else // fixed
17661782
{
17671783
Eigen::Isometry3d T;
@@ -1770,6 +1786,6 @@ namespace robot_dart {
17701786
body->getParentJoint()->setTransformFromParentBodyNode(T);
17711787
}
17721788

1773-
return std::make_shared<Robot>(ellipsoid_skel, ellipsoid_name);
1789+
return robot;
17741790
}
17751791
} // namespace robot_dart

src/robot_dart/robot.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ namespace robot_dart {
6565

6666
void reset();
6767

68+
void clear_external_forces();
69+
void clear_internal_forces();
70+
void reset_commands();
71+
6872
// actuator type can be: torque, servo, velocity, passive, locked, mimic (only for completeness, use set_mimic to use this)
6973
// Be careful that actuator types are per joint and not per DoF
7074
void set_actuator_types(const std::string& type, const std::vector<std::string>& joint_names = {}, bool override_mimic = false, bool override_base = false);
@@ -155,8 +159,6 @@ namespace robot_dart {
155159
void add_external_torque(const std::string& body_name, const Eigen::Vector3d& torque, bool local = false);
156160
void add_external_torque(size_t body_index, const Eigen::Vector3d& torque, bool local = false);
157161

158-
void clear_external_forces();
159-
160162
Eigen::Vector6d external_forces(const std::string& body_name) const;
161163
Eigen::Vector6d external_forces(size_t body_index) const;
162164

0 commit comments

Comments
 (0)