Loading...
Searching...
No Matches
PlanarManipulatorPolyWorld.h
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2015, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Ryan Luna */
36
37#ifndef PLANAR_MANIPULATOR_POLY_WORLD_H_
38#define PLANAR_MANIPULATOR_POLY_WORLD_H_
39
40#include "PolyWorld.h"
41#include <Eigen/Dense>
42#include <cmath>
43#include <vector>
44#include <boost/math/constants/constants.hpp>
45
46// Create the 'corridor' environment for a unit-length planar manipulator with
47// n links. The chain must navigate a narrow gap.
48PolyWorld createCorridorProblem(int n, Eigen::Affine2d &basePose, Eigen::Affine2d &goalPose)
49{
50 // The dimensions of the world.
51 const double minX = 0;
52 const double minY = 0;
53 const double maxX = 1.25;
54 const double maxY = 1.25;
55 PolyWorld world("corridor", {minX, maxX}, {minY, maxY});
56
57 const double len = 1.0 / n;
58 const double gap = len * (1.1 * boost::math::constants::pi<double>() + log(n) / (double)n);
59
60 std::vector<Point> pts(4);
61
62 // two obstacles with a gap in the middle
63 const double w = ((maxX - minX) * 0.50) - gap;
64 const double h1 = minY + gap;
65 const double h2 = maxY - gap;
66
67 pts[0] = std::make_pair(minX, h1);
68 pts[1] = std::make_pair(minX + w, h1);
69 pts[2] = std::make_pair(minX + w, h2);
70 pts[3] = std::make_pair(minX, h2);
71 const ConvexPolygon left_obj(pts);
72
73 pts[0] = std::make_pair(minX + w + gap, h1);
74 pts[1] = std::make_pair(maxX, h1);
75 pts[2] = std::make_pair(maxX, h2);
76 pts[3] = std::make_pair(minX + w + gap, h2);
77 const ConvexPolygon right_obj(pts);
78
79 world.addObstacle(left_obj);
80 world.addObstacle(right_obj);
81
82 // Set the base frame for the manipulator.
83 basePose = Eigen::Affine2d::Identity();
84 basePose.translation()(1) = gap / 2.0; // set the y coordinate of the base.
85
86 // Set the goal frame for the end effector.
87 goalPose = Eigen::Affine2d::Identity();
88 goalPose.translation()(0) = (w + gap) * 0.95;
89 goalPose.translation()(1) = std::min(4.0 * gap, 0.50);
90 goalPose.rotate(0.0);
91
92 return world;
93}
94
95// Create the 'constricted' environment for a planar manipulator with n links
96// and unit-length.
97// The first half of the chain lies in a narrow gap between two obstacles,
98// whereas the second half of the chain is in a fairly open environment.
99// Returns the position of the base of the chain.
100PolyWorld createConstrictedProblem(int n, Eigen::Affine2d &basePose, Eigen::Affine2d &goalPose)
101{
102 const double minX = 0;
103 const double minY = 0;
104 const double maxX = 1.25;
105 const double maxY = 1.25;
106 PolyWorld world("constricted", {minX, maxX}, {minY, maxY});
107
108 const double gap = (log10(n) / (double)n) * 2.0;
109
110 // Make the interior gap small enough so that it is difficult for the
111 // chain to double back on itself on the first half.
112 const double inner_gap = 1.0 / n;
113
114 // robot base at (0, 0.5), chain has unit length.
115 const double robot_y = 0.5;
116 const double ymax = 1.25;
117
118 std::vector<Point> pts(4);
119
120 // lower corridor obstacle
121 const double lower_interior_y = robot_y - inner_gap;
122 const double upper_interior_y = robot_y + inner_gap;
123
124 {
125 pts[0] = std::make_pair(0, 0);
126 pts[1] = std::make_pair(0.5, 0);
127 pts[2] = std::make_pair(0.5, lower_interior_y);
128 pts[3] = std::make_pair(0, lower_interior_y);
129 const ConvexPolygon lower(pts);
130 world.addObstacle(lower);
131 }
132
133 // upper corridor obstacle
134 {
135 pts[0] = std::make_pair(0, upper_interior_y);
136 pts[1] = std::make_pair(0.5, upper_interior_y);
137 pts[2] = std::make_pair(0.5, ymax);
138 pts[3] = std::make_pair(0, ymax);
139 const ConvexPolygon upper(pts);
140 world.addObstacle(upper);
141 }
142
143 // The obstacle separating the start and goal configurations.
144 {
145 pts[0] = std::make_pair(0.5 + gap, 0.5 + (gap / 2.0));
146 pts[1] = std::make_pair(1.0, 0.5 + (gap / 2.0));
147 pts[2] = std::make_pair(1.0, 0.5 + gap);
148 pts[3] = std::make_pair(0.5 + gap, 0.5 + gap);
149 const ConvexPolygon right(pts);
150 world.addObstacle(right);
151 }
152
153 basePose = Eigen::Affine2d::Identity();
154 basePose.translation()(1) = robot_y;
155
156 goalPose = Eigen::Affine2d::Identity();
157 goalPose.translation()(0) = 0.75;
158 goalPose.translation()(1) = 0.5 + 1.5 * gap;
159 goalPose.rotate(0.0);
160
161 return world;
162}
163
164#endif
void log(const char *file, int line, LogLevel level, const char *m,...)
Root level logging function. This should not be invoked directly, but rather used via a logging macro...
Definition Console.cpp:120