Skip to content

Commit 6f8813d

Browse files
Levi ArmstrongLevi-Armstrong
authored andcommitted
Add support for replacing links and joints
1 parent 423206c commit 6f8813d

File tree

17 files changed

+1317
-225
lines changed

17 files changed

+1317
-225
lines changed

tesseract_environment/include/tesseract_environment/core/command.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ enum class CommandType
5656
CHANGE_JOINT_ACCELERATION_LIMITS = 15,
5757
ADD_KINEMATICS_INFORMATION = 16,
5858
CHANGE_DEFAULT_CONTACT_MARGIN = 17,
59-
CHANGE_PAIR_CONTACT_MARGIN = 18
59+
CHANGE_PAIR_CONTACT_MARGIN = 18,
60+
REPLACE_JOINT = 19
6061
};
6162

6263
class Command

tesseract_environment/include/tesseract_environment/core/commands.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <tesseract_environment/core/commands/remove_allowed_collision_link_command.h>
4848
#include <tesseract_environment/core/commands/remove_joint_command.h>
4949
#include <tesseract_environment/core/commands/remove_link_command.h>
50+
#include <tesseract_environment/core/commands/replace_joint_command.h>
5051

5152
#ifdef SWIG
5253

@@ -56,6 +57,7 @@
5657
%shared_ptr(tesseract_environment::MoveJointCommand)
5758
%shared_ptr(tesseract_environment::RemoveLinkCommand)
5859
%shared_ptr(tesseract_environment::RemoveJointCommand)
60+
%shared_ptr(tesseract_environment::ReplaceJointCommand)
5961
%shared_ptr(tesseract_environment::ChangeLinkOriginCommand)
6062
%shared_ptr(tesseract_environment::ChangeJointOriginCommand)
6163
%shared_ptr(tesseract_environment::ChangeLinkCollisionEnabledCommand)
@@ -75,15 +77,16 @@
7577
%shared_factory(
7678
tesseract_environment::Command,
7779
tesseract_environment::AddLinkCommand,
78-
tesseract_environment::MoveLinkCommand,
79-
tesseract_environment::MoveJointCommand,
80-
tesseract_environment::RemoveLinkCommand,
81-
tesseract_environment::RemoveJointCommand,
82-
tesseract_environment::ChangeLinkOriginCommand,
83-
tesseract_environment::ChangeJointOriginCommand,
84-
tesseract_environment::ChangeLinkCollisionEnabledCommand,
85-
tesseract_environment::ChangeLinkVisibilityCommand,
86-
tesseract_environment::AddAllowedCollisionCommand,
80+
tesseract_environment::MoveLinkCommand,
81+
tesseract_environment::MoveJointCommand,
82+
tesseract_environment::RemoveLinkCommand,
83+
tesseract_environment::RemoveJointCommand,
84+
tesseract_environment::ReplaceJointCommand,
85+
tesseract_environment::ChangeLinkOriginCommand,
86+
tesseract_environment::ChangeJointOriginCommand,
87+
tesseract_environment::ChangeLinkCollisionEnabledCommand,
88+
tesseract_environment::ChangeLinkVisibilityCommand,
89+
tesseract_environment::AddAllowedCollisionCommand,
8790
tesseract_environment::RemoveAllowedCollisionCommand,
8891
tesseract_environment::RemoveAllowedCollisionLinkCommand,
8992
tesseract_environment::AddSceneGraphCommand,

tesseract_environment/include/tesseract_environment/core/commands/add_link_command.h

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
* See the License for the specific language governing permissions and
2424
* limitations under the License.
2525
*/
26-
#ifndef TESSERACT_ENVIRONMENT_ADD_COMMAND_H
27-
#define TESSERACT_ENVIRONMENT_ADD_COMMAND_H
26+
#ifndef TESSERACT_ENVIRONMENT_ADD_LINK_COMMAND_H
27+
#define TESSERACT_ENVIRONMENT_ADD_LINK_COMMAND_H
2828

2929
#include <tesseract_common/macros.h>
3030
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
@@ -44,36 +44,62 @@ class AddLinkCommand : public Command
4444
using ConstPtr = std::shared_ptr<const AddLinkCommand>;
4545

4646
/**
47-
* @brief Adds a link to the environment
47+
* @brief Adds or replace a link to the environment
4848
*
49-
* This method should attach the link to the root link with a fixed joint
49+
* If the link exists and replace_allowed equals true:
50+
*
51+
* This command should replace the current link with the new link
52+
*
53+
* If the link exists and replace_allowed equals false:
54+
*
55+
* This command should result in an error
56+
*
57+
* If the link does not exist:
58+
*
59+
* This command should attach the link to the root link with a fixed joint
5060
* with a joint name of joint_{link name}".
5161
*
5262
* @param link The link to be added to the graph
63+
* @param replace_allowed If true then if the link exists it will be replaced, otherwise if false it will fail.
5364
*/
54-
AddLinkCommand(const tesseract_scene_graph::Link& link)
55-
: link_(std::make_shared<tesseract_scene_graph::Link>(link.clone())), joint_(nullptr)
65+
AddLinkCommand(const tesseract_scene_graph::Link& link, bool replace_allowed = false)
66+
: link_(std::make_shared<tesseract_scene_graph::Link>(link.clone()))
67+
, joint_(nullptr)
68+
, replace_allowed_(replace_allowed)
5669
{
5770
}
5871

5972
/**
60-
* @brief Adds a link to the environment
73+
* @brief Adds a link and joint in the environment
74+
*
75+
* If the link or joint exists:
76+
*
77+
* This command should result in an error
78+
*
6179
* @param link The link to be added to the graph
6280
* @param joint The joint to be used to attach link to environment
81+
* @param replace_allowed If true then if the link exists it will be replaced, otherwise if false it will fail.
6382
*/
6483
AddLinkCommand(const tesseract_scene_graph::Link& link, const tesseract_scene_graph::Joint& joint)
6584
: link_(std::make_shared<tesseract_scene_graph::Link>(link.clone()))
6685
, joint_(std::make_shared<tesseract_scene_graph::Joint>(joint.clone()))
6786
{
87+
if (joint_->child_link_name != link.getName())
88+
throw std::runtime_error("AddLinkCommand: The provided joint child link name must equal the name of the provided "
89+
"link.");
90+
91+
/** @todo if joint is not fixed we should verify that limits are provided */
6892
}
6993

7094
CommandType getType() const final { return CommandType::ADD_LINK; }
7195
const tesseract_scene_graph::Link::ConstPtr& getLink() const { return link_; }
7296
const tesseract_scene_graph::Joint::ConstPtr& getJoint() const { return joint_; }
97+
bool replaceAllowed() const { return replace_allowed_; }
7398

7499
private:
75100
tesseract_scene_graph::Link::ConstPtr link_;
76101
tesseract_scene_graph::Joint::ConstPtr joint_;
102+
bool replace_allowed_{ false };
77103
};
78104
} // namespace tesseract_environment
79105

tesseract_environment/include/tesseract_environment/core/commands/add_scene_graph_command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class AddSceneGraphCommand : public Command
6969
*/
7070
AddSceneGraphCommand(const tesseract_scene_graph::SceneGraph& scene_graph,
7171
const tesseract_scene_graph::Joint& joint,
72-
std::string prefix)
72+
std::string prefix = "")
7373
: scene_graph_(scene_graph.clone())
7474
, joint_(std::make_shared<tesseract_scene_graph::Joint>(joint.clone()))
7575
, prefix_(std::move(prefix))
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* @file replace_joint_command.h
3+
* @brief Used to replace joint in environment
4+
*
5+
* @author Levi Armstrong
6+
* @date February 11, 2021
7+
* @version TODO
8+
* @bug No known bugs
9+
*
10+
* @copyright Copyright (c) 2021, Southwest Research Institute
11+
*
12+
* @par License
13+
* Software License Agreement (Apache License)
14+
* @par
15+
* Licensed under the Apache License, Version 2.0 (the "License");
16+
* you may not use this file except in compliance with the License.
17+
* You may obtain a copy of the License at
18+
* http://www.apache.org/licenses/LICENSE-2.0
19+
* @par
20+
* Unless required by applicable law or agreed to in writing, software
21+
* distributed under the License is distributed on an "AS IS" BASIS,
22+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23+
* See the License for the specific language governing permissions and
24+
* limitations under the License.
25+
*/
26+
#ifndef TESSERACT_ENVIRONMENT_REPLACE_JOINT_COMMAND_H
27+
#define TESSERACT_ENVIRONMENT_REPLACE_JOINT_COMMAND_H
28+
#include <tesseract_common/macros.h>
29+
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
30+
#include <memory>
31+
TESSERACT_COMMON_IGNORE_WARNINGS_POP
32+
33+
#include <tesseract_environment/core/command.h>
34+
#include <tesseract_scene_graph/joint.h>
35+
36+
namespace tesseract_environment
37+
{
38+
class ReplaceJointCommand : public Command
39+
{
40+
public:
41+
using Ptr = std::shared_ptr<ReplaceJointCommand>;
42+
using ConstPtr = std::shared_ptr<const ReplaceJointCommand>;
43+
44+
/**
45+
* @brief Replace a joint in the environment
46+
*
47+
* If the joint does not exist:
48+
*
49+
* This command should result in an error
50+
*
51+
* If the child link is not the same:
52+
*
53+
* This command should result in an error
54+
*
55+
* @param joint The joint to be replaced
56+
*/
57+
ReplaceJointCommand(const tesseract_scene_graph::Joint& joint)
58+
: joint_(std::make_shared<tesseract_scene_graph::Joint>(joint.clone()))
59+
{
60+
if (joint_->type != tesseract_scene_graph::JointType::FIXED)
61+
{
62+
// if ()
63+
/** @todo check limits */
64+
}
65+
}
66+
67+
CommandType getType() const final { return CommandType::REPLACE_JOINT; }
68+
const tesseract_scene_graph::Joint::ConstPtr& getJoint() const { return joint_; }
69+
70+
private:
71+
tesseract_scene_graph::Joint::ConstPtr joint_;
72+
};
73+
74+
} // namespace tesseract_environment
75+
76+
#endif // TESSERACT_ENVIRONMENT_REPLACE_JOINT_COMMAND_H

tesseract_environment/include/tesseract_environment/core/environment.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ class Environment
213213
*/
214214
Environment::Ptr clone() const;
215215

216-
/** @brief reset to initialized state */
216+
/**
217+
* @brief reset to initialized state
218+
* @details If the environment has not been initialized then this returns false
219+
* @return True if environment was successfully reset, otherwise false.
220+
*/
217221
bool reset();
218222

219223
/** @brief clear content and uninitialize */
@@ -449,7 +453,7 @@ class Environment
449453
* @brief Get the transform corresponding to the link.
450454
* @return Transform and is identity when no transform is available.
451455
*/
452-
virtual const Eigen::Isometry3d& getLinkTransform(const std::string& link_name) const;
456+
virtual Eigen::Isometry3d getLinkTransform(const std::string& link_name) const;
453457

454458
/**
455459
* @brief Returns a clone of the environments state solver
@@ -765,6 +769,7 @@ class Environment
765769
bool applyMoveJointCommand(const MoveJointCommand::ConstPtr& cmd);
766770
bool applyRemoveLinkCommand(const RemoveLinkCommand::ConstPtr& cmd);
767771
bool applyRemoveJointCommand(const RemoveJointCommand::ConstPtr& cmd);
772+
bool applyReplaceJointCommand(const ReplaceJointCommand::ConstPtr& cmd);
768773
bool applyChangeLinkOriginCommand(const ChangeLinkOriginCommand::ConstPtr& cmd);
769774
bool applyChangeJointOriginCommand(const ChangeJointOriginCommand::ConstPtr& cmd);
770775
bool applyChangeLinkCollisionEnabledCommand(const ChangeLinkCollisionEnabledCommand::ConstPtr& cmd);

tesseract_environment/include/tesseract_environment/core/state_solver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ class StateSolver
100100
*/
101101
virtual EnvState::Ptr getRandomState() const = 0;
102102

103+
/**
104+
* @brief Get the vector of joint names which align with the limits
105+
* @return A vector of joint names
106+
*/
107+
virtual const std::vector<std::string>& getJointNames() const = 0;
108+
103109
/**
104110
* @brief Getter for kinematic limits
105111
* @return The kinematic limits

tesseract_environment/include/tesseract_environment/kdl/kdl_state_solver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class KDLStateSolver : public StateSolver
5858

5959
EnvState::Ptr getRandomState() const override;
6060

61+
const std::vector<std::string>& getJointNames() const override;
62+
6163
const tesseract_common::KinematicLimits& getLimits() const override;
6264

6365
private:

tesseract_environment/include/tesseract_environment/ofkt/ofkt_state_solver.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class OFKTStateSolver : public StateSolver
101101

102102
EnvState::Ptr getRandomState() const override;
103103

104+
const std::vector<std::string>& getJointNames() const override;
105+
104106
const tesseract_common::KinematicLimits& getLimits() const override;
105107

106108
private:
@@ -164,6 +166,30 @@ class OFKTStateSolver : public StateSolver
164166
*/
165167
void removeNode(OFKTNode* node, std::vector<std::string>& removed_joints, std::vector<long>& removed_joints_indices);
166168

169+
/**
170+
* @brief This a helper function for moving a link
171+
* @param new_kinematic_joints The vector to store new kinematic joints added to the solver
172+
* @param joint The joint performing the move
173+
*/
174+
void moveLinkHelper(std::vector<tesseract_scene_graph::Joint::ConstPtr>& new_kinematic_joints,
175+
const tesseract_scene_graph::Joint::ConstPtr& joint);
176+
177+
/**
178+
* @brief This is a helper function for replacing a joint
179+
* @param new_kinematic_joints The vector to store new kinematic joints added to the solver
180+
* @param joint The joint performing the replacement
181+
*/
182+
void replaceJointHelper(std::vector<tesseract_scene_graph::Joint::ConstPtr>& new_kinematic_joints,
183+
const tesseract_scene_graph::Joint::ConstPtr& joint);
184+
185+
/**
186+
* @brief This will clean up member variables joint_names_ and limits_
187+
* @param removed_joints The removed joint names container
188+
* @param removed_joints_indices The removed joint names indices container
189+
*/
190+
void removeJointHelper(const std::vector<std::string>& removed_joints,
191+
const std::vector<long>& removed_joints_indices);
192+
167193
friend struct ofkt_builder;
168194
};
169195

0 commit comments

Comments
 (0)