Terrain

Terrain objects are used to describe the terrain over to optimize a gait.

HeightMap

namespace gambol

Variables

static const std::map<HeightMap::TerrainID, std::string> terrain_names = {{HeightMap::FlatID, "Flat"}, {HeightMap::BlockID, "Block"}, {HeightMap::StairsID, "Stairs"}, {HeightMap::GapID, "Gap"}, {HeightMap::SlopeID, "Slope"}, {HeightMap::ChimneyID, "Chimney"}, {HeightMap::ChimneyLRID, "ChimenyLR"},}
class HeightMap
#include <HeightMap.h>

Holds the height and slope information of the terrain.

This class and the examples were taken from TOWR!

This class is responsible for providing the height values and slope at each position (x,y). Examples of various height map examples can be found in height_map_examples.h.

If a height map of the terrain already exists, e.g. Octomap/Gridmap, then a simple adapter for these can be written to comply to this minimal interface and to be used with towr.

The height map is used to formulate constraints such as “foot must be touching terrain during stance phase”.

See

TerrainConstraint

Subclassed by gambol::Block, gambol::Chimney, gambol::ChimneyLR, gambol::FlatGround, gambol::Gap, gambol::Hill, gambol::Slope, gambol::SlopeConstant, gambol::Stairs

Public Types

enum TerrainID

Terrains IDs corresponding for factory method.

Values:

enumerator FlatID
enumerator BlockID
enumerator StairsID
enumerator GapID
enumerator SlopeID
enumerator ChimneyID
enumerator ChimneyLRID
enumerator HillID
enumerator SlopeConstantID
enumerator TERRAIN_COUNT
enum Direction

Values:

enumerator Normal
enumerator Tangent1
enumerator Tangent2
using Ptr = std::shared_ptr<HeightMap>
using Vector3d = Eigen::Vector3d
using MatrixXd = Eigen::MatrixXd
using Jacobian = Eigen::SparseMatrix<double, Eigen::RowMajor>

Public Functions

HeightMap() = default
virtual ~HeightMap() = default
virtual double GetHeight(double x, double y) const = 0
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

double GetHeight(const Vector3d &pos) const
double GetDerivativeOfHeightWrt(Dim2D dim, double x, double y) const

How the height value changes at a 2D position in direction dim.

Parameters
  • dim – The direction (x,y) w.r.t. which the height change is desired.

  • x – The x position on the terrain.

  • y – The y position on the terrain.

Returns

The derivative of the height with respect to the dimension.

double GetDerivativeOfHeightWrt(Dim2D dim, const Vector3d &pos) const
Vector3d GetNormalizedBasis(Direction direction, double x, double y) const

Returns either the vector normal or tangent to the terrain patch.

Parameters
  • direction – The terrain normal or tangent vectors.

  • x – The x position on the terrain.

  • y – The y position on the terrain.

Returns

The normalized 3D vector in the specified direction.

Vector3d GetNormalizedBasis(Direction direction, const Vector3d &pos) const
Vector3d GetDerivativeOfNormalizedBasisWrt(Direction direction, Dim2D dim, double x, double y) const

How the terrain normal/tangent vectors change when moving in x or y.

Parameters
  • direction – The terrain normal or tangent vectors.

  • dim – The dimension w.r.t which the change is searched for.

  • x – The x position on the terrain.

  • y – The y position on the terrain.

Returns

The normalized 3D derivative w.r.t dimension dim.

Vector3d GetDerivativeOfNormalizedBasisWrt(Direction direction, Dim2D dim, const Vector3d &pos) const
Jacobian GetDerivativeOfNormalizedBasis(Direction direction, const Vector3d &pos) const

How the terrain normal/tangent vectors change when moving.

This version returns an entire jacobian. The w.r.t.-z component is zero.

Parameters
  • direction – The terrain normal or tangent vectors.

  • pos – The x, y and z position on the terrain.

Returns

The normalized 3D derivative w.r.t dimension dim.

double GetFrictionCoeff() const
Returns

The constant friction coefficient over the whole terrain.

Public Static Functions

static HeightMap::Ptr MakeTerrain(TerrainID type)

Instantiate one of the sample terrains.

Protected Attributes

double friction_coeff_ = 0.5

Private Types

using DimDerivs = std::vector<Dim2D>

dimensional derivatives

Private Functions

Vector3d GetBasis(Direction direction, double x, double y, const DimDerivs &dim_deriv = {}) const

returns either the terrain normal/tangent or its derivative.

Parameters
  • direction – Terrain normal or tangent vector.

  • x – The x position on the terrain.

  • y – The y position on the terrain.

  • dim_deriv – If empty, the vector is returned, if e.g. X_ is set, the derivative of the vector w.r.t. x is returned.

Returns

the 3D not-normalized vector.

Vector3d GetNormal(double x, double y, const DimDerivs& = {}) const
Vector3d GetTangent1(double x, double y, const DimDerivs& = {}) const
Vector3d GetTangent2(double x, double y, const DimDerivs& = {}) const
double GetSecondDerivativeOfHeightWrt(Dim2D dim1, Dim2D dim2, double x, double y) const
Vector3d GetDerivativeOfNormalizedVectorWrtNonNormalizedIndex(const Vector3d &non_normalized, int index) const
Jacobian GetDerivativeOfBasis(Direction direction, const Vector3d &pos) const
Jacobian GetDerivativeOfNormalizedVectorWrtNonNormalized(const Vector3d &v) const
virtual double GetHeightDerivWrtX(double x, double y) const
virtual double GetHeightDerivWrtY(double x, double y) const
virtual double GetHeightDerivWrtXX(double x, double y) const
virtual double GetHeightDerivWrtXY(double x, double y) const
virtual double GetHeightDerivWrtYX(double x, double y) const
virtual double GetHeightDerivWrtYY(double x, double y) const

HeightMap Examples

namespace gambol
class Block : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain with a step in height in x-direction.

Public Functions

virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

virtual double GetHeightDerivWrtX(double x, double y) const override

Private Members

double block_start = 0.2
double length_ = 0.2
double height_ = 0.2
double eps_ = 0.0005
const double slope_ = height_ / eps_
class Chimney : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain with a tilted vertical wall to cross a gap.

Public Functions

virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

virtual double GetHeightDerivWrtY(double x, double y) const override

Private Members

const double x_start_ = 1.0
const double length_ = 1.5
const double y_start_ = 0.5
const double slope_ = 3.0
const double x_end_ = x_start_ + length_
class ChimneyLR : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain with two tilted vertical walls to cross a gap.

Public Functions

virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

virtual double GetHeightDerivWrtY(double x, double y) const override

Private Members

const double x_start_ = 0.5
const double length_ = 0.3
const double y_start_ = 0.5
const double slope_ = 1.0
const double x_end1_ = x_start_ + length_
const double x_end2_ = x_start_ + 2 * length_
class FlatGround : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain of even height.

Public Functions

FlatGround(double height = 0.0)
virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

Private Members

double height_
class Gap : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain with parabola-modeled gap in x-direction.

Public Functions

virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

virtual double GetHeightDerivWrtX(double x, double y) const override
virtual double GetHeightDerivWrtXX(double x, double y) const override

Private Members

const double gap_start_ = 0.6
const double w = 0.3
const double h = 1.5
const double slope_ = h / w
const double dx = w / 2.0
const double xc = gap_start_ + dx
const double gap_end_x = gap_start_ + w
const double a = (4 * h) / (w * w)
const double b = -(8 * h * xc) / (w * w)
const double c = -(h * (w - 2 * xc) * (w + 2 * xc)) / (w * w)
class Hill : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain which is a quadratic hill.

Public Functions

virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

virtual double GetHeightDerivWrtX(double x, double y) const override
virtual double GetHeightDerivWrtY(double x, double y) const override
virtual double GetHeightDerivWrtXX(double x, double y) const override
virtual double GetHeightDerivWrtYY(double x, double y) const override

Private Members

double center_x_ = -1.0
double center_y_ = -1.0
double factor_x_ = 0.1
double factor_y_ = 0.1
class Slope : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain with an increasing and then decreasing slope in x-direction.

Public Functions

virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

virtual double GetHeightDerivWrtX(double x, double y) const override

Private Members

const double slope_start_ = 0.1
const double up_length_ = 3.0
const double down_length_ = 3.0
const double height_center = 1.5
const double x_down_start_ = slope_start_ + up_length_
const double x_flat_start_ = x_down_start_ + down_length_
const double slope_ = height_center / up_length_
class SlopeConstant : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain which is a constant slope.

Public Functions

virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

virtual double GetHeightDerivWrtX(double x, double y) const override
virtual double GetHeightDerivWrtY(double x, double y) const override

Private Members

double center_x_ = 0.0
double center_y_ = 0.0
double slope_x_ = 0.2
double slope_y_ = 0.2
class Stairs : public gambol::HeightMap
#include <HeightMapExamples.h>

Sample terrain with a two-steps in height in x-direction.

Public Functions

virtual double GetHeight(double x, double y) const override
Parameters
  • x – The x position.

  • y – The y position.

Returns

The height of the terrain [m] at a specific 2D position.

Private Members

double first_step_start_ = 1.0
double first_step_width_ = 0.4
double height_first_step = 0.2
double height_second_step = 0.4
double width_top = 1.0