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
44DynamicPlatformObstacleAvoidance::SubClassRegistry
45 DynamicPlatformObstacleAvoidance::Registry(DynamicPlatformObstacleAvoidance::GetName(),
47
48void
50{
51 // put your user code for the enter-point here
52 // execution time should be short (<100ms)
53}
54
55void
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
137void
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
This util class helps with keeping a cycle time during a control cycle.
Definition CycleUtil.h:41
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
void setMaxVelocities(float max_vel, float max_angular_vel)
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64