CollisionAvoidanceCore.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ...
17  * @author Jianfeng Gao ( jianfeng dot gao at kit dot edu )
18  * @date 2024
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <VirtualRobot/Robot.h>
26 
28 
30 #include <armarx/control/common/control_law/aron/CollisionAvoidanceConfig.aron.generated.h>
31 
32 #include <simox/control/environment/CollisionRobot.h>
33 #include <simox/control/geodesics/metric/inertia.h>
34 #include <simox/control/impl/simox/robot/Robot.h>
35 
37 {
38 
40 
41  /**
42  * @defgroup Library-CollisionAvoidanceBase CollisionAvoidanceBase
43  * @ingroup Library-RobotUnit-NJointControllers
44  * A description of the library CollisionAvoidanceBase.
45  *
46  * @class CollisionAvoidanceBase
47  * @ingroup Library-CollisionAvoidanceBase
48  * @brief Brief description of class CollisionAvoidanceBase.
49  *
50  * Detailed description of class CollisionAvoidanceBase.
51  */
53  {
54 
55  public:
57  using SimoxRobotPtr = std::shared_ptr<SimoxRobot>;
58  using DistanceResults = std::vector<::simox::control::environment::DistanceResult>;
59  using DistanceResultsPtr = std::shared_ptr<DistanceResults>;
60  using CollisionRobot = ::simox::control::environment::CollisionRobot<hpp::fcl::OBBRSS>;
61  using CollisionRobotPtr = std::unique_ptr<CollisionRobot>;
62  using InertiaPtr = std::shared_ptr<simox::control::geodesics::metric::Inertia>;
63  using CtrlConfig = armarx::control::common::control_law::arondto::CollisionAvoidanceConfig;
64  using Config =
65  ::armarx::control::common::control_law::arondto::CollisionAvoidanceConfigDict;
66  using ConfigPtr = std::shared_ptr<Config>;
67  using RtStatus = law::CollisionAvoidanceController::RtStatusForSafetyStrategy;
68 
69  // using ConfigDict = std::map<std::string, ConfigPtr>;
70 
72  {
73  std::string nodeSetName;
74 
75  /// !!!!!!! Note that, all the data below should only be accessed in rt thread !!!!!!!
76  VirtualRobot::RobotNodeSetPtr rtRNS;
77  std::string tcpName;
78  std::vector<std::string> jointNames;
79 
80  /// controller (maths)
82  RtStatus rts; // should only be used in rt thread
84 
85  /// self-collision avoidance
88  std::shared_ptr<std::vector<int>> pointsOnArm;
90 
91  // reduced robot required to get node where contact point is located to compute Jacobian
93 
95  const std::string& robotNodeSetName,
96  SimoxRobotPtr simoxReducedRobot,
97  SimoxRobotPtr simoxControlRobot,
99  Config& c);
100  void reset(Config& c);
101  };
102 
103  using CollArmPtr = std::shared_ptr<CollisionAvoidanceArmData>;
104 
105  CollisionAvoidanceBase(const VirtualRobot::RobotPtr& rtRobot, const Config& cfg);
107 
108  void rtCollisionChecking();
109  void rtLimbControllerRun(const std::string& robotNodeSetName,
110  Eigen::VectorXf& qpos,
111  Eigen::VectorXf& qvelFiltered,
112  float torqueLimit,
113  Eigen::VectorXf& impedanceJointTorque);
114  void rtPreActivate();
115  void rtPostDeactivate();
116  void updateRtConfigFromUser();
117 
118  std::map<std::string, CollArmPtr> collLimb;
119  Config userCfg; // used in nonRT
121 
122  void validateConfigData(Config& cfg);
123  void setUserCfg(const Config& cfg);
124 
125  protected:
130 
131  std::vector<std::string> actuatedJointNames; /// TODO, rename to actuatedJointNames
132  Eigen::VectorXd qposActuatedJoints;
133  std::vector<int> translationJointIndex;
134  //int qposActuatedJointsIndex;
135 
136  private:
137  float preFilterDistance = 0.6; // in meter
138  // int maxCollisionPairs = 100;
139 
140  Config rtCfg; // used in RT
141  VirtualRobot::RobotPtr rtRobot;
142  };
143 
144  using CollisionAvoidanceBasePtr = std::shared_ptr<CollisionAvoidanceBase>;
145 } // namespace armarx::control::njoint_controller::core
armarx::control::njoint_controller::core::CollisionAvoidanceBase::setUserCfg
void setUserCfg(const Config &cfg)
Definition: CollisionAvoidanceCore.cpp:319
armarx::control::njoint_controller::core::CollisionAvoidanceBase::ConfigPtr
std::shared_ptr< Config > ConfigPtr
Definition: CollisionAvoidanceCore.h:66
armarx::control::njoint_controller::core::CollisionAvoidanceBase::~CollisionAvoidanceBase
~CollisionAvoidanceBase()
Definition: CollisionAvoidanceCore.cpp:92
armarx::control::njoint_controller::core::CollisionAvoidanceBase::collisionRobotPtr
CollisionRobotPtr collisionRobotPtr
Definition: CollisionAvoidanceCore.h:126
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceBase
CollisionAvoidanceBase(const VirtualRobot::RobotPtr &rtRobot, const Config &cfg)
Definition: CollisionAvoidanceCore.cpp:6
armarx::control::njoint_controller::core::CollisionAvoidanceBase::SimoxRobot
::simox::control::simox::robot::Robot SimoxRobot
Definition: CollisionAvoidanceCore.h:56
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::inertiaPtr
InertiaPtr inertiaPtr
self-collision avoidance
Definition: CollisionAvoidanceCore.h:86
armarx::control::njoint_controller::core::CollisionAvoidanceBase::rtPreActivate
void rtPreActivate()
Definition: CollisionAvoidanceCore.cpp:144
armarx::control::njoint_controller::core::CollisionAvoidanceBase::userCfg
Config userCfg
Definition: CollisionAvoidanceCore.h:119
armarx::control::njoint_controller::core::CollisionAvoidanceBase::SimoxRobotPtr
std::shared_ptr< SimoxRobot > SimoxRobotPtr
Definition: CollisionAvoidanceCore.h:57
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData
Definition: CollisionAvoidanceCore.h:71
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::tcpName
std::string tcpName
Definition: CollisionAvoidanceCore.h:77
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionRobot
::simox::control::environment::CollisionRobot< hpp::fcl::OBBRSS > CollisionRobot
Definition: CollisionAvoidanceCore.h:60
armarx::control::njoint_controller::core::CollisionAvoidanceBase::Config
::armarx::control::common::control_law::arondto::CollisionAvoidanceConfigDict Config
Definition: CollisionAvoidanceCore.h:65
armarx::control::njoint_controller::core::CollisionAvoidanceBase::actuatedJointNames
std::vector< std::string > actuatedJointNames
Definition: CollisionAvoidanceCore.h:131
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::jointNames
std::vector< std::string > jointNames
Definition: CollisionAvoidanceCore.h:78
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::rts
RtStatus rts
Definition: CollisionAvoidanceCore.h:82
armarx::control::njoint_controller::core::CollisionAvoidanceBase::rtLimbControllerRun
void rtLimbControllerRun(const std::string &robotNodeSetName, Eigen::VectorXf &qpos, Eigen::VectorXf &qvelFiltered, float torqueLimit, Eigen::VectorXf &impedanceJointTorque)
Definition: CollisionAvoidanceCore.cpp:275
armarx::control::njoint_controller::core
This file is part of ArmarX.
Definition: CollisionAvoidanceCore.cpp:3
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::nodeSetName
std::string nodeSetName
Definition: CollisionAvoidanceCore.h:73
armarx::control::njoint_controller::core::CollisionAvoidanceBasePtr
std::shared_ptr< CollisionAvoidanceBase > CollisionAvoidanceBasePtr
Definition: CollisionAvoidanceCore.h:144
armarx::control::njoint_controller::core::CollisionAvoidanceBase::bufferCfgUserToRT
armarx::TripleBuffer< Config > bufferCfgUserToRT
Definition: CollisionAvoidanceCore.h:120
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::CollisionAvoidanceArmData
CollisionAvoidanceArmData(VirtualRobot::RobotPtr rtRobot, const std::string &robotNodeSetName, SimoxRobotPtr simoxReducedRobot, SimoxRobotPtr simoxControlRobot, DistanceResultsPtr collisionPairs, Config &c)
Definition: CollisionAvoidanceCore.cpp:97
armarx::control::njoint_controller::core::CollisionAvoidanceBase::DistanceResults
std::vector<::simox::control::environment::DistanceResult > DistanceResults
Definition: CollisionAvoidanceCore.h:58
armarx::control::njoint_controller::core::CollisionAvoidanceBase::qposActuatedJoints
Eigen::VectorXd qposActuatedJoints
TODO, rename to actuatedJointNames.
Definition: CollisionAvoidanceCore.h:132
armarx::control::njoint_controller::core::CollisionAvoidanceBase::translationJointIndex
std::vector< int > translationJointIndex
Definition: CollisionAvoidanceCore.h:133
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CtrlConfig
armarx::control::common::control_law::arondto::CollisionAvoidanceConfig CtrlConfig
Definition: CollisionAvoidanceCore.h:63
armarx::control::njoint_controller::core::CollisionAvoidanceBase::updateRtConfigFromUser
void updateRtConfigFromUser()
Definition: CollisionAvoidanceCore.cpp:162
armarx::control::common::control_law::CollisionAvoidanceController
Definition: CollisionAvoidance.h:58
armarx::control::njoint_controller::core::CollisionAvoidanceBase::simoxReducedRobotPtr
SimoxRobotPtr simoxReducedRobotPtr
Definition: CollisionAvoidanceCore.h:128
armarx::armem::human::Robot
@ Robot
Definition: util.h:14
armarx::control::njoint_controller::core::CollisionAvoidanceBase::rtPostDeactivate
void rtPostDeactivate()
Definition: CollisionAvoidanceCore.cpp:153
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::collisionPairsPtr
DistanceResultsPtr collisionPairsPtr
Definition: CollisionAvoidanceCore.h:87
armarx::control::njoint_controller::core::CollisionAvoidanceBase::DistanceResultsPtr
std::shared_ptr< DistanceResults > DistanceResultsPtr
Definition: CollisionAvoidanceCore.h:59
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollArmPtr
std::shared_ptr< CollisionAvoidanceArmData > CollArmPtr
Definition: CollisionAvoidanceCore.h:103
armarx::control::njoint_controller::core::CollisionAvoidanceBase::simoxControlRobotPtr
SimoxRobotPtr simoxControlRobotPtr
Definition: CollisionAvoidanceCore.h:127
armarx::control::njoint_controller::core::CollisionAvoidanceBase::RtStatus
law::CollisionAvoidanceController::RtStatusForSafetyStrategy RtStatus
Definition: CollisionAvoidanceCore.h:67
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::bufferRTtoPublish
armarx::TripleBuffer< RtStatus > bufferRTtoPublish
Definition: CollisionAvoidanceCore.h:83
armarx::control::njoint_controller::core::CollisionAvoidanceBase::InertiaPtr
std::shared_ptr< simox::control::geodesics::metric::Inertia > InertiaPtr
Definition: CollisionAvoidanceCore.h:62
TripleBuffer.h
armarx::control::njoint_controller::core::CollisionAvoidanceBase::collLimb
std::map< std::string, CollArmPtr > collLimb
Definition: CollisionAvoidanceCore.h:118
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::controller
law::CollisionAvoidanceController controller
controller (maths)
Definition: CollisionAvoidanceCore.h:81
CollisionAvoidance.h
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::reset
void reset(Config &c)
Definition: CollisionAvoidanceCore.cpp:135
armarx::control::njoint_controller::core::CollisionAvoidanceBase::collisionPairs
DistanceResultsPtr collisionPairs
Definition: CollisionAvoidanceCore.h:129
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::pointsOnArm
std::shared_ptr< std::vector< int > > pointsOnArm
Definition: CollisionAvoidanceCore.h:88
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::pointsOnArmIndex
int pointsOnArmIndex
Definition: CollisionAvoidanceCore.h:89
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionRobotPtr
std::unique_ptr< CollisionRobot > CollisionRobotPtr
Definition: CollisionAvoidanceCore.h:61
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::rtRNS
VirtualRobot::RobotNodeSetPtr rtRNS
!!!!!!! Note that, all the data below should only be accessed in rt thread !!!!!!!
Definition: CollisionAvoidanceCore.h:76
armarx::control::njoint_controller::core::CollisionAvoidanceBase::validateConfigData
void validateConfigData(Config &cfg)
Definition: CollisionAvoidanceCore.cpp:307
armarx::control::njoint_controller::core::CollisionAvoidanceBase::rtCollisionChecking
void rtCollisionChecking()
Definition: CollisionAvoidanceCore.cpp:170
armarx::control::njoint_controller::core::CollisionAvoidanceBase::CollisionAvoidanceArmData::simoxReducedRobotPtr
SimoxRobotPtr simoxReducedRobotPtr
Definition: CollisionAvoidanceCore.h:92
armarx::control::njoint_controller::core::CollisionAvoidanceBase
Brief description of class CollisionAvoidanceBase.
Definition: CollisionAvoidanceCore.h:52
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::TripleBuffer< RtStatus >