DynamicPlatformObstacleAvoidance.cpp
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 Armar6Skills::DynamicPlatformObstacleAvoidanceGroup
17  * @author Mirko Wächter ( mirko dot waechter at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
26 
27 
28 // Eigen
29 #include <Eigen/Geometry>
30 
31 // Ice
32 #include <IceUtil/Time.h>
33 
34 // Simox
35 #include <VirtualRobot/Nodes/RobotNode.h>
36 
37 // ArmarX
39 
41 
42 
43 // DO NOT EDIT NEXT LINE
44 DynamicPlatformObstacleAvoidance::SubClassRegistry
45  DynamicPlatformObstacleAvoidance::Registry(DynamicPlatformObstacleAvoidance::GetName(),
47 
48 void
50 {
51  // put your user code for the enter-point here
52  // execution time should be short (<100ms)
53 }
54 
55 void
57 {
58  ARMARX_VERBOSE << "Starting platform movement towards target position.";
59 
60  // Component proxies.
61  //OpenPoseEstimationInterfacePrx openPoseEstimation = getOpenPoseEstimation();
62  //HumanObstacleDetectionInterfacePrx humanObstacleDetection = getHumanObstacleDetection();
63  // LaserScannerObstacleDetectionInterfacePrx laserScannerObstacleDetection = getLaserScannerObstacleDetection();
64  // DynamicObstacleManagerInterfacePrx dynamicObstacleManager = getDynamicObstacleManager();
65 
66  PlatformUnitInterfacePrx platform = getPlatformUnit2();
67  VirtualRobot::RobotPtr robot = getLocalRobot();
68 
69  // LEGACY, will be removed.
70  if (in.isGoalNameSet())
71  {
72  ARMARX_WARNING << "Property `GoalName` with value `" << in.getGoalName()
73  << "` is deprecated and will be ignored! Unset this property and use "
74  "`GoalPose` instead. ";
75  }
76 
77  // Get parameters.
78  const Eigen::Vector3f target_pose = in.getGoalPose()->toEigen();
79  const std::vector<ObstacleAvoidingPlatformUnitHelper::Target> waypoints = [&]
80  {
81  std::vector<ObstacleAvoidingPlatformUnitHelper::Target> waypoints;
82 
83  if (in.isWaypointsPoseListSet())
84  {
85  const std::vector<armarx::Vector3Ptr> waypoints_eigen = in.getWaypointsPoseList();
86  waypoints.reserve(waypoints_eigen.size());
87  std::transform(waypoints_eigen.begin(),
88  waypoints_eigen.end(),
89  std::back_inserter(waypoints),
90  [](const armarx::Vector3Ptr av)
91  {
92  const Eigen::Vector3f v = av->toEigen();
93  return ObstacleAvoidingPlatformUnitHelper::Target{v.head<2>(), v[2]};
94  });
95  }
96 
97  return waypoints;
98  }();
99  const Eigen::Vector2f target_pos = target_pose.head<2>();
100  const float target_ori = target_pose(2);
101 
103  cfg.pos_reached_threshold = in.getPositionReachedThreshold();
104  cfg.ori_reached_threshold = in.getAngleReachedThreshold();
105  cfg.pos_near_threshold = in.getPositionNearThreshold();
106  cfg.ori_near_threshold = in.getAngleNearThreshold();
107 
108  // enable obstacle detection
109  //openPoseEstimation->start3DPoseEstimation();
110  //humanObstacleDetection->enable();
111  // laserScannerObstacleDetection->enable();
112  // dynamicObstacleManager->wait_unitl_obstacles_are_ready();
113 
114  ObstacleAvoidingPlatformUnitHelper platform_ctrl{platform, robot, cfg};
115  platform_ctrl.setMaxVelocities(in.getMaxVelocity(), in.getMaxAngularVelocity());
116  platform_ctrl.setWaypoints(waypoints);
117  platform_ctrl.addWaypoint(target_pos, target_ori);
118 
119  CycleUtil cycle{IceUtil::Time::milliSeconds(10)};
120  while (not isRunningTaskStopped() and not platform_ctrl.isFinalTargetReached())
121  {
122  RemoteRobot::synchronizeLocalClone(robot, getRobotStateComponent());
123  platform_ctrl.update();
124  cycle.waitForCycleDuration();
125  }
126 
127  ARMARX_VERBOSE << "Stopping platform now.";
128  platform->stopPlatform();
129 
130  //openPoseEstimation->stop();
131  //humanObstacleDetection->disable();
132  // laserScannerObstacleDetection->disable();
133 
134  platform_ctrl.isFinalTargetReached() ? emitSuccess() : emitFailure();
135 }
136 
137 void
138 DynamicPlatformObstacleAvoidance::onExit()
139 {
140  // put your user code for the exit point here
141  // execution time should be short (<100ms)
142  PlatformUnitInterfacePrx platform = getPlatformUnit2();
143  platform->stopPlatform();
144 }
145 
146 // DO NOT EDIT NEXT FUNCTION
148 DynamicPlatformObstacleAvoidance::CreateInstance(XMLStateConstructorParams stateData)
149 {
151 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance::run
void run() override
Definition: DynamicPlatformObstacleAvoidance.cpp:56
armarx::RemoteRobot::synchronizeLocalClone
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
Definition: RemoteRobot.cpp:522
armarx::ObstacleAvoidingPlatformUnitHelper::Config::pos_reached_threshold
float pos_reached_threshold
Definition: ObstacleAvoidingPlatformUnitHelper.h:45
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armarx::DynamicPlatformObstacleAvoidanceGroup
Definition: DynamicPlatformObstacleAvoidance.h:29
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< Vector3 >
armarx::ObstacleAvoidingPlatformUnitHelper::Config
Definition: ObstacleAvoidingPlatformUnitHelper.h:43
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance::onEnter
void onEnter() override
Definition: DynamicPlatformObstacleAvoidance.cpp:49
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance::Registry
static SubClassRegistry Registry
Definition: DynamicPlatformObstacleAvoidance.h:51
armarx::ObstacleAvoidingPlatformUnitHelper::Config::ori_near_threshold
float ori_near_threshold
Definition: ObstacleAvoidingPlatformUnitHelper.h:48
armarx::ObstacleAvoidingPlatformUnitHelper::Config::ori_reached_threshold
float ori_reached_threshold
Definition: ObstacleAvoidingPlatformUnitHelper.h:46
armarx::ObstacleAvoidingPlatformUnitHelper
Definition: ObstacleAvoidingPlatformUnitHelper.h:39
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT >>
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:351
CycleUtil.h
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DynamicPlatformObstacleAvoidance.cpp:148
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance
Definition: DynamicPlatformObstacleAvoidance.h:31
armarx::ObstacleAvoidingPlatformUnitHelper::Config::pos_near_threshold
float pos_near_threshold
Definition: ObstacleAvoidingPlatformUnitHelper.h:47
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
DynamicPlatformObstacleAvoidance.h
ObstacleAvoidingPlatformUnitHelper.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19