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
40 
41 
42 // DO NOT EDIT NEXT LINE
43 DynamicPlatformObstacleAvoidance::SubClassRegistry
45  DynamicPlatformObstacleAvoidance::GetName(),
47 
48 
49 void
51 {
52  // put your user code for the enter-point here
53  // execution time should be short (<100ms)
54 }
55 
56 
57 void
59 {
60  ARMARX_VERBOSE << "Starting platform movement towards target position.";
61 
62  // Component proxies.
63  //OpenPoseEstimationInterfacePrx openPoseEstimation = getOpenPoseEstimation();
64  //HumanObstacleDetectionInterfacePrx humanObstacleDetection = getHumanObstacleDetection();
65  // LaserScannerObstacleDetectionInterfacePrx laserScannerObstacleDetection = getLaserScannerObstacleDetection();
66  // DynamicObstacleManagerInterfacePrx dynamicObstacleManager = getDynamicObstacleManager();
67 
68  PlatformUnitInterfacePrx platform = getPlatformUnit2();
69  VirtualRobot::RobotPtr robot = getLocalRobot();
70 
71  // LEGACY, will be removed.
72  if (in.isGoalNameSet())
73  {
74  ARMARX_WARNING << "Property `GoalName` with value `" << in.getGoalName()
75  << "` is deprecated and will be ignored! Unset this property and use `GoalPose` instead. ";
76  }
77 
78  // Get parameters.
79  const Eigen::Vector3f target_pose = in.getGoalPose()->toEigen();
80  const std::vector<ObstacleAvoidingPlatformUnitHelper::Target> waypoints = [&]
81  {
82  std::vector<ObstacleAvoidingPlatformUnitHelper::Target> waypoints;
83 
84  if (in.isWaypointsPoseListSet())
85  {
86  const std::vector<armarx::Vector3Ptr> waypoints_eigen = in.getWaypointsPoseList();
87  waypoints.reserve(waypoints_eigen.size());
88  std::transform(waypoints_eigen.begin(), 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 
138 void
139 DynamicPlatformObstacleAvoidance::onExit()
140 {
141  // put your user code for the exit point here
142  // execution time should be short (<100ms)
143  PlatformUnitInterfacePrx platform = getPlatformUnit2();
144  platform->stopPlatform();
145 }
146 
147 
148 // DO NOT EDIT NEXT FUNCTION
150 DynamicPlatformObstacleAvoidance::CreateInstance(XMLStateConstructorParams stateData)
151 {
153 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance::run
void run() override
Definition: DynamicPlatformObstacleAvoidance.cpp:58
armarx::RemoteRobot::synchronizeLocalClone
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
Definition: RemoteRobot.cpp:448
armarx::ObstacleAvoidingPlatformUnitHelper::Config::pos_reached_threshold
float pos_reached_threshold
Definition: ObstacleAvoidingPlatformUnitHelper.h:47
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armarx::DynamicPlatformObstacleAvoidanceGroup
Definition: DynamicPlatformObstacleAvoidance.h:30
IceInternal::Handle< Vector3 >
armarx::ObstacleAvoidingPlatformUnitHelper::Config
Definition: ObstacleAvoidingPlatformUnitHelper.h:45
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance::onEnter
void onEnter() override
Definition: DynamicPlatformObstacleAvoidance.cpp:50
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance::Registry
static SubClassRegistry Registry
Definition: DynamicPlatformObstacleAvoidance.h:51
armarx::ObstacleAvoidingPlatformUnitHelper::Config::ori_near_threshold
float ori_near_threshold
Definition: ObstacleAvoidingPlatformUnitHelper.h:50
armarx::ObstacleAvoidingPlatformUnitHelper::Config::ori_reached_threshold
float ori_reached_threshold
Definition: ObstacleAvoidingPlatformUnitHelper.h:48
armarx::ObstacleAvoidingPlatformUnitHelper
Definition: ObstacleAvoidingPlatformUnitHelper.h:40
CycleUtil.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
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:315
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DynamicPlatformObstacleAvoidance.cpp:150
armarx::DynamicPlatformObstacleAvoidanceGroup::DynamicPlatformObstacleAvoidance
Definition: DynamicPlatformObstacleAvoidance.h:32
armarx::ObstacleAvoidingPlatformUnitHelper::Config::pos_near_threshold
float pos_near_threshold
Definition: ObstacleAvoidingPlatformUnitHelper.h:49
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
DynamicPlatformObstacleAvoidance.h
ObstacleAvoidingPlatformUnitHelper.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18