Skip to content

Commit c52c1d5

Browse files
Update ChangeJointLimits is only for joint limits
1 parent 3825604 commit c52c1d5

File tree

4 files changed

+269
-24
lines changed

4 files changed

+269
-24
lines changed

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

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ enum class CommandType
5555
REMOVE_ALLOWED_COLLISION = 10,
5656
REMOVE_ALLOWED_COLLISION_LINK = 11,
5757
ADD_SCENE_GRAPH = 12,
58-
CHANGE_JOINT_LIMITS = 13
58+
CHANGE_JOINT_POSITION_LIMITS = 13,
59+
CHANGE_JOINT_VELOCITY_LIMITS = 14,
60+
CHANGE_JOINT_ACCELERATION_LIMITS = 15
5961
};
6062

6163
class Command
@@ -288,19 +290,68 @@ class AddSceneGraphCommand : public Command
288290
std::string prefix_;
289291
};
290292

291-
class ChangeJointLimitsCommand : public Command
293+
class ChangeJointPositionLimitsCommand : public Command
292294
{
293295
public:
294-
ChangeJointLimitsCommand(std::string joint_name, tesseract_scene_graph::JointLimits joint_limits)
295-
: Command(CommandType::CHANGE_JOINT_LIMITS), joint_name_(std::move(joint_name)), joint_limits_(joint_limits)
296+
ChangeJointPositionLimitsCommand(std::string joint_name, double lower, double upper)
297+
: Command(CommandType::CHANGE_JOINT_POSITION_LIMITS)
298+
, limits_({ std::make_pair(joint_name, std::make_pair(lower, upper)) })
296299
{
300+
assert(upper > lower);
301+
}
302+
303+
ChangeJointPositionLimitsCommand(std::unordered_map<std::string, std::pair<double, double>> limits)
304+
: Command(CommandType::CHANGE_JOINT_POSITION_LIMITS), limits_(std::move(limits))
305+
{
306+
assert(std::all_of(limits_.begin(), limits_.end(), [](const auto& p) { return p.second.second > p.second.first; }));
297307
}
298-
const std::string& getJointName() const { return joint_name_; }
299-
const tesseract_scene_graph::JointLimits& getLimits() const { return joint_limits_; }
308+
309+
const std::unordered_map<std::string, std::pair<double, double>>& getLimits() const { return limits_; }
300310

301311
private:
302-
std::string joint_name_;
303-
tesseract_scene_graph::JointLimits joint_limits_;
312+
std::unordered_map<std::string, std::pair<double, double>> limits_;
313+
};
314+
315+
class ChangeJointVelocityLimitsCommand : public Command
316+
{
317+
public:
318+
ChangeJointVelocityLimitsCommand(std::string joint_name, double limit)
319+
: Command(CommandType::CHANGE_JOINT_VELOCITY_LIMITS), limits_({ std::make_pair(joint_name, limit) })
320+
{
321+
assert(limit > 0);
322+
}
323+
324+
ChangeJointVelocityLimitsCommand(std::unordered_map<std::string, double> limits)
325+
: Command(CommandType::CHANGE_JOINT_VELOCITY_LIMITS), limits_(std::move(limits))
326+
{
327+
assert(std::all_of(limits_.begin(), limits_.end(), [](const auto& p) { return p.second > 0; }));
328+
}
329+
330+
const std::unordered_map<std::string, double>& getLimits() const { return limits_; }
331+
332+
private:
333+
std::unordered_map<std::string, double> limits_;
334+
};
335+
336+
class ChangeJointAccelerationLimitsCommand : public Command
337+
{
338+
public:
339+
ChangeJointAccelerationLimitsCommand(std::string joint_name, double limit)
340+
: Command(CommandType::CHANGE_JOINT_ACCELERATION_LIMITS), limits_({ std::make_pair(joint_name, limit) })
341+
{
342+
assert(limit > 0);
343+
}
344+
345+
ChangeJointAccelerationLimitsCommand(std::unordered_map<std::string, double> limits)
346+
: Command(CommandType::CHANGE_JOINT_ACCELERATION_LIMITS), limits_(std::move(limits))
347+
{
348+
assert(std::all_of(limits_.begin(), limits_.end(), [](const auto& p) { return p.second > 0; }));
349+
}
350+
351+
const std::unordered_map<std::string, double>& getLimits() const { return limits_; }
352+
353+
private:
354+
std::unordered_map<std::string, double> limits_;
304355
};
305356

306357
} // namespace tesseract_environment

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,49 @@ class Environment
345345
virtual bool changeJointOrigin(const std::string& joint_name, const Eigen::Isometry3d& new_origin);
346346

347347
/**
348-
* @brief Changes the limits associated with a joint
348+
* @brief Changes the position limits associated with a joint
349349
* @param joint_name Name of the joint to be updated
350-
* @param limits New limits to be set as the joint limits
350+
* @param limits New position limits to be set as the joint limits
351351
* @return
352352
*/
353-
virtual bool changeJointLimits(const std::string& joint_name, const tesseract_scene_graph::JointLimits& limits);
353+
virtual bool changeJointPositionLimits(const std::string& joint_name, double lower, double upper);
354+
355+
/**
356+
* @brief Changes the position limits associated with a joint
357+
* @param limits A map of joint names to new position limits
358+
* @return
359+
*/
360+
virtual bool changeJointPositionLimits(const std::unordered_map<std::string, std::pair<double, double>>& limits);
361+
362+
/**
363+
* @brief Changes the velocity limits associated with a joint
364+
* @param joint_name Name of the joint to be updated
365+
* @param limits New velocity limits to be set as the joint limits
366+
* @return
367+
*/
368+
virtual bool changeJointVelocityLimits(const std::string& joint_name, double limit);
369+
370+
/**
371+
* @brief Changes the velocity limits associated with a joint
372+
* @param limits A map of joint names to new velocity limits
373+
* @return
374+
*/
375+
virtual bool changeJointVelocityLimits(const std::unordered_map<std::string, double>& limits);
376+
377+
/**
378+
* @brief Changes the acceleration limits associated with a joint
379+
* @param joint_name Name of the joint to be updated
380+
* @param limits New acceleration limits to be set as the joint limits
381+
* @return
382+
*/
383+
virtual bool changeJointAccelerationLimits(const std::string& joint_name, double limit);
384+
385+
/**
386+
* @brief Changes the acceleration limits associated with a joint
387+
* @param limits A map of joint names to new acceleration limits
388+
* @return
389+
*/
390+
virtual bool changeJointAccelerationLimits(const std::unordered_map<std::string, double>& limits);
354391

355392
/**
356393
* @brief Gets the limits associated with a joint

tesseract/tesseract_environment/src/core/environment.cpp

Lines changed: 163 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,24 @@ bool Environment::applyCommand(const Command& command)
172172
}
173173
break;
174174
}
175-
176-
case tesseract_environment::CommandType::CHANGE_JOINT_LIMITS:
175+
case tesseract_environment::CommandType::CHANGE_JOINT_POSITION_LIMITS:
176+
{
177+
const auto& cmd = static_cast<const tesseract_environment::ChangeJointPositionLimitsCommand&>(command);
178+
if (!changeJointPositionLimits(cmd.getLimits()))
179+
return false;
180+
break;
181+
}
182+
case tesseract_environment::CommandType::CHANGE_JOINT_VELOCITY_LIMITS:
183+
{
184+
const auto& cmd = static_cast<const tesseract_environment::ChangeJointVelocityLimitsCommand&>(command);
185+
if (!changeJointVelocityLimits(cmd.getLimits()))
186+
return false;
187+
break;
188+
}
189+
case tesseract_environment::CommandType::CHANGE_JOINT_ACCELERATION_LIMITS:
177190
{
178-
const auto& cmd = static_cast<const tesseract_environment::ChangeJointLimitsCommand&>(command);
179-
if (!changeJointLimits(cmd.getJointName(), cmd.getLimits()))
191+
const auto& cmd = static_cast<const tesseract_environment::ChangeJointAccelerationLimitsCommand&>(command);
192+
if (!changeJointAccelerationLimits(cmd.getLimits()))
180193
return false;
181194
break;
182195
}
@@ -370,18 +383,161 @@ bool Environment::changeJointOrigin(const std::string& joint_name, const Eigen::
370383
return true;
371384
}
372385

373-
bool Environment::changeJointLimits(const std::string& joint_name, const tesseract_scene_graph::JointLimits& limits)
386+
bool Environment::changeJointPositionLimits(const std::string& joint_name, double lower, double upper)
387+
{
388+
std::lock_guard<std::mutex> lock(mutex_);
389+
tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph_->getJointLimits(joint_name);
390+
if (jl == nullptr)
391+
return false;
392+
393+
tesseract_scene_graph::JointLimits jl_copy = *jl;
394+
jl_copy.lower = lower;
395+
jl_copy.upper = upper;
396+
397+
if (!scene_graph_->changeJointLimits(joint_name, jl_copy))
398+
return false;
399+
400+
// TODO: Only change joint limits rather than completely rebuilding kinematics
401+
if (!manipulator_manager_->update())
402+
return false;
403+
404+
++revision_;
405+
commands_.push_back(std::make_shared<ChangeJointPositionLimitsCommand>(joint_name, lower, upper));
406+
407+
environmentChanged();
408+
409+
return true;
410+
}
411+
412+
bool Environment::changeJointPositionLimits(const std::unordered_map<std::string, std::pair<double, double> >& limits)
413+
{
414+
std::lock_guard<std::mutex> lock(mutex_);
415+
for (const auto& l : limits)
416+
{
417+
tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph_->getJointLimits(l.first);
418+
if (jl == nullptr)
419+
return false;
420+
421+
tesseract_scene_graph::JointLimits jl_copy = *jl;
422+
jl_copy.lower = l.second.first;
423+
jl_copy.upper = l.second.second;
424+
425+
if (!scene_graph_->changeJointLimits(l.first, jl_copy))
426+
return false;
427+
}
428+
429+
// TODO: Only change joint limits rather than completely rebuilding kinematics
430+
if (!manipulator_manager_->update())
431+
return false;
432+
433+
++revision_;
434+
commands_.push_back(std::make_shared<ChangeJointPositionLimitsCommand>(limits));
435+
436+
environmentChanged();
437+
438+
return true;
439+
}
440+
441+
bool Environment::changeJointVelocityLimits(const std::string& joint_name, double limit)
442+
{
443+
std::lock_guard<std::mutex> lock(mutex_);
444+
tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph_->getJointLimits(joint_name);
445+
if (jl == nullptr)
446+
return false;
447+
448+
tesseract_scene_graph::JointLimits jl_copy = *jl;
449+
jl_copy.velocity = limit;
450+
451+
if (!scene_graph_->changeJointLimits(joint_name, jl_copy))
452+
return false;
453+
454+
// TODO: Only change joint limits rather than completely rebuilding kinematics
455+
if (!manipulator_manager_->update())
456+
return false;
457+
458+
++revision_;
459+
commands_.push_back(std::make_shared<ChangeJointVelocityLimitsCommand>(joint_name, limit));
460+
461+
environmentChanged();
462+
463+
return true;
464+
}
465+
466+
bool Environment::changeJointVelocityLimits(const std::unordered_map<std::string, double>& limits)
467+
{
468+
std::lock_guard<std::mutex> lock(mutex_);
469+
for (const auto& l : limits)
470+
{
471+
tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph_->getJointLimits(l.first);
472+
if (jl == nullptr)
473+
return false;
474+
475+
tesseract_scene_graph::JointLimits jl_copy = *jl;
476+
jl_copy.velocity = l.second;
477+
478+
if (!scene_graph_->changeJointLimits(l.first, jl_copy))
479+
return false;
480+
}
481+
482+
// TODO: Only change joint limits rather than completely rebuilding kinematics
483+
if (!manipulator_manager_->update())
484+
return false;
485+
486+
++revision_;
487+
commands_.push_back(std::make_shared<ChangeJointVelocityLimitsCommand>(limits));
488+
489+
environmentChanged();
490+
491+
return true;
492+
}
493+
494+
bool Environment::changeJointAccelerationLimits(const std::string& joint_name, double limit)
374495
{
375496
std::lock_guard<std::mutex> lock(mutex_);
376-
if (!scene_graph_->changeJointLimits(joint_name, limits))
497+
tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph_->getJointLimits(joint_name);
498+
if (jl == nullptr)
499+
return false;
500+
501+
tesseract_scene_graph::JointLimits jl_copy = *jl;
502+
jl_copy.acceleration = limit;
503+
504+
if (!scene_graph_->changeJointLimits(joint_name, jl_copy))
377505
return false;
378506

379507
// TODO: Only change joint limits rather than completely rebuilding kinematics
380508
if (!manipulator_manager_->update())
381509
return false;
382510

383511
++revision_;
384-
commands_.push_back(std::make_shared<ChangeJointLimitsCommand>(joint_name, limits));
512+
commands_.push_back(std::make_shared<ChangeJointAccelerationLimitsCommand>(joint_name, limit));
513+
514+
environmentChanged();
515+
516+
return true;
517+
}
518+
519+
bool Environment::changeJointAccelerationLimits(const std::unordered_map<std::string, double>& limits)
520+
{
521+
std::lock_guard<std::mutex> lock(mutex_);
522+
for (const auto& l : limits)
523+
{
524+
tesseract_scene_graph::JointLimits::ConstPtr jl = scene_graph_->getJointLimits(l.first);
525+
if (jl == nullptr)
526+
return false;
527+
528+
tesseract_scene_graph::JointLimits jl_copy = *jl;
529+
jl_copy.acceleration = l.second;
530+
531+
if (!scene_graph_->changeJointLimits(l.first, jl_copy))
532+
return false;
533+
}
534+
535+
// TODO: Only change joint limits rather than completely rebuilding kinematics
536+
if (!manipulator_manager_->update())
537+
return false;
538+
539+
++revision_;
540+
commands_.push_back(std::make_shared<ChangeJointAccelerationLimitsCommand>(limits));
385541

386542
environmentChanged();
387543

tesseract/tesseract_environment/src/ofkt/ofkt_state_solver.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,19 @@ void OFKTStateSolver::onEnvironmentChanged(const Commands& commands)
392392

393393
break;
394394
}
395-
case tesseract_environment::CommandType::CHANGE_JOINT_LIMITS:
395+
case tesseract_environment::CommandType::CHANGE_JOINT_POSITION_LIMITS:
396396
{
397-
const auto& cmd = static_cast<const tesseract_environment::ChangeJointLimitsCommand&>(*command);
397+
const auto& cmd = static_cast<const tesseract_environment::ChangeJointPositionLimitsCommand&>(*command);
398+
const std::unordered_map<std::string, std::pair<double, double>>& limits = cmd.getLimits();
398399
// Loop through all names until we find the one we need
399400
for (std::size_t i = 0; i < joint_names_.size(); i++)
400401
{
402+
auto it = limits.find(joint_names_[i]);
401403
// Assign the lower/upper. Velocity, acceleration, and effort are ignored
402-
if (joint_names_[i] == cmd.getJointName())
404+
if (it != limits.end())
403405
{
404-
limits_(static_cast<Eigen::Index>(i), 0) = cmd.getLimits().lower;
405-
limits_(static_cast<Eigen::Index>(i), 1) = cmd.getLimits().upper;
406-
break;
406+
limits_(static_cast<Eigen::Index>(i), 0) = it->second.first;
407+
limits_(static_cast<Eigen::Index>(i), 1) = it->second.second;
407408
}
408409
}
409410

0 commit comments

Comments
 (0)