Tutorial

After following the installation procedure presented in the installation guide, you should be able to run our hello world example.

Let’s first have a look at the code of the example. You can find below the explanation of each piece of code.

import arena

############################
# Instantiate corridors
############################
corridor1 = arena.CorridorWorld(width = 3, height = 7.2, center = [0, 3], tilt = 1.570796)
corridor2 = arena.CorridorWorld(width = 3, height = 4.8, center = [1.73, 7], tilt = 0.523598)

corridor_list = [corridor1, corridor2]

##########################
# Instantiate unicycle
##########################

# Unicycle parameters
vehicle_width = 0.430
vehicle_length = 0.430
vehicle_vmax = 0.5
vehicle_omegamax = 0.5
initial_pose = [0.6425, 0.6305, 0.0]

vehicle = arena.Unicycle(state = initial_pose, width = vehicle_width, length = vehicle_length, v_max = vehicle_vmax, v_min = -vehicle_vmax, omega_max = vehicle_omegamax, omega_min = -vehicle_omegamax)

############################
# Instantiate Motion Planner
############################
final_pose = [3, 8.3, 2.88]
mp = arena.MotionPlanner(vehicle, corridor_list, initial_pose, final_pose)

###################################
# Compute the analytical trajectory
###################################
optimal_trajectory, _ = mp.compute_trajectory_analytical()

############################
# Plot results
############################
import matplotlib.pyplot as plt

# Plot corridors
figure = arena.plot_corridors(corridor_list = corridor_list)

plt.xlabel('x [m]')
plt.ylabel('y [m]')

# Plot trajectory
colors = ['b', 'm', 'r', 'g', 'y', 'b', 'm']

for ind, trajectory_piece in enumerate(optimal_trajectory):
    trajectory_piece.plot_path(figure, color = colors[ind])

    # Plot circumference
    if isinstance(trajectory_piece, arena.CurvilinearArcUnicycle):
        trajectory_piece.plot_circle(figure)

plt.show(block = True)

First of all, you need to import Arena

from arena import *

The free space is defined by means of a list of available concatenated corridors. Every corridor is an instance of the class CorridorWorld

corridor1 = arena.CorridorWorld(width = 3, height = 7.2, center = [0, 3], tilt = 1.570796)
corridor2 = arena.CorridorWorld(width = 3, height = 4.8, center = [1.73, 7], tilt = 0.523598)

corridor_list = [corridor1, corridor2]

We also need to instantiate the vehicle we are using. For this we use the class Unicycle, which requires a state (initial pose), width, length, and lower and upper bounds for its control inputs.

vehicle_width = 0.430
vehicle_length = 0.430
vehicle_vmax = 0.5
vehicle_omegamax = 0.5
initial_pose = [0.6425, 0.6305, 0.0]

vehicle = arena.Unicycle(state = initial_pose, width = vehicle_width, length = vehicle_length, v_max = vehicle_vmax, v_min = -vehicle_vmax, omega_max = vehicle_omegamax, omega_min = -vehicle_omegamax)

Now we define a desired final pose (which belongs to the second corridor) and instatiate our analytical planner based on the variables we instantiated before.

final_pose = [3, 8.3, 2.88]

mp = arena.MotionPlanner(vehicle, corridor_list, initial_pose, final_pose)

Finally, we execute the analytical motion planner by calling the compute_trajectory_analytical method. This method returns the solution optimal_trajectory as a list of trajectory pieces which belong to one of this classes: CurvilinearArcUnicycle, LinearSegmentUnicycle and TurnOnTheSpot. The second returned value is a boolean that indicates whether a specific case has been detected where the overall time-optimal trajectory does not involve an arc maneuver to move from one corridor to the other. This is not used in this example.

optimal_trajectory, _ = mp.compute_trajectory_analytical()

To visualize the results, we provide several useful methods. To plot the corridors, you can use the method plot_corridors, which requires the corridor list. In addition, every element in the list of trajectories optimal_trajectory can be plotted by using the plot_path method. For arc trajectories, you can also plot the circumference to which the arc belongs by using theplot_circle plot_circle method.

import matplotlib.pyplot as plt

# Plot corridors
figure = arena.plot_corridors(corridor_list = corridor_list)

plt.xlabel('x [m]')
plt.ylabel('y [m]')

# Plot trajectory
colors = ['b', 'm', 'r', 'g', 'y', 'b', 'm']

for ind, trajectory_piece in enumerate(optimal_trajectory):
    trajectory_piece.plot_path(figure, color = colors[ind])

    # Plot circumference
    if isinstance(trajectory_piece, arena.CurvilinearArcUnicycle):
        trajectory_piece.plot_circle(figure)

plt.show(block = True)