Geely-backed ECARX signs $750 million deal to build purpose-built robotaxis for May Mobility
Back to Tutorials
techTutorialintermediate

Geely-backed ECARX signs $750 million deal to build purpose-built robotaxis for May Mobility

May 19, 20269 views5 min read

Learn how to simulate autonomous vehicle fleets using CARLA and Python, replicating the technology used by companies like ECARX and May Mobility in their robotaxi development.

Introduction

In the rapidly evolving landscape of autonomous vehicle technology, companies like ECARX and May Mobility are leading the charge in developing purpose-built robotaxis. This tutorial will guide you through creating a simulation environment for autonomous vehicle fleets using Python and the CARLA simulator, a key technology in the development of autonomous driving systems. You'll learn how to set up a fleet of autonomous vehicles, configure their sensors, and simulate real-world driving scenarios.

Prerequisites

  • Python 3.7 or higher installed
  • Basic understanding of object-oriented programming
  • Experience with Python libraries such as NumPy and Matplotlib
  • Access to a machine with at least 8GB RAM and a GPU (for optimal performance)
  • Installed CARLA simulator (version 0.9.13 or higher)

Step-by-Step Instructions

1. Setting Up the CARLA Environment

Before we can simulate autonomous vehicles, we need to ensure our CARLA environment is properly configured. This step is crucial as it sets up the foundation for all subsequent operations.

1.1 Install Required Python Packages

We'll start by installing the necessary Python packages for working with CARLA.

pip install carla numpy matplotlib

Why this step? The CARLA Python API requires specific packages to communicate with the simulator and handle data processing. Installing these ensures we have all the tools needed for vehicle control and simulation.

1.2 Verify CARLA Installation

Check that CARLA is properly installed by running a simple Python script to connect to the simulator.

import carla

# Connect to CARLA server
client = carla.Client('localhost', 2000)
world = client.get_world()
print(f"Connected to CARLA world: {world.get_map().getName()}")

Why this step? This verification ensures that our Python environment can communicate with the CARLA simulator, which is essential for all subsequent vehicle simulation tasks.

2. Creating Autonomous Vehicle Blueprints

Autonomous vehicles in CARLA need to be properly configured with sensors and vehicle properties to simulate real-world scenarios.

2.1 Define Vehicle Properties

We'll create a class to represent our autonomous vehicle with configurable properties.

class AutonomousVehicle:
    def __init__(self, vehicle_id, blueprint, transform):
        self.vehicle_id = vehicle_id
        self.blueprint = blueprint
        self.transform = transform
        self.vehicle = None
        self.sensors = []
        
    def spawn_vehicle(self, world):
        # Spawn the vehicle in the world
        self.vehicle = world.spawn_actor(self.blueprint, self.transform)
        print(f"Spawned vehicle {self.vehicle_id}")

Why this step? Creating a class structure for vehicles allows us to easily manage multiple vehicles in a fleet, each with their own properties and configurations.

2.2 Configure Vehicle Sensors

Autonomous vehicles require various sensors to perceive their environment. We'll add sensors to our vehicle blueprint.

def add_sensors(self, world):
    # Add a camera sensor
    camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')
    camera_bp.set_attribute('image_size_x', '800')
    camera_bp.set_attribute('image_size_y', '600')
    camera_bp.set_attribute('fov', '90')
    
    camera_transform = carla.Transform(carla.Location(x=1.5, z=2.4))
    camera = world.spawn_actor(camera_bp, camera_transform, attach_to=self.vehicle)
    self.sensors.append(camera)
    
    # Add a LIDAR sensor
    lidar_bp = world.get_blueprint_library().find('sensor.lidar.ray_cast')
    lidar_bp.set_attribute('range', '100')
    lidar_bp.set_attribute('rotation_frequency', '10')
    lidar_bp.set_attribute('channels', '32')
    
    lidar_transform = carla.Transform(carla.Location(x=0.0, z=2.0))
    lidar = world.spawn_actor(lidar_bp, lidar_transform, attach_to=self.vehicle)
    self.sensors.append(lidar)
    
    print(f"Added sensors to vehicle {self.vehicle_id}")

Why this step? Sensors like cameras and LIDAR are fundamental to autonomous vehicle perception systems. Adding these to our vehicle blueprint mimics real-world vehicle configurations.

3. Simulating a Robotaxi Fleet

Now that we have our vehicle structure, we'll create a fleet of autonomous vehicles to simulate a real robotaxi operation.

3.1 Create Vehicle Fleet Manager

We'll implement a manager class to handle multiple vehicles in our fleet.

class FleetManager:
    def __init__(self, world):
        self.world = world
        self.vehicles = []
        
    def add_vehicle(self, vehicle_id, blueprint, transform):
        vehicle = AutonomousVehicle(vehicle_id, blueprint, transform)
        vehicle.spawn_vehicle(self.world)
        vehicle.add_sensors(self.world)
        self.vehicles.append(vehicle)
        
    def get_fleet_info(self):
        return [f"Vehicle {v.vehicle_id}: {v.vehicle.type_id}" for v in self.vehicles]

Why this step? A fleet manager allows us to efficiently control and monitor multiple autonomous vehicles simultaneously, similar to how ECARX might manage a large robotaxi fleet.

3.2 Initialize and Run Fleet Simulation

We'll now create a complete simulation with multiple vehicles.

# Initialize the fleet manager
fleet_manager = FleetManager(world)

# Get vehicle blueprints
vehicle_bp = world.get_blueprint_library().filter('vehicle.*')

# Define spawn points for vehicles
spawn_points = world.get_map().get_spawn_points()

# Create a fleet of 5 vehicles
for i in range(5):
    if i < len(spawn_points):
        fleet_manager.add_vehicle(i, vehicle_bp[0], spawn_points[i])
    else:
        # If we don't have enough spawn points, use the first one
        fleet_manager.add_vehicle(i, vehicle_bp[0], spawn_points[0])

# Print fleet information
print("Fleet Information:")
for info in fleet_manager.get_fleet_info():
    print(info)

Why this step? This simulation demonstrates how multiple autonomous vehicles can be managed in a coordinated fleet, similar to what May Mobility might implement in their commercial robotaxi operations.

4. Implementing Autonomous Driving Logic

To make our vehicles truly autonomous, we need to implement basic driving logic.

4.1 Add Basic Navigation

We'll implement simple navigation logic to move vehicles along predefined paths.

def navigate_vehicle(vehicle, target_location):
    # Get vehicle control
    control = carla.VehicleControl()
    
    # Simple navigation logic
    vehicle_location = vehicle.vehicle.get_location()
    direction = target_location - vehicle_location
    
    # Calculate distance to target
    distance = direction.length()
    
    # Set vehicle control based on distance
    if distance > 2.0:
        control.throttle = 0.5
        control.steer = direction.x / distance
    else:
        control.throttle = 0.0
        control.brake = 1.0
        
    vehicle.vehicle.apply_control(control)
    
    return distance

Why this step? Implementing navigation logic is essential for autonomous vehicles to move safely and efficiently in a simulated environment, mimicking the autonomous driving capabilities of companies like ECARX.

4.2 Run Autonomous Navigation

Finally, we'll run our autonomous navigation simulation.

# Define target locations for vehicles
locations = [
    carla.Location(x=100, y=100, z=0),
    carla.Location(x=200, y=200, z=0),
    carla.Location(x=300, y=300, z=0),
    carla.Location(x=400, y=400, z=0),
    carla.Location(x=500, y=500, z=0)
]

# Run autonomous navigation for each vehicle
for i, vehicle in enumerate(fleet_manager.vehicles):
    if i < len(locations):
        navigate_vehicle(vehicle, locations[i])
        print(f"Vehicle {i} moving towards {locations[i]}")

Why this step? This demonstrates how autonomous vehicles can navigate complex environments using sensor data and control logic, representing a core component of robotaxi technology.

Summary

This tutorial has walked you through creating a simulation environment for autonomous vehicle fleets using the CARLA simulator. You've learned how to set up the environment, create vehicle blueprints with sensors, manage a fleet of vehicles, and implement basic autonomous driving logic. These concepts are fundamental to the technology that companies like ECARX and May Mobility use to develop their robotaxi fleets. While this simulation is simplified compared to real-world systems, it provides a practical foundation for understanding autonomous vehicle development.

Source: TNW Neural

Related Articles