Skip to content

Commit 7a2b83d

Browse files
Add floating joint support
1 parent ea05dde commit 7a2b83d

File tree

17 files changed

+592
-105
lines changed

17 files changed

+592
-105
lines changed

tesseract_environment/include/tesseract_environment/environment.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,11 @@ class Environment
296296
* will update the contact managers transforms
297297
*
298298
*/
299-
void setState(const std::unordered_map<std::string, double>& joints);
300-
void setState(const std::vector<std::string>& joint_names, const Eigen::Ref<const Eigen::VectorXd>& joint_values);
299+
void setState(const std::unordered_map<std::string, double>& joints,
300+
const tesseract_common::TransformMap& floating_joints = {});
301+
void setState(const std::vector<std::string>& joint_names,
302+
const Eigen::Ref<const Eigen::VectorXd>& joint_values,
303+
const tesseract_common::TransformMap& floating_joints = {});
301304

302305
/**
303306
* @brief Get the state of the environment for a given set or subset of joint values.
@@ -307,9 +310,11 @@ class Environment
307310
* @param joints A map of joint names to joint values to change.
308311
* @return A the state of the environment
309312
*/
310-
tesseract_scene_graph::SceneState getState(const std::unordered_map<std::string, double>& joints) const;
313+
tesseract_scene_graph::SceneState getState(const std::unordered_map<std::string, double>& joints,
314+
const tesseract_common::TransformMap& floating_joints = {}) const;
311315
tesseract_scene_graph::SceneState getState(const std::vector<std::string>& joint_names,
312-
const Eigen::Ref<const Eigen::VectorXd>& joint_values) const;
316+
const Eigen::Ref<const Eigen::VectorXd>& joint_values,
317+
const tesseract_common::TransformMap& floating_joints = {}) const;
313318

314319
/** @brief Get the current state of the environment */
315320
tesseract_scene_graph::SceneState getState() const;
@@ -389,6 +394,18 @@ class Environment
389394
*/
390395
Eigen::VectorXd getCurrentJointValues(const std::vector<std::string>& joint_names) const;
391396

397+
/**
398+
* @brief Get the current floating joint values
399+
* @return The joint origin transform for the floating joint
400+
*/
401+
tesseract_common::TransformMap getCurrentFloatingJointValues() const;
402+
403+
/**
404+
* @brief Get the current floating joint values
405+
* @return The joint origin transform for the floating joint
406+
*/
407+
tesseract_common::TransformMap getCurrentFloatingJointValues(const std::vector<std::string>& joint_names) const;
408+
392409
/**
393410
* @brief Get the root link name
394411
* @return String

tesseract_environment/src/environment.cpp

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,21 @@ struct Environment::Implementation
289289

290290
bool initHelper(const std::vector<std::shared_ptr<const Command>>& commands);
291291

292-
void setState(const std::unordered_map<std::string, double>& joints);
292+
void setState(const std::unordered_map<std::string, double>& joints,
293+
const tesseract_common::TransformMap& floating_joints = {});
293294

294-
void setState(const std::vector<std::string>& joint_names, const Eigen::Ref<const Eigen::VectorXd>& joint_values);
295+
void setState(const std::vector<std::string>& joint_names,
296+
const Eigen::Ref<const Eigen::VectorXd>& joint_values,
297+
const tesseract_common::TransformMap& floating_joints = {});
295298

296299
Eigen::VectorXd getCurrentJointValues() const;
297300

298301
Eigen::VectorXd getCurrentJointValues(const std::vector<std::string>& joint_names) const;
299302

303+
tesseract_common::TransformMap getCurrentFloatingJointValues() const;
304+
305+
tesseract_common::TransformMap getCurrentFloatingJointValues(const std::vector<std::string>& joint_names) const;
306+
300307
std::vector<std::string> getStaticLinkNames(const std::vector<std::string>& joint_names) const;
301308

302309
void clear();
@@ -425,7 +432,7 @@ struct Environment::Implementation
425432

426433
tesseract_scene_graph::SceneState current_state;
427434
ar& boost::serialization::make_nvp("current_state", current_state);
428-
setState(current_state.joints);
435+
setState(current_state.joints, current_state.floating_joints);
429436

430437
// No need to serialize the contact allowed validator because it cannot be modified and is constructed internally
431438
// from the scene graph
@@ -567,16 +574,18 @@ bool Environment::Implementation::initHelper(const std::vector<std::shared_ptr<c
567574
return initialized;
568575
}
569576

570-
void Environment::Implementation::setState(const std::unordered_map<std::string, double>& joints)
577+
void Environment::Implementation::setState(const std::unordered_map<std::string, double>& joints,
578+
const tesseract_common::TransformMap& floating_joints)
571579
{
572-
state_solver->setState(joints);
580+
state_solver->setState(joints, floating_joints);
573581
currentStateChanged();
574582
}
575583

576584
void Environment::Implementation::setState(const std::vector<std::string>& joint_names,
577-
const Eigen::Ref<const Eigen::VectorXd>& joint_values)
585+
const Eigen::Ref<const Eigen::VectorXd>& joint_values,
586+
const tesseract_common::TransformMap& floating_joints)
578587
{
579-
state_solver->setState(joint_names, joint_values);
588+
state_solver->setState(joint_names, joint_values, floating_joints);
580589
currentStateChanged();
581590
}
582591

@@ -601,6 +610,21 @@ Eigen::VectorXd Environment::Implementation::getCurrentJointValues(const std::ve
601610
return jv;
602611
}
603612

613+
tesseract_common::TransformMap Environment::Implementation::getCurrentFloatingJointValues() const
614+
{
615+
return current_state.floating_joints;
616+
}
617+
618+
tesseract_common::TransformMap
619+
Environment::Implementation::getCurrentFloatingJointValues(const std::vector<std::string>& joint_names) const
620+
{
621+
tesseract_common::TransformMap fjv;
622+
for (const auto& joint_name : joint_names)
623+
fjv[joint_name] = current_state.floating_joints.at(joint_name);
624+
625+
return fjv;
626+
}
627+
604628
std::vector<std::string>
605629
Environment::Implementation::getStaticLinkNames(const std::vector<std::string>& joint_names) const
606630
{
@@ -2427,40 +2451,44 @@ const std::string& Environment::getName() const
24272451
return std::as_const<Implementation>(*impl_).scene_graph->getName();
24282452
}
24292453

2430-
void Environment::setState(const std::unordered_map<std::string, double>& joints)
2454+
void Environment::setState(const std::unordered_map<std::string, double>& joints,
2455+
const tesseract_common::TransformMap& floating_joints)
24312456
{
24322457
{
24332458
std::unique_lock<std::shared_mutex> lock(mutex_);
2434-
impl_->setState(joints);
2459+
impl_->setState(joints, floating_joints);
24352460
}
24362461

24372462
std::shared_lock<std::shared_mutex> lock(mutex_);
24382463
impl_->triggerCurrentStateChangedCallbacks();
24392464
}
24402465

24412466
void Environment::setState(const std::vector<std::string>& joint_names,
2442-
const Eigen::Ref<const Eigen::VectorXd>& joint_values)
2467+
const Eigen::Ref<const Eigen::VectorXd>& joint_values,
2468+
const tesseract_common::TransformMap& floating_joints)
24432469
{
24442470
{
24452471
std::unique_lock<std::shared_mutex> lock(mutex_);
2446-
impl_->setState(joint_names, joint_values);
2472+
impl_->setState(joint_names, joint_values, floating_joints);
24472473
}
24482474

24492475
std::shared_lock<std::shared_mutex> lock(mutex_);
24502476
impl_->triggerCurrentStateChangedCallbacks();
24512477
}
24522478

2453-
tesseract_scene_graph::SceneState Environment::getState(const std::unordered_map<std::string, double>& joints) const
2479+
tesseract_scene_graph::SceneState Environment::getState(const std::unordered_map<std::string, double>& joints,
2480+
const tesseract_common::TransformMap& floating_joints) const
24542481
{
24552482
std::shared_lock<std::shared_mutex> lock(mutex_);
2456-
return std::as_const<Implementation>(*impl_).state_solver->getState(joints);
2483+
return std::as_const<Implementation>(*impl_).state_solver->getState(joints, floating_joints);
24572484
}
24582485

24592486
tesseract_scene_graph::SceneState Environment::getState(const std::vector<std::string>& joint_names,
2460-
const Eigen::Ref<const Eigen::VectorXd>& joint_values) const
2487+
const Eigen::Ref<const Eigen::VectorXd>& joint_values,
2488+
const tesseract_common::TransformMap& floating_joints) const
24612489
{
24622490
std::shared_lock<std::shared_mutex> lock(mutex_);
2463-
return std::as_const<Implementation>(*impl_).state_solver->getState(joint_names, joint_values);
2491+
return std::as_const<Implementation>(*impl_).state_solver->getState(joint_names, joint_values, floating_joints);
24642492
}
24652493

24662494
tesseract_scene_graph::SceneState Environment::getState() const
@@ -2543,6 +2571,19 @@ Eigen::VectorXd Environment::getCurrentJointValues(const std::vector<std::string
25432571
return std::as_const<Implementation>(*impl_).getCurrentJointValues(joint_names);
25442572
}
25452573

2574+
tesseract_common::TransformMap Environment::getCurrentFloatingJointValues() const
2575+
{
2576+
std::shared_lock<std::shared_mutex> lock(mutex_);
2577+
return std::as_const<Implementation>(*impl_).getCurrentFloatingJointValues();
2578+
}
2579+
2580+
tesseract_common::TransformMap
2581+
Environment::getCurrentFloatingJointValues(const std::vector<std::string>& joint_names) const
2582+
{
2583+
std::shared_lock<std::shared_mutex> lock(mutex_);
2584+
return std::as_const<Implementation>(*impl_).getCurrentFloatingJointValues(joint_names);
2585+
}
2586+
25462587
std::string Environment::getRootLinkName() const
25472588
{
25482589
std::shared_lock<std::shared_mutex> lock(mutex_);

tesseract_kinematics/core/src/joint_group.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ JointGroup::JointGroup(std::string name,
5252
throw std::runtime_error("Joint name '" + joint_name + "' does not exist in the provided scene graph!");
5353
}
5454

55-
tesseract_scene_graph::KDLTreeData data =
56-
tesseract_scene_graph::parseSceneGraph(scene_graph, joint_names_, scene_state.joints);
55+
tesseract_scene_graph::KDLTreeData data = tesseract_scene_graph::parseSceneGraph(
56+
scene_graph, joint_names_, scene_state.joints, scene_state.floating_joints);
5757
state_solver_ = std::make_unique<tesseract_scene_graph::KDLStateSolver>(scene_graph, data);
5858
jacobian_map_.reserve(joint_names_.size());
5959
std::vector<std::string> solver_jn = state_solver_->getActiveJointNames();

tesseract_scene_graph/include/tesseract_scene_graph/kdl_parser.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
4949
#include <kdl/jacobian.hpp>
5050
TESSERACT_COMMON_IGNORE_WARNINGS_POP
5151

52+
#include <tesseract_common/eigen_types.h>
53+
5254
namespace tesseract_scene_graph
5355
{
5456
class SceneGraph;
@@ -122,13 +124,20 @@ KDL::RigidBodyInertia convert(const std::shared_ptr<const Inertial>& inertial);
122124
/** @brief The KDLTreeData populated when parsing scene graph */
123125
struct KDLTreeData
124126
{
127+
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
128+
125129
KDL::Tree tree;
126130
std::string base_link_name;
127131
std::vector<std::string> joint_names;
128132
std::vector<std::string> active_joint_names;
133+
std::vector<std::string> floating_joint_names;
129134
std::vector<std::string> link_names;
130135
std::vector<std::string> active_link_names;
131136
std::vector<std::string> static_link_names;
137+
tesseract_common::TransformMap floating_joint_values;
138+
139+
bool operator==(const KDLTreeData& rhs) const;
140+
bool operator!=(const KDLTreeData& rhs) const;
132141
};
133142

134143
/**
@@ -153,7 +162,8 @@ KDLTreeData parseSceneGraph(const SceneGraph& scene_graph);
153162
*/
154163
KDLTreeData parseSceneGraph(const SceneGraph& scene_graph,
155164
const std::vector<std::string>& joint_names,
156-
const std::unordered_map<std::string, double>& joint_values);
165+
const std::unordered_map<std::string, double>& joint_values,
166+
const tesseract_common::TransformMap& floating_joint_values);
157167

158168
} // namespace tesseract_scene_graph
159169

tesseract_scene_graph/include/tesseract_scene_graph/scene_state.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ struct SceneState
6969
/** @brief The joint values used for calculating the joint and link transforms */
7070
std::unordered_map<std::string, double> joints;
7171

72+
/** @brief The floating joint values used for calculating the joint and link transforms */
73+
tesseract_common::TransformMap floating_joints;
74+
7275
/** @brief The link transforms in world coordinate system */
7376
tesseract_common::TransformMap link_transforms;
7477

@@ -77,6 +80,8 @@ struct SceneState
7780

7881
Eigen::VectorXd getJointValues(const std::vector<std::string>& joint_names) const;
7982

83+
tesseract_common::TransformMap getFloatingJointValues(const std::vector<std::string>& joint_names) const;
84+
8085
bool operator==(const SceneState& rhs) const;
8186
bool operator!=(const SceneState& rhs) const;
8287

0 commit comments

Comments
 (0)