Skip to content

Commit 8ec7791

Browse files
mpowelsonLevi-Armstrong
authored andcommitted
Add changeJointLimits Command
1 parent 7d38e90 commit 8ec7791

File tree

5 files changed

+92
-2
lines changed

5 files changed

+92
-2
lines changed

tesseract/tesseract_environment/include/tesseract_environment/core/commands.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ enum class CommandType
5454
ADD_ALLOWED_COLLISION = 9,
5555
REMOVE_ALLOWED_COLLISION = 10,
5656
REMOVE_ALLOWED_COLLISION_LINK = 11,
57-
ADD_SCENE_GRAPH = 12
57+
ADD_SCENE_GRAPH = 12,
58+
CHANGE_JOINT_LIMITS = 13
5859
};
5960

6061
class Command
@@ -287,6 +288,23 @@ class AddSceneGraphCommand : public Command
287288
std::string prefix_;
288289
};
289290

291+
class TESSERACT_ENVIRONMENT_CORE_PUBLIC ChangeJointLimitsCommand : public Command
292+
{
293+
public:
294+
ChangeJointLimitsCommand(std::string joint_name, tesseract_scene_graph::JointLimits joint_limits)
295+
: Command(CommandType::CHANGE_JOINT_LIMITS)
296+
, joint_name_(std::move(joint_name))
297+
, joint_limits_(std::move(joint_limits))
298+
{
299+
}
300+
const std::string& getJointName() const { return joint_name_; }
301+
const tesseract_scene_graph::JointLimits& getLimits() const { return joint_limits_; }
302+
303+
private:
304+
std::string joint_name_;
305+
tesseract_scene_graph::JointLimits joint_limits_;
306+
};
307+
290308
} // namespace tesseract_environment
291309

292310
#endif // TESSERACT_ENVIRONMENT_COMMANDS_H

tesseract/tesseract_environment/include/tesseract_environment/core/environment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ class Environment
329329
*/
330330
virtual bool changeJointOrigin(const std::string& joint_name, const Eigen::Isometry3d& new_origin);
331331

332+
virtual bool changeJointLimits(const std::string& joint_name, const tesseract_scene_graph::JointLimits limits);
333+
332334
/**
333335
* @brief Set whether a link should be considered during collision checking
334336
* @param enabled True if should be condisdered during collision checking, otherwise false

tesseract/tesseract_environment/src/core/environment.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ bool Environment::applyCommand(const Command& command)
172172
}
173173
break;
174174
}
175+
176+
case tesseract_environment::CommandType::CHANGE_JOINT_LIMITS:
177+
{
178+
const auto& cmd = static_cast<const tesseract_environment::ChangeJointLimitsCommand&>(command);
179+
if (!changeJointLimits(cmd.getJointName(), cmd.getLimits()))
180+
return false;
181+
break;
182+
}
175183
default:
176184
{
177185
CONSOLE_BRIDGE_logError("Unhandled environment command");
@@ -362,6 +370,20 @@ bool Environment::changeJointOrigin(const std::string& joint_name, const Eigen::
362370
return true;
363371
}
364372

373+
bool Environment::changeJointLimits(const std::string& joint_name, const tesseract_scene_graph::JointLimits limits)
374+
{
375+
std::lock_guard<std::mutex> lock(mutex_);
376+
if (!scene_graph_->changeJointLimits(joint_name, limits))
377+
return false;
378+
379+
++revision_;
380+
commands_.push_back(std::make_shared<ChangeJointLimitsCommand>(joint_name, limits));
381+
382+
environmentChanged();
383+
384+
return true;
385+
}
386+
365387
void Environment::setLinkCollisionEnabled(const std::string& name, bool enabled)
366388
{
367389
std::lock_guard<std::mutex> lock(mutex_);

tesseract/tesseract_scene_graph/include/tesseract_scene_graph/graph.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,25 @@ class SceneGraph : public Graph
261261
/** @brief Changes the "origin" transform of the joint and recomputes the associated edge
262262
* @param name Name of the joint to be changed
263263
* @param new_origin The new transform associated with the joint
264-
* @return
264+
* @return True if successful.
265265
*/
266266
bool changeJointOrigin(const std::string& name, const Eigen::Isometry3d& new_origin);
267267

268+
/**
269+
* @brief Changes the limits of a joint. The JointLimits::Ptr remains the same, but the values passed in are assigned
270+
* @param name Name of the joint to be changed
271+
* @param limits The new limits associated with the joint
272+
* @return True if successful.
273+
*/
274+
bool changeJointLimits(const std::string& name, const JointLimits& limits);
275+
276+
/**
277+
* @brief Gets the limits of the joint specified by name
278+
* @param name Name of the joint which limits will be retrieved
279+
* @return Limits of the joint. Returns nullptr is joint is not found.
280+
*/
281+
JointLimits::ConstPtr getJointLimits(const std::string& name);
282+
268283
/**
269284
* @brief Disable collision between two collision objects
270285
* @param link_name1 Collision object name

tesseract/tesseract_scene_graph/src/graph.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,39 @@ bool SceneGraph::changeJointOrigin(const std::string& name, const Eigen::Isometr
340340
return true;
341341
}
342342

343+
bool SceneGraph::changeJointLimits(const std::string& name, const JointLimits& limits)
344+
{
345+
auto found = joint_map_.find(name);
346+
347+
if (found == joint_map_.end())
348+
{
349+
CONSOLE_BRIDGE_logWarn("Tried to change Joint limit with name (%s) which does not exist in scene graph.",
350+
name.c_str());
351+
return false;
352+
}
353+
354+
found->second.first->limits->lower = limits.lower;
355+
found->second.first->limits->upper = limits.upper;
356+
found->second.first->limits->effort = limits.effort;
357+
found->second.first->limits->velocity = limits.velocity;
358+
found->second.first->limits->acceleration = limits.acceleration;
359+
360+
return true;
361+
}
362+
363+
JointLimits::ConstPtr SceneGraph::getJointLimits(const std::string& name)
364+
{
365+
auto found = joint_map_.find(name);
366+
367+
if (found == joint_map_.end())
368+
{
369+
CONSOLE_BRIDGE_logWarn("SceneGraph::getJointLimits tried to find Joint with name (%s) which does not exist in scene graph.",
370+
name.c_str());
371+
return nullptr;
372+
}
373+
return found->second.first->limits;
374+
}
375+
343376
void SceneGraph::addAllowedCollision(const std::string& link_name1,
344377
const std::string& link_name2,
345378
const std::string& reason)

0 commit comments

Comments
 (0)