Loading...
Searching...
No Matches
KoulesStateSpace.cpp
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2013, 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 the 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: Beck Chen, Mark Moll */
36
37#include "KoulesConfig.h"
38#include "KoulesStateSpace.h"
39#include "KoulesProjection.h"
40
41namespace ob = ompl::base;
42
43KoulesStateSpace::KoulesStateSpace(unsigned int numKoules)
44 : RealVectorStateSpace(4 * numKoules + 5), mass_(numKoules + 1, kouleMass), radius_(numKoules + 1, kouleRadius)
45{
46 mass_[0] = shipMass;
47 radius_[0] = shipRadius;
48 setName("Koules" + std::to_string(numKoules) + getName());
49 // layout: (x_s y_s vx_s vy_s theta_s ... x_i y_i vx_i vy_i ... ),
50 // where (x_i, y_i) is the position of koule i (i=1,..,numKoules),
51 // (vx_i, vy_i) its velocity, (x_s, y_s) the position of the ship,
52 // (vx_s, vy_s) its velocity, and theta_s its orientation.
53
54 // create the bounds
55 unsigned int j = 0;
56 // set the bounds for the ship's position
57 bounds_.setLow(j, shipRadius);
58 bounds_.setHigh(j++, sideLength - shipRadius);
59 bounds_.setLow(j, shipRadius);
60 bounds_.setHigh(j++, sideLength - shipRadius);
61 // set the bounds for the ship's velocity
62 bounds_.setLow(j, -10.);
63 bounds_.setHigh(j++, 10.);
64 bounds_.setLow(j, -10.);
65 bounds_.setHigh(j++, 10.);
66 // set bounds on orientation
67 bounds_.setLow(j, -boost::math::constants::pi<double>());
68 bounds_.setHigh(j++, boost::math::constants::pi<double>());
69 for (unsigned int i = 0; i < numKoules; ++i)
70 {
71 // set the bounds for koule i's position
72 bounds_.setLow(j, -2. * kouleRadius);
73 bounds_.setHigh(j++, sideLength + 2. * kouleRadius);
74 bounds_.setLow(j, -2. * kouleRadius);
75 bounds_.setHigh(j++, sideLength + 2. * kouleRadius);
76 // set the bounds for koule i's velocity
77 bounds_.setLow(j, -10);
78 bounds_.setHigh(j++, 10.);
79 bounds_.setLow(j, -10.);
80 bounds_.setHigh(j++, 10.);
81 }
82}
83
84void KoulesStateSpace::registerProjections()
85{
86 registerDefaultProjection(std::make_shared<KoulesProjection>(this, 3));
87 registerProjection("PDSTProjection", std::make_shared<KoulesProjection>(this, (getDimension() - 1) / 2 + 1));
88}
89
90bool KoulesStateSpace::isDead(const ompl::base::State *state, unsigned int i) const
91{
92 const auto *s = static_cast<const StateType *>(state);
93 return s->values[i != 0u ? 4 * i + 1 : 0] == -2. * kouleRadius;
94}
Definition of an abstract state.
Definition State.h:50
This namespace contains sampling based planning routines shared by both planning under geometric cons...