BlimpPlanning.cpp
1 /*********************************************************************
2 * Rice University Software Distribution License
3 *
4 * Copyright (c) 2010, Rice University
5 * All Rights Reserved.
6 *
7 * For a full description see the file named LICENSE.
8 *
9 *********************************************************************/
10 
11 /* Author: Mark Moll */
12 
13 #include "omplapp/apps/BlimpPlanning.h"
14 
15 ompl::base::ScopedState<> ompl::app::BlimpPlanning::getDefaultStartState() const
16 {
17  base::ScopedState<base::SE3StateSpace> s(getGeometricComponentStateSpace());
18  aiVector3D c = getRobotCenter(0);
19 
20  s->setXYZ(c.x, c.y, c.z);
21  s->rotation().setIdentity();
22  return getFullStateFromGeometricComponent(s);
23 }
24 
25 ompl::base::ScopedState<> ompl::app::BlimpPlanning::getFullStateFromGeometricComponent(
26  const base::ScopedState<> &state) const
27 {
28  const base::SO3StateSpace::StateType& rot = state->as<base::SE3StateSpace::StateType>()->rotation();
29  double norm = sqrt(rot.z * rot.z + rot.w * rot.w);
30  base::ScopedState<> s(getStateSpace());
32  s->as<base::CompoundStateSpace::StateType>()->as<base::SE3StateSpace::StateType>(0)->rotation();
33  s = 0.0;
34  // set x,y,z
35  for (unsigned int i=0; i<3; ++i)
36  s[i] = state[i];
37  // set heading
38  rot2.z = rot.z / norm;
39  rot2.w = rot.w / norm;
40  return s;
41 }
42 
43 void ompl::app::BlimpPlanning::postPropagate(const base::State* /*state*/, const control::Control* /*control*/, const double /*duration*/, base::State *result)
44 {
45  // Constrain orientation of the blimp about the z axis.
48  pose.rotation().setAxisAngle(0,0,1, pose.rotation().x);
49 
50  // Enforce velocity bounds
51  getStateSpace()->as<base::CompoundStateSpace>()->getSubspace(1)->enforceBounds(s[1]);
52 
53  // Enforce steering bounds
54  getStateSpace()->as<base::CompoundStateSpace>()->getSubspace(2)->enforceBounds(s[2]);
55 }
56 
57 void ompl::app::BlimpPlanning::ode(const control::ODESolver::StateType& q, const control::Control *ctrl, control::ODESolver::StateType& qdot)
58 {
59  // Retrieving control inputs
60  const double *u = ctrl->as<control::RealVectorControlSpace::ControlType>()->values;
61 
62  // zero out qdot
63  qdot.resize (q.size (), 0);
64 
65  qdot[0] = q[7];
66  qdot[1] = q[8];
67  qdot[2] = q[9];
68 
69  qdot[3] = q[10];
70 
71  qdot[7] = u[0] * cos(q[3]);
72  qdot[8] = u[0] * sin(q[3]);
73  qdot[9] = u[1];
74  qdot[10] = u[2];
75 }
76 
77 ompl::base::StateSpacePtr ompl::app::BlimpPlanning::constructStateSpace()
78 {
79  auto stateSpace(std::make_shared<base::CompoundStateSpace>());
80 
81  stateSpace->addSubspace(std::make_shared<base::SE3StateSpace>(), 1.);
82  stateSpace->addSubspace(std::make_shared<base::RealVectorStateSpace>(3), .3);
83  stateSpace->addSubspace(std::make_shared<base::RealVectorStateSpace>(1), .3);
84  stateSpace->lock();
85  return stateSpace;
86 }
87 
88 void ompl::app::BlimpPlanning::setDefaultBounds()
89 {
90  base::RealVectorBounds velbounds(3), omegabounds(1), controlbounds(3);
91 
92  velbounds.setLow(-1);
93  velbounds.setHigh(1);
94  getStateSpace()->as<base::CompoundStateSpace>()->as<base::RealVectorStateSpace>(1)->setBounds(velbounds);
95  omegabounds.setLow(-.2);
96  omegabounds.setHigh(.2);
97  getStateSpace()->as<base::CompoundStateSpace>()->as<base::RealVectorStateSpace>(2)->setBounds(omegabounds);
98  controlbounds.setLow(-1);
99  controlbounds.setHigh(1);
100  controlbounds.setLow(2,-.3);
101  controlbounds.setHigh(2,.3);
102  getControlSpace()->as<control::RealVectorControlSpace>()->setBounds(controlbounds);
103 
104 }
const base::StateSpacePtr & getStateSpace() const
Get the current instance of the state space.
Definition: SimpleSetup.h:87
Definition of a scoped state.
Definition: ScopedState.h:56
A shared pointer wrapper for ompl::base::StateSpace.
aiVector3D getRobotCenter(unsigned int robotIndex) const
Get the robot&#39;s center (average of all the vertices of all its parts)
const T * as() const
Cast this instance to a desired type.
Definition: State.h:66
ompl::base::CompoundState StateType
Define the type of state allocated by this state space.
Definition: StateSpace.h:577
ompl::base::State StateType
Define the type of state allocated by this space.
Definition: StateSpace.h:78
std::vector< double > StateType
Portable data type for the state values.
Definition: ODESolver.h:73
const T * as(unsigned int index) const
Cast a component of this instance to a desired type.
Definition: State.h:95