Loading...
Searching...
No Matches
LTLProblemDefinition.cpp
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2012, 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: Matt Maly */
36
37#include "ompl/control/PathControl.h"
38#include "ompl/control/planners/ltl/LTLProblemDefinition.h"
39#include "ompl/control/planners/ltl/LTLSpaceInformation.h"
40#include "ompl/base/ProblemDefinition.h"
41
42namespace ob = ompl::base;
43namespace oc = ompl::control;
44
45oc::LTLProblemDefinition::LTLProblemDefinition(const LTLSpaceInformationPtr &ltlsi)
46 : ob::ProblemDefinition(ltlsi), ltlsi_(ltlsi)
47{
48 createGoal();
49}
50
51void oc::LTLProblemDefinition::addLowerStartState(const ob::State *s)
52{
53 ob::ScopedState<ob::CompoundStateSpace> fullStart(si_);
54 ltlsi_->getFullState(s, fullStart.get());
55 addStartState(fullStart);
56}
57
58ob::PathPtr oc::LTLProblemDefinition::getLowerSolutionPath() const
59{
60 PathControl *fullPath = static_cast<PathControl *>(getSolutionPath().get());
61 auto lowPath(std::make_shared<PathControl>(ltlsi_->getLowSpace()));
62
63 if (fullPath->getStateCount() > 0)
64 {
65 for (size_t i = 0; i < fullPath->getStateCount() - 1; ++i)
66 lowPath->append(ltlsi_->getLowLevelState(fullPath->getState(i)), fullPath->getControl(i),
67 fullPath->getControlDuration(i));
68
69 // The last state does not have a control
70 lowPath->append(ltlsi_->getLowLevelState(fullPath->getState(fullPath->getStateCount() - 1)));
71 }
72
73 return lowPath;
74}
75
76void oc::LTLProblemDefinition::createGoal()
77{
78 class LTLGoal : public base::Goal
79 {
80 public:
81 LTLGoal(const LTLSpaceInformationPtr &ltlsi) : ob::Goal(ltlsi), ltlsi_(ltlsi), prod_(ltlsi->getProductGraph())
82 {
83 }
84 ~LTLGoal() override = default;
85 bool isSatisfied(const ob::State *s) const override
86 {
87 return prod_->isSolution(ltlsi_->getProdGraphState(s));
88 }
89
90 protected:
91 const LTLSpaceInformationPtr ltlsi_;
92 const ProductGraphPtr prod_;
93 };
94
95 // Some compilers have trouble with LTLGoal being hidden in this function,
96 // and so we explicitly cast it to its base type.
97 setGoal(std::make_shared<LTLGoal>(ltlsi_));
98}
void addStartState(const State *state)
Add a start state. The state is copied.
SpaceInformationPtr si_
The space information this problem definition is for.
Definition of an abstract state.
Definition State.h:50
A shared pointer wrapper for ompl::control::LTLSpaceInformation.
Definition of a control path.
Definition PathControl.h:61
This namespace contains sampling based planning routines shared by both planning under geometric cons...
This namespace contains sampling based planning routines used by planning under differential constrai...
Definition Control.h:45