Rover Trajectory Problem

class blackbox.rover_trajectory_problem.AABoxes(low, high)[source]

Bases: object

__init__(low, high)[source]

Class to create axis aligned bounding boxes for the obstacles, typically used to model rectangular obstacles in 2D or 3D spaces

Parameters:
  • low (np.ndarray) – lower bound of the bounding box, should be a 2D array of shape (n, dim) where n is the number of boxes and dim is the dimension of the space

  • high (np.ndarray) – upper bound of the bounding box, should be a 2D array of shape (n, dim) where n is the number of boxes and dim is the dimension of the space

contains(X)[source]

Check if a set of points X is inside the bounding box

Parameters:

X (np.ndarray) – 2D numpy array containing (x,y) coordinates

Returns:

bool – 2D boolean numpy array indicating if the point is inside the bounding box

Return type:

np.ndarray

class blackbox.rover_trajectory_problem.AdditiveCosts(fns)[source]

Bases: object

__call__(x)[source]

Method to compute additive cost for given x

Parameters:

x (np.ndarray) – numpy array containing (x,y) point(s)

Return type:

2D numpy array containing constant cost for each point

__init__(fns)[source]

Class to create a cost function that is the sum of the given cost functions.

Parameters:

fns (list) – list of cost function handles to be added

class blackbox.rover_trajectory_problem.ConstCost(constant_cost)[source]

Bases: object

__call__(x)[source]

Method to assign a constant cost for each point

Parameters:

x (np.ndarray) – numpy array containing (x,y) point(s)

Return type:

2D numpy array containing constant cost for each point

__init__(constant_cost)[source]

class to create a constant cost function

Parameters:

cost (float) – constant cost for each point in the trajectory

class blackbox.rover_trajectory_problem.ConstObstacleCost(geometry, obstacle_cost)[source]

Bases: object

__call__(x)[source]

method to compute obstacle for each point

Parameters:

x (np.ndarray) – numpy array containing (x,y) point(s)

Return type:

2D numpy array containing constant obstacle cost for each point

__init__(geometry, obstacle_cost)[source]

class to create a cost function for the obstacles

Parameters:
  • geometry (object) – geometry of the obstacles, should be a class that implements the __call__ method to calculate the cost of the trajectory

  • obstacle_cost (float) – constant obstacle cost if a given point is inside the obstacles

class blackbox.rover_trajectory_problem.ConstantOffsetFn(fn_instance, offset)[source]

Bases: object

__call__(x)[source]

Method to return the function output with an offset

__init__(fn_instance, offset)[source]

Class to add a constant offset to a given function’s output

Parameters:
  • fn_instance (function handle)

  • offset (float) – offset to be added

class blackbox.rover_trajectory_problem.NegGeom(geom)[source]

Bases: object

__init__(geom)[source]

Class to create a negation of the given geometry. The negation is used to transform the occupied regions into free space and vice versa, which is particularly useful in scenarios where defining the complement of a geometric region is more straightforward or efficient.

Parameters:

geom (object) – geometry to be negated, should be a class that implements the contains method to check if a point is inside the geometry

contains(X)[source]

Check if a set of points X is inside the negated geometry.

Parameters:

x (np.ndarray) – 2D numpy array containing (x,y) coordinates

Returns:

bool – 2D boolean numpy array indicating if the point is inside the bounding box

Return type:

np.ndarray

class blackbox.rover_trajectory_problem.NormalizedInputFn(fn_instance, x_range)[source]

Bases: object

__call__(x)[source]

Call self as a function.

__init__(fn_instance, x_range)[source]
get_range()[source]
inv_project_input(x)[source]
project_input(x)[source]
class blackbox.rover_trajectory_problem.PointBSpline(dim, num_control_points)[source]

Bases: object

__init__(dim, num_control_points)[source]

Class to create a smooth B-spline trajectory based on the given points

Parameters:
  • dim (int) – number of dimensions of the domain (env), mostly 2D

  • num_control_points (int) – number of control points used for fitting B-spline trajectory

fit_bspline(control_points, start=None, goal=None)[source]

Method to fit a parameterized b-spline curve

Parameters:
  • control_points (np.ndarray) – 1D numpy array containing (x,y) coordinates of the control points

  • start (np.ndarray) – 1D numpy array containing (x,y) for the starting position, default=None

  • goal (np.ndarray) – 1D numpy array containing (x,y) for the goal position, default=None

get_traj_points(u)[source]

Method to evaluate the parameterized b-spline curve at given parameter values

Parameters:

u (np.ndarray) – 1D numpy array consisting of parameter values for the b-spline curve, shape (n,) where n is the number of parameter values

Returns:

traj_points – a numpy array representing points along the b-spline curve, shape (n,d)

Return type:

np.ndarray

class blackbox.rover_trajectory_problem.Rover(dim=60, start=array([0.05, 0.05]), goal=array([0.95, 0.95]), force_start=False, force_goal=False)[source]

Bases: BaseProblem

__call__(x)[source]

Evaluate the cost of the trajectory for a given x

Parameters:

x (np.ndarray) – input to be evaluated, can be a single sample or multiple samples, (dim,) or (n_samples,dim)

Returns:

cost – cost of the trajectory for the given input, (1,) or (n_samples,1)

Return type:

np.ndarray

__init__(dim=60, start=array([0.05, 0.05]), goal=array([0.95, 0.95]), force_start=False, force_goal=False)[source]

Main class for the user to create a domain with obstacles and evaluate the cost of a trajectory for a given input

Parameters:
  • dim (int) – dimension of the problem, determines the number of control points for the B-spline trajectory

  • start (np.ndarray) – 1D numpy array representing (x,y) coordinates of the starting point, default=(0.05,0.05)

  • goal (np.ndarray) – 1D numpy array representing (x,y) coordinates of the goal point, default=(0.95,0.95)

  • force_start (bool) – flag to fix the starting point, default=False

  • force_goal (bool) – flag to fix the goal point, default=False

class blackbox.rover_trajectory_problem.RoverDomain(cost_fn, start, goal, traj, start_miss_cost=None, goal_miss_cost=None, force_start=True, force_goal=True)[source]

Bases: object

__call__(control_points, n_samples=1000)[source]

Method to estimate the cost for a given control points i.e. design variable vector x

Parameters:
  • control_points (np.ndarray) – 1D numpy array representing coordinates of the control points for fitting b-spline, shape (n,) where n = number of control points X 2. This is essential the design variable vector for which cost needs to be computed

  • n_samples (int) – number of points which will be used to query the b-spline after fitting, default = 1000

Returns:

total_cost – total cost of the trajectory

Return type:

float

__init__(cost_fn, start, goal, traj, start_miss_cost=None, goal_miss_cost=None, force_start=True, force_goal=True)[source]

Class for creating rover domain

Parameters:
  • cost_fn – function handle to compute cost for a given set of points that define a trajectory

  • start (np.ndarray) – starting position (x,y) of the rover, shape (2,)

  • end (np.ndarray) – final (end) position (x,y) of the rover, shape (2,)

  • traj – a parameterized trajectory object that can create a smooth b-spline trajectory from the given control points

  • start_miss_cost – function handle to compute cost for missing starting position, default=None

  • goal_miss_cost – function handle to compute cost for missing final position, default=None

  • force_start (bool) – flag to compute cost for missing the start position, default=True

  • force_goal (bool) – flag to compute cost for missing the goal position, default=True

class blackbox.rover_trajectory_problem.UnionGeom(geoms)[source]

Bases: object

__init__(geoms)[source]

Class to create a union of the given geometries. The union is used to combine multiple geometric regions into a single region, which is useful for defining complex obstacles or free space.

Parameters:

geoms (list) – list of geometries to be combined, should be a list of classes that implements the contains method to calculate the cost of the trajectory

contains(X)[source]

Check if the point X is inside the union of the geometries.

Parameters:

X (np.ndarray) – 2D numpy array containing (x,y) coordinates

Returns:

bool – 2D boolean array indicating if the point is inside the union of the geometries

Return type:

np.ndarray

blackbox.rover_trajectory_problem.create_cost()[source]

function to create a cost function, the location of the obstacles is fixed to ensure consistency

Returns:

cost_fn – function handle for calculating the cost of the trajectory

Return type:

function

blackbox.rover_trajectory_problem.l1cost(x, point)[source]

function to calculate the l1 cost if the x deviates from point

Parameters:
  • x (np.ndarray) – point to be evaluated

  • point (np.ndarray) – point to be matched

Return type:

a float representing L1 cost

blackbox.rover_trajectory_problem.plot_traj(control_points, rover, ngrid_points=100, ntraj_points=1000, colormap='GnBu', draw_colorbar=True, show_figure=True)[source]

function to plot the trajectory for given control points

Parameters:
  • control_points (np.ndarray) – a 1D numpy array representing the coordinates of the control points

  • rover (Rover) – a Rover object

  • ngrid_points (int) – number of grid points along one axis, default=100

  • ntraj_points (int) – number of points along the trajectory, default=1000

  • colormap (str) – a valid matplotlib colormap, default=”GnBu”

  • draw_colorbar (bool) – flag to have colorbar or not, default=True

  • show_figure (bool) – flag to determine whether to show the plot or not, default=True

blackbox.rover_trajectory_problem.simple_rbf(x, point)[source]

function to calculate the RBF-based cost if the x deviates from point

Parameters:
  • x (np.ndarray) – point to be evaluated

  • point (np.ndarray) – point to be matched

Return type:

a float representing L1 cost