Example 1: Hello World

Example of a two-corridor setup

This example demonstrates how to use Arena with a simple scenario.

hello_world.py
 1import arena
 2""" Hello World Example for Arena Framework: Motion Planning for a Unicycle Robot Within 2 Corridors"""
 3
 4### Define corridors ###
 5width1 = 3
 6height1 = 7.2
 7center1 = [0, 3]
 8phi1 = 1.570796  # 90 degrees 
 9width2 = 3
10height2 = 4.8
11center2 = [1.73, 7]
12phi2 = 0.523598  # 30 degrees 
13
14corridor1 = arena.CorridorWorld(
15    width = width1,
16    height = height1,
17    center = center1,
18    tilt = phi1)
19
20corridor2 = arena.CorridorWorld(
21    width = width2,
22    height = height2,
23    center = center2,
24    tilt = phi2)
25
26corridor_list = [corridor1, corridor2]
27
28### Define Unicycle vehicle ###
29vehicle_width = 0.430
30vehicle_length = 0.430
31vehicle_vmax = 0.5
32vehicle_omegamax = 0.5
33
34unicycle = arena.Unicycle(
35    state = [0,0,0],
36    width = vehicle_width,
37    length = vehicle_length,
38    v_max = vehicle_vmax,
39    v_min = -vehicle_vmax,
40    omega_max = vehicle_omegamax,
41    omega_min = -vehicle_omegamax)
42
43### Define initial pose and final pose ###
44initial_pose = [0.6425, 0.6305, 0.0]
45final_pose = [3, 8.3, 2.88]
46
47### Define Motion Planner ###
48mp = arena.MotionPlanner(unicycle, corridor_list, initial_pose, final_pose)
49
50### Compute analytical trajectory ###
51analytical_trajectory = mp.compute_trajectory_analytical()
52
53### Plot results ###
54import matplotlib.pyplot as plt
55
56figure = mp.plot_planner_inputs()
57plt.title('Analytical Motion Planner - Unicycle in Two Corridors')
58arena.plot_analytical_trajectory(analytical_trajectory, figure)
59arena.plot_velocity_profiles(analytical_trajectory, unicycle)
60plt.show(block = True)

Step 1 — Corridors definition

To begin, we define the geometric properties for two corridors. Each corridor is represented as a rectangle, and is defined by its width, length, center point and orientation. Then, we instantiate two CorridorWorld objects with the defined parameters and place them in a list that defines the order in which the vehicle will navigate them.

### Define corridors ###
width1 = 3
height1 = 7.2
center1 = [0, 3]
phi1 = 1.570796  # 90 degrees 
width2 = 3
height2 = 4.8
center2 = [1.73, 7]
phi2 = 0.523598  # 30 degrees 

corridor1 = arena.CorridorWorld(
    width = width1,
    height = height1,
    center = center1,
    tilt = phi1)

corridor2 = arena.CorridorWorld(
    width = width2,
    height = height2,
    center = center2,
    tilt = phi2)

corridor_list = [corridor1, corridor2]

Step 2 — Vehicle definition

Next, we define the characteristics of a unicycle vehicle, and instatiate the Unicycle object.

### Define Unicycle vehicle ###
vehicle_width = 0.430
vehicle_length = 0.430
vehicle_vmax = 0.5
vehicle_omegamax = 0.5

unicycle = arena.Unicycle(
    state = [0,0,0],
    width = vehicle_width,
    length = vehicle_length,
    v_max = vehicle_vmax,
    v_min = -vehicle_vmax,
    omega_max = vehicle_omegamax,
    omega_min = -vehicle_omegamax)

Step 3 — Initial and Final Pose definition

The start and end poses of the vehicle are represented as lists with three elements: x, y, θ. These correspond to the position in the plane (x and y) and the vehicle’s orientation θ (in radians). It is important to provide consistent values, as the planner will deliver trajectories only if the initial position lies within the first corridor and the final position lies within the last corridor in corridor_list.

### Define initial pose and final pose ###
initial_pose = [0.6425, 0.6305, 0.0]
final_pose = [3, 8.3, 2.88]

Step 4 — Create the Motion Planner and compute the trajectory

With all the elements for the motion planning problem ready, we can instantiate the MotionPlananer object, and compute the trajectory by using its method compute_trajectory_analytical().

### Define Motion Planner ###
mp = arena.MotionPlanner(unicycle, corridor_list, initial_pose, final_pose)

### Compute analytical trajectory ###
analytical_trajectory = mp.compute_trajectory_analytical()

Step 5 — Plot the results

Finally, we can easily plot the results by creating a figure with the method plot_planner_inputs(). Then the function plot_analytical_trajectory() plots the solution path in the figure. The function plot_velocity_profiles() instead creates a new figure showing the control profiles.

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

figure = mp.plot_planner_inputs()
plt.title('Analytical Motion Planner - Unicycle in Two Corridors')
arena.plot_analytical_trajectory(analytical_trajectory, figure)
arena.plot_velocity_profiles(analytical_trajectory, unicycle)
plt.show(block = True)