1 #ifndef PPL_GROUP_CFG_H_
2 #define PPL_GROUP_CFG_H_
16 #include "Transformation.h"
38 template <
typename GraphType>
173 const
double _oriRes) const;
193 const
mathtool::Orientation& _rotation,
194 const
bool _debug = false);
208 const
mathtool::Transformation& _transform,
209 const
mathtool::Transformation& _relativeTransform
259 const std::vector<
Robot*>& _robots);
265 void SetData(const std::vector<
double>& _dofs);
283 int* const _nTicks, const
double _positionRes,
284 const
double _orientationRes);
311 template<typename DistanceMetricPointer>
312 void GetRandomRay(const
double _length, DistanceMetricPointer _dm, const
bool _norm=true);
322 std::string
PrettyPrint(
const size_t _precision = 4)
const;
332 virtual void InitializeLocalCfgs() noexcept override;
338 template <typename GraphType>
343 template <
typename GraphType>
349 template <
typename GraphType>
354 if(this->m_group != _other.m_group)
358 if(this->m_groupMap != _other.m_groupMap)
362 for(
size_t i = 0; i < this->m_vids.size(); ++i) {
363 const VID thisVID = this->m_vids[i],
364 otherVID = _other.m_vids[i];
367 if(thisVID != otherVID)
370 else if(this->GetRobotCfg(i) != _other.GetRobotCfg(i))
378 template <
typename GraphType>
383 const auto& robots = this->GetRobots();
385 for(
size_t i = 0; i < robots.size(); i++) {
386 const auto& cfg1 = this->GetRobotCfg(i);
387 const auto& cfg2 = _other.GetRobotCfg(i);
398 template <
typename GraphType>
403 return (newCfg += _other);
407 template <
typename GraphType>
412 return (newCfg -= _other);
416 template <
typename GraphType>
421 return (newCfg *= _other);
425 template <
typename GraphType>
431 if(this->m_group != _other.
m_group)
436 for(
size_t i = 0; i < this->GetNumRobots(); ++i)
437 this->SetRobotCfg(i, this->GetRobotCfg(i) + _other.
GetRobotCfg(i));
443 template <
typename GraphType>
449 if(this->m_group != _other.
m_group)
454 for(
size_t i = 0; i < this->GetNumRobots(); ++i)
455 this->SetRobotCfg(i, this->GetRobotCfg(i) - _other.
GetRobotCfg(i));
461 template <
typename GraphType>
467 for(
size_t i = 0; i < this->GetNumRobots(); ++i)
468 this->SetRobotCfg(i, this->GetRobotCfg(i) * _val);
475 template <
typename GraphType>
483 template <
typename GraphType>
488 if(this->m_group != _newRoadmap->
GetGroup())
496 for(
size_t i = 0; i < this->GetNumRobots(); ++i)
502 template <
typename GraphType>
506 for(
auto robot : this->GetRobots())
507 if(robot->IsNonholonomic())
513 template <
typename GraphType>
518 for(
auto robot : this->GetRobots())
519 dofSum += robot->GetMultiBody()->DOF();
524 template <
typename GraphType>
529 for(
size_t i = 0; i < this->GetNumRobots(); ++i) {
530 const double m = this->GetRobotCfg(i).Magnitude();
533 return std::sqrt(result);
537 template <
typename GraphType>
542 for(
size_t i = 0; i < this->GetNumRobots(); ++i) {
543 const double m = this->GetRobotCfg(i).PositionMagnitude();
546 return std::sqrt(result);
550 template <
typename GraphType>
555 for(
size_t i = 0; i < this->GetNumRobots(); ++i) {
556 const double m = this->GetRobotCfg(i).OrientationMagnitude();
559 return std::sqrt(result);
564 template <
typename GraphType>
568 for(
size_t i = 0; i < this->GetNumRobots(); ++i)
569 this->GetRobotCfg(i).ConfigureRobot();
573 template <
typename GraphType>
577 const double _oriRes)
const {
578 for(
size_t i = 0; i < this->GetNumRobots(); ++i)
579 if(!this->GetRobotCfg(i).WithinResolution(_cfg.
GetRobotCfg(i), _posRes, _oriRes))
587 template <
typename GraphType>
591 const mathtool::Orientation& _rotation,
const bool _debug) {
600 const size_t leaderIndex = _robotList[0];
603 const IndividualCfg& leaderCfg = this->GetRobotCfg(leaderIndex);
607 mathtool::Transformation initialLeaderTransform = leaderCfg.GetMultiBody()->
608 GetBody(0)->GetWorldTransformation();
610 const mathtool::Transformation rotation(mathtool::Vector3d(0,0,0), _rotation);
613 std::cout <<
"Rotating bodies " << _robotList <<
" with rotation = "
614 << rotation << std::endl;
620 const mathtool::Transformation transform = initialLeaderTransform * rotation;
622 ApplyTransformationForRobots(_robotList, transform, initialLeaderTransform);
626 template <
typename GraphType>
630 const mathtool::Transformation& _transform,
631 const mathtool::Transformation& _relativeTransform) {
633 for (
const size_t robotIndex : _robotList) {
634 const IndividualCfg& robotCfg = this->GetRobotCfg(robotIndex);
637 if(robotCfg.GetMultiBody()->GetNumBodies() > 1)
641 const mathtool::Transformation& initialRobotTransform =
642 robotCfg.GetMultiBody()->GetBody(0)->GetWorldTransformation();
647 const mathtool::Transformation newTransformation = _transform *
648 (-_relativeTransform) *
649 initialRobotTransform;
652 const std::vector<double>& transformed = newTransformation.GetCfg();
654 OverwriteDofsForRobots(transformed, {robotIndex});
659 template <
typename GraphType>
663 for(
const size_t robotIndex : _robots) {
664 if(this->IsLocalCfg(robotIndex)) {
669 if(_dofs.size() != cfg.DOF())
671 <<
"dofs to robot " << robotIndex
672 <<
", which has " << cfg.DOF() <<
" DOFs.";
675 for(
unsigned int i = 0; i < _dofs.size(); ++i)
683 if(_dofs.size() != cfg.DOF())
685 <<
"dofs to robot " << robotIndex
686 <<
", which has " << cfg.DOF() <<
" DOFs.";
689 for(
unsigned int i = 0; i < _dofs.size(); ++i)
691 this->SetRobotCfg(robotIndex, std::move(cfg));
697 template <
typename GraphType>
701 for(
const size_t robotIndex : _robots) {
703 for(
size_t i = 0; i < robotCfg.PosDOF(); ++i)
704 robotCfg[i] += _dofs[i];
705 this->SetRobotCfg(robotIndex, std::move(robotCfg));
710 template <
typename GraphType>
715 for(
const size_t robotIndex : _robots) {
717 newIndividualCfg.SetData(_dofs);
718 this->SetRobotCfg(robotIndex, std::move(newIndividualCfg));
723 template <
typename GraphType>
728 for(
const size_t robotIndex : _robots) {
730 newIndividualCfg.SetLinearPosition(_dofs);
731 this->SetRobotCfg(robotIndex, std::move(newIndividualCfg));
736 template <
typename GraphType>
740 for(
const size_t robotIndex : _robots) {
742 this->SetRobotCfg(robotIndex, std::move(robotCfg));
747 template <
typename GraphType>
751 const std::vector<Robot*>& _robots) {
753 toGroup = this->m_groupMap->GetGroup();
755 for(
Robot*
const robot : _robots) {
757 toIndex = toGroup->GetGroupIndex(robot);
759 this->SetRobotCfg(toIndex, std::move(robotCfg));
764 template <
typename GraphType>
767 SetData(
const std::vector<double>& _dofs) {
768 if(_dofs.size() != CompositeDOF())
770 <<
" DOFs on a robot group with "
771 << CompositeDOF() <<
" DOFs.";
773 size_t compositeIndex = 0;
774 for(
size_t i = 0; i < this->GetNumRobots(); ++i) {
775 const size_t robotDof = this->GetRobot(i)->GetMultiBody()->DOF();
778 for(
size_t i = 0; i < robotDof; ++i, ++compositeIndex)
779 robotCfg[i] = _dofs[compositeIndex];
784 template <
typename GraphType>
793 <<
"with this operation currently!";
797 for(
size_t i = 0; i < this->GetNumRobots(); ++i) {
800 this->SetRobotCfg(i, std::move(incr));
805 template <
typename GraphType>
809 const double _positionRes,
const double _orientationRes) {
812 *_nTicks = std::max(1., std::ceil(std::max(
816 FindIncrement(_start, _goal, *_nTicks);
820 template <
typename GraphType>
824 for(
size_t i = 0; i < this->GetNumRobots(); ++i)
825 if(!this->GetRobotCfg(i).InBounds(_b))
832 template <
typename GraphType>
836 return InBounds(_env->GetBoundary());
839 template <
typename GraphType>
843 std::set<Robot*> found;
844 auto group = this->m_group;
846 for(
size_t i = 0; i < this->GetNumRobots(); i++) {
849 InitializeLocalCfgs();
851 auto robots = group->GetRobots();
852 for(
size_t i = 0; i < robots.size(); i++) {
853 auto robot = robots[i];
856 if(found.count(robot))
864 this->m_localCfgs[i] = cfg;
868 template <
typename GraphType>
875 template <
typename GraphType>
880 for(
size_t i = 0; i < this->GetNumRobots(); ++i)
881 this->GetRobotCfg(i).NormalizeOrientation();
883 for(
size_t i : _robots)
884 this->GetRobotCfg(i).NormalizeOrientation();
889 template <
typename GraphType>
893 std::ostringstream oss;
894 oss.precision(_precision);
896 for(
size_t i = 0; i < this->GetNumRobots(); ++i) {
898 if(this->IsLocalCfg(i))
900 oss << robotCfg.PrettyPrint(_precision) <<
", ";
909 template <
typename GraphType>
915 const size_t numRobots = this->GetNumRobots();
916 if(this->m_localCfgs.size() == numRobots)
919 this->m_localCfgs.clear();
920 this->m_localCfgs.resize(numRobots);
922 for(
size_t i = 0; i < numRobots; ++i)
923 this->m_localCfgs[i] = IndividualCfg(this->GetRobot(i));
926 template <
typename GraphType>
927 template <
class DistanceMetricPo
inter>
930 GetRandomRay(
const double _length, DistanceMetricPointer _dm,
const bool _norm) {
933 for(
size_t j = 0; j < this->GetNumRobots(); ++j) {
934 for(
size_t i = 0; i < this->GetRobotCfg(j).DOF(); ++i)
935 this->GetRobotCfg(j)[i] =
GRand();
938 _dm->ScaleCfg(_length, *
this);
942 NormalizeOrientation();
947 template <
typename GraphType>
#define INVALID_VID
Definition: GenericStateGraph.h:23
std::ostream & operator<<(std::ostream &_os, const GroupCfg< GraphType > &_groupCfg)
Definition: GroupCfg.h:949
double GRand(bool _reset)
Definition: MPUtils.cpp:13
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
Definition: Boundary.h:30
virtual void GetRandomCfg(const Boundary *const _b)
Definition: Cfg.cpp:902
Definition: CompositeGraph.h:27
virtual RobotGroup * GetGroup()
Get the robot group.
Definition: CompositeGraph.h:190
Definition: CompositeState.h:26
GraphType::CfgType CfgType
The indiv. graph vertex type.
Definition: CompositeState.h:35
size_t VID
A VID in an individual graph.
Definition: CompositeState.h:33
virtual size_t GetNumRobots() const noexcept
Get the number of robots in this composite state.
Definition: CompositeState.h:269
virtual CfgType & GetRobotCfg(Robot *const _robot)
Definition: CompositeState.h:393
RobotGroup * m_group
The robot group for this state.
Definition: CompositeState.h:181
Definition: Environment.h:137
Boundary * GetBoundary() const noexcept
Get the single boundary of the environemnt.
Definition: Environment.cpp:622
Definition: GroupCfg.h:39
CompositeState< GraphType > BaseType
Definition: GroupCfg.h:46
void ApplyTransformationForRobots(const Formation &_robotList, const mathtool::Transformation &_transform, const mathtool::Transformation &_relativeTransform=mathtool::Transformation())
Definition: GroupCfg.h:629
void FindIncrement(const GroupCfg &_start, const GroupCfg &_goal, const int _nTicks)
Definition: GroupCfg.h:787
void GetRandomGroupCfg(const Boundary *const _b)
Definition: GroupCfg.h:842
bool operator==(const GroupCfg &_other) const noexcept
Definition: GroupCfg.h:352
void SetGroupRoadmap(GroupRoadmapType *const _newRoadmap)
Definition: GroupCfg.h:486
bool InBounds(const Boundary *const _b) const noexcept
Definition: GroupCfg.h:823
GroupCfg & operator*=(const double &_val)
Definition: GroupCfg.h:464
GroupCfg operator*(const double &_other) const
Definition: GroupCfg.h:419
GroupRoadmapType * GetGroupRoadmap() const noexcept
Get the group roadmap this group cfg is with respect to.
Definition: GroupCfg.h:478
double Magnitude() const
Compute the composite magnitude.
Definition: GroupCfg.h:527
BaseType::CfgType IndividualCfg
Definition: GroupCfg.h:51
BaseType::GroupGraphType GroupGraphType
Definition: GroupCfg.h:50
GroupCfg operator-(const GroupCfg &_other) const
Definition: GroupCfg.h:410
void SetData(const std::vector< double > &_dofs)
Definition: GroupCfg.h:767
double PositionMagnitude() const
Compute the composite manitude of the positional components.
Definition: GroupCfg.h:540
size_t CompositeDOF() const
Compute the total DOF for this robot group.
Definition: GroupCfg.h:516
GroupRoadmap< GroupCfg, GroupLocalPlan< GraphType > > GroupRoadmapType
Definition: GroupCfg.h:47
GroupCfg operator+(const GroupCfg &_other) const
Definition: GroupCfg.h:401
bool IsNonholonomic() const noexcept
Check if there is a nonholonomic robot in the group.
Definition: GroupCfg.h:505
bool WithinResolution(const GroupCfg &_cfg, const double _posRes, const double _oriRes) const
Definition: GroupCfg.h:576
double OrientationMagnitude() const
Compute the composite magnitude of the orientation components.
Definition: GroupCfg.h:553
std::vector< size_t > Formation
Definition: GroupCfg.h:58
void GetRandomRay(const double _length, DistanceMetricPointer _dm, const bool _norm=true)
Definition: GroupCfg.h:930
virtual void NormalizeOrientation(const std::vector< size_t > &_robots={}) noexcept
Normalize Orientation DOFs for a Group Cfg.
Definition: GroupCfg.h:878
bool operator<(const GroupCfg &_other) const noexcept
Definition: GroupCfg.h:381
void AddDofsForRobots(const std::vector< double > &_dofs, const Formation &_robots)
Definition: GroupCfg.h:662
GroupCfg & operator-=(const GroupCfg &_other)
Definition: GroupCfg.h:446
GroupCfg(GroupRoadmapType *const &_groupMap=nullptr)
Definition: GroupCfg.h:340
void RotateFormationAboutLeader(const Formation &_robotList, const mathtool::Orientation &_rotation, const bool _debug=false)
Definition: GroupCfg.h:590
std::string PrettyPrint(const size_t _precision=4) const
Definition: GroupCfg.h:892
GroupCfg & operator+=(const GroupCfg &_other)
Definition: GroupCfg.h:428
void ConfigureRobot() const
Definition: GroupCfg.h:567
BaseType::VID VID
Definition: GroupCfg.h:49
void OverwriteDofsForRobots(const std::vector< double > &_dofs, const Formation &_robots)
Definition: GroupCfg.h:713
Definition: GroupRoadmap.h:25
A group of one or more robots.
Definition: RobotGroup.h:17
size_t GetGroupIndex(Robot *const _robot) const noexcept
Definition: RobotGroup.cpp:108
Definition: PMPLExceptions.h:62