Skip to content

Commit 65e030f

Browse files
authored
Merge pull request #153 from resibots/break_sensors
Allow to "break" sensors
2 parents 855c76b + 188ee84 commit 65e030f

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/robot_dart/robot.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ namespace robot_dart {
6969
return skeleton->getGravityForces();
7070
else if (content == 15)
7171
return skeleton->getCoriolisAndGravityForces();
72+
else if (content == 16)
73+
return skeleton->getConstraintForces();
7274
ROBOT_DART_EXCEPTION_ASSERT(false, "Unknown type of data!");
7375
}
7476

@@ -81,6 +83,8 @@ namespace robot_dart {
8183
tmp = skeleton->getGravityForces();
8284
else if (content == 15)
8385
tmp = skeleton->getCoriolisAndGravityForces();
86+
else if (content == 16)
87+
tmp = skeleton->getConstraintForces();
8488

8589
for (size_t i = 0; i < dof_names.size(); i++) {
8690
auto it = dof_map.find(dof_names[i]);
@@ -112,7 +116,7 @@ namespace robot_dart {
112116
data(i) = dof->getForceLowerLimit();
113117
else if (content == 12)
114118
data(i) = dof->getForceUpperLimit();
115-
else if (content == 13 || content == 14 || content == 15)
119+
else if (content == 13 || content == 14 || content == 15 || content == 16)
116120
data(i) = tmp(it->second);
117121
else
118122
ROBOT_DART_EXCEPTION_ASSERT(false, "Unknown type of data!");
@@ -1640,6 +1644,11 @@ namespace robot_dart {
16401644
return detail::dof_data<15>(_skeleton, dof_names, _dof_map);
16411645
}
16421646

1647+
Eigen::VectorXd Robot::constraint_forces(const std::vector<std::string>& dof_names) const
1648+
{
1649+
return detail::dof_data<16>(_skeleton, dof_names, _dof_map);
1650+
}
1651+
16431652
Eigen::VectorXd Robot::vec_dof(const Eigen::VectorXd& vec, const std::vector<std::string>& dof_names) const
16441653
{
16451654
assert(vec.size() == static_cast<int>(_skeleton->getNumDofs()));

src/robot_dart/robot.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ namespace robot_dart {
218218
Eigen::VectorXd coriolis_forces(const std::vector<std::string>& dof_names = {}) const;
219219
Eigen::VectorXd gravity_forces(const std::vector<std::string>& dof_names = {}) const;
220220
Eigen::VectorXd coriolis_gravity_forces(const std::vector<std::string>& dof_names = {}) const;
221+
Eigen::VectorXd constraint_forces(const std::vector<std::string>& dof_names = {}) const;
221222

222223
// Get only the part of vector for DOFs in dof_names
223224
Eigen::VectorXd vec_dof(const Eigen::VectorXd& vec, const std::vector<std::string>& dof_names) const;

src/robot_dart/sensor/sensor.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,18 @@ namespace robot_dart {
4343
void Sensor::set_pose(const Eigen::Isometry3d& tf) { _world_pose = tf; }
4444
const Eigen::Isometry3d& Sensor::pose() const { return _world_pose; }
4545

46+
void Sensor::detach() {
47+
_attached_to_body = false;
48+
_attached_to_joint = false;
49+
_body_attached = nullptr;
50+
_joint_attached = nullptr;
51+
_active = false;
52+
}
53+
4654
void Sensor::refresh(double t)
4755
{
56+
if (!_active)
57+
return;
4858
if (_attaching_to_body && !_attached_to_body) {
4959
attach_to_body(_body_attached, _attached_tf);
5060
}
@@ -71,7 +81,6 @@ namespace robot_dart {
7181
if (body)
7282
_world_pose = body->getWorldTransform() * tf * _attached_tf;
7383
}
74-
7584
calculate(t);
7685
}
7786

@@ -111,5 +120,13 @@ namespace robot_dart {
111120
_attached_to_joint = false;
112121
}
113122
}
123+
const std::string& Sensor::attached_to() const
124+
{
125+
ROBOT_DART_EXCEPTION_ASSERT(_attached_to_body || _attached_to_joint, "Joint is not attached to anything");
126+
if (_attached_to_body)
127+
return _body_attached->getName();
128+
// attached to joint
129+
return _joint_attached->getName();
130+
}
114131
} // namespace sensor
115132
} // namespace robot_dart

src/robot_dart/sensor/sensor.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace robot_dart {
5252
virtual void attach_to_joint(dart::dynamics::Joint* joint, const Eigen::Isometry3d& tf = Eigen::Isometry3d::Identity());
5353
void attach_to_joint(const std::shared_ptr<Robot>& robot, const std::string& joint_name, const Eigen::Isometry3d& tf = Eigen::Isometry3d::Identity()) { attach_to_joint(robot->joint(joint_name), tf); }
5454

55+
void detach();
56+
const std::string& attached_to() const;
5557
protected:
5658
RobotDARTSimu* _simu = nullptr;
5759
bool _active;

0 commit comments

Comments
 (0)