Working with States and State Spaces
本教程大概意思应该是:如何使用状态与状态空间对象、以及两者之间的关系,状态空间是整个规划算法的描述基础,我觉得很重要。
1 Allocating memory for states(如何创建对象)
状态对象的内存分配或者说如何创建一个状态对象
1.1 The simple version
从官方提供的两个代码可以看出
- StateSpace:是基本的状态空间对象
- SpaceInformation:是在StateSpace的基础上进一步构建的(从名字可以看出是带有信息的状态空间,因此包含的内容最起码有StateSpace)
- ScopedState:是一种状态,状态是来自状态空间的所以其在StateSpace的基础上构建的(从名字可以看出是一定范围内的某个状态,这个范围就是状态空间)
- StateSpace的创建是通过动态分配内存实现的
- SpaceInformation 与ScopedState 是其他方式构造的。
- 模板参数 T:表示其他各种实际的状态空间类型,比如R3,SE(3),SO(3)R^3,SE(3),SO(3)R3,SE(3),SO(3)等等,从这里可以看出StateSpace 一定是其他派生的状态空间的基类。
ompl::base::StateSpacePtr space(new T());
ompl::base::ScopedState<> state(space);
或者使用
ompl::base::SpaceInformationPtr si(space);
ompl::base::ScopedState<T> state(si);
上面状态的产生会根据状态空间自动的分配对应的状态,除了使用构函数外也可以使用=
和==
这样的赋值操作。如果模板T
被明确定义,那么会将实际状态空间表示的状态转换成模板指定的状态对象T::StateType
,这个过程中对于=
会使用StateSpace::copyState(),对于==
会使用StateSpace::equalStates()
这段话描述了状态生成的机制,状态的产生最好使用状态空间进行,并且两者并不是完全对应的,可以通过模板参数进行转换。(可是从一个状态空间拿的状态就应该是对应的状态类型啊,所以感觉没啥应用场景啊。这里暂且直到吧)
The ompl::base::ScopedState class will do the necessary memory operations to allocate a state from the correct state space. This is the recommended way of allocating states for code other than ompl internals. Convenience operators such as = and == are provided. If a type T is provided, where T is a state space type, the maintained state is cast as T::StateType. operator= will use ompl::base::StateSpace::copyState() and operator== will use ompl::base::StateSpace::equalStates().
1.2 The expert version
官方提供的代码,高级版的内存分配,从代码中可以看出:
- 状态的生成取决于一个定义好的状态空间。
- 状态的生成可以使用状态空间的allocState()方法来分配内存(很奇怪啊,状态与状态空间看起来明明是两个类对象,但是状态的生成却要由状态空间对象的方法提供)
- 生成的状态具体是什么属性(free还是怎么样)也是由状态空间的提供的方法完成
ompl::base::SpaceInformationPtr si(space);
ompl::base::State* state = si->allocState();
...
si->freeState(state);
下面解释了我上面的一个疑问(哎,自己在那瞎想,结果官方有解释):
- 状态是一个抽象基类,因此不能直接分配内存,而是要依据子类对象
- 状态空间的产生成功的提供了这个子类对象信息
- 因此使用状态空间对象创建状态对象
- 使用SpaceInformation::allocState() 比StateSpace::allocState() 更好,因为后面的规划器(planner)使用的正是SpaceInformation对象进行建立的。
The structure of a state depends on the state space specification. T