Xiaomi built a robotic arm that plugs in your EV at home, delivering on a promise Tesla made in 2014 and never kept
Back to Tutorials
techTutorialintermediate

Xiaomi built a robotic arm that plugs in your EV at home, delivering on a promise Tesla made in 2014 and never kept

June 15, 202618 views5 min read

Learn to simulate Xiaomi's robotic EV charging arm by building a Python-based system that detects vehicles, moves robotic arms, and manages charging processes.

Introduction

Xiaomi's robotic charging arm represents a fascinating intersection of robotics, IoT, and electric vehicle infrastructure. While this specific implementation is a commercial product, we can build a simplified simulation of its core functionality using Python and basic robotics concepts. This tutorial will guide you through creating a simulation of an automated EV charging system that detects vehicle position, extends a charging arm, and manages the charging process.

Prerequisites

  • Python 3.7 or higher installed on your system
  • Familiarity with basic Python programming concepts
  • Understanding of object-oriented programming
  • Basic knowledge of robotics concepts (position detection, actuation)
  • Optional: Raspberry Pi or similar microcontroller for physical implementation

Step-by-Step Instructions

Step 1: Set Up Your Development Environment

Install Required Libraries

First, we'll create a virtual environment and install necessary packages for our simulation. This ensures we don't interfere with system-wide packages.

python -m venv ev_charging_env
source ev_charging_env/bin/activate  # On Windows: ev_charging_env\Scripts\activate
pip install numpy matplotlib

Why This Step?

Creating a virtual environment isolates our project dependencies, making it easier to manage and reproduce the environment on different systems. The libraries we'll use are essential for mathematical operations and visualization.

Step 2: Create the Base Classes

Define Vehicle and ChargingSystem Classes

We'll start by creating the fundamental classes that represent our EV and the charging system.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import time

class EV:
    def __init__(self, x, y, charging_port_offset=0.5):
        self.x = x
        self.y = y
        self.charging_port_offset = charging_port_offset
        self.battery_level = 100
        self.is_charging = False
        
    def get_charging_port_position(self):
        # Return the position of the charging port
        return (self.x + self.charging_port_offset, self.y)
        
    def charge(self, amount):
        self.battery_level = min(100, self.battery_level + amount)
        
    def discharge(self, amount):
        self.battery_level = max(0, self.battery_level - amount)


class ChargingSystem:
    def __init__(self, garage_width=10, garage_length=15):
        self.garage_width = garage_width
        self.garage_length = garage_length
        self.arm_length = 3
        self.arm_position = (0, 0)
        self.arm_angle = 0
        self.is_extended = False
        self.target_vehicle = None
        
    def detect_vehicle(self, vehicles):
        # Simple detection based on proximity
        if not vehicles:
            return None
        
        vehicle = vehicles[0]  # Simplified: take first vehicle
        distance = np.sqrt((vehicle.x - self.arm_position[0])**2 + 
                          (vehicle.y - self.arm_position[1])**2)
        
        if distance < 2:
            return vehicle
        return None
        
    def extend_arm(self, target):
        self.is_extended = True
        self.target_vehicle = target
        print("Charging arm extended towards vehicle")
        
    def retract_arm(self):
        self.is_extended = False
        self.target_vehicle = None
        print("Charging arm retracted")
        
    def connect_charger(self, vehicle):
        if self.is_extended and vehicle == self.target_vehicle:
            vehicle.is_charging = True
            print("Charger connected to vehicle")
            return True
        return False
        
    def disconnect_charger(self, vehicle):
        if vehicle.is_charging:
            vehicle.is_charging = False
            print("Charger disconnected from vehicle")
            return True
        return False

Why This Step?

We're creating the foundational structure for our simulation. The EV class represents the vehicle with its position and battery state, while the ChargingSystem class handles the robotic arm's behavior and interactions.

Step 3: Implement Position Detection and Movement

Add Movement and Detection Logic

Now we'll enhance our system with more realistic movement and detection capabilities.

class ChargingSystem:
    # ... previous code ...
    
    def move_to_position(self, target_x, target_y):
        # Simple linear movement simulation
        current_x, current_y = self.arm_position
        dx = target_x - current_x
        dy = target_y - current_y
        distance = np.sqrt(dx**2 + dy**2)
        
        if distance > 0.1:  # If not close enough
            step_size = 0.1
            move_x = dx * step_size / distance
            move_y = dy * step_size / distance
            
            self.arm_position = (current_x + move_x, current_y + move_y)
            return False  # Not reached yet
        else:
            self.arm_position = (target_x, target_y)
            return True  # Reached target
    
    def get_arm_position(self):
        return self.arm_position
    
    def calculate_reach(self):
        # Calculate the maximum reach of the arm
        return self.arm_length
    
    def is_within_reach(self, target_x, target_y):
        arm_x, arm_y = self.arm_position
        distance = np.sqrt((target_x - arm_x)**2 + (target_y - arm_y)**2)
        return distance <= self.arm_length

Why This Step?

This step adds realistic movement simulation to our charging arm. We're implementing a basic path-finding algorithm that moves the arm towards a target position, which is crucial for a real-world robotic system.

Step 4: Create the Charging Simulation

Build the Main Simulation Loop

Now we'll create the complete simulation that demonstrates the charging process.

def simulate_charging_process():
    # Create garage and vehicles
    garage = ChargingSystem()
    vehicle = EV(5, 5)  # Place vehicle in garage
    
    print("Starting EV Charging Simulation")
    print(f"Vehicle at position: ({vehicle.x}, {vehicle.y})")
    
    # Main simulation loop
    for i in range(100):
        # Detect vehicle
        detected_vehicle = garage.detect_vehicle([vehicle])
        
        if detected_vehicle and not garage.is_extended:
            # Move to vehicle position
            target_x, target_y = detected_vehicle.get_charging_port_position()
            
            if garage.is_within_reach(target_x, target_y):
                reached = garage.move_to_position(target_x, target_y)
                if reached:
                    garage.extend_arm(detected_vehicle)
                    garage.connect_charger(detected_vehicle)
            else:
                print("Vehicle out of arm reach")
                break
        
        # Simulate charging
        if vehicle.is_charging:
            vehicle.discharge(0.5)  # Discharge while charging
            if vehicle.battery_level <= 80:  # Stop at 80% for demo
                garage.disconnect_charger(vehicle)
                garage.retract_arm()
                print(f"Charging complete. Battery level: {vehicle.battery_level}%")
                break
        
        time.sleep(0.1)  # Simulate time passing
        
        # Update display
        if i % 10 == 0:
            print(f"Battery level: {vehicle.battery_level}%")
            
    print("Simulation completed")

# Run the simulation
simulate_charging_process()

Why This Step?

This creates a complete simulation that demonstrates the core functionality described in the news article. It shows how the system would detect a vehicle, move the arm, connect the charger, and manage the charging process.

Step 5: Add Visualization (Optional)

Create a Visual Representation

To better understand the system's behavior, we'll add a visualization component.

def visualize_simulation():
    fig, ax = plt.subplots(1, 1, figsize=(10, 8))
    
    # Draw garage
    garage = Rectangle((0, 0), 10, 15, linewidth=2, edgecolor='black', facecolor='lightgray')
    ax.add_patch(garage)
    
    # Draw vehicle
    vehicle = EV(5, 5)
    vehicle_rect = Rectangle((vehicle.x - 0.5, vehicle.y - 0.5), 1, 1, 
                           linewidth=2, edgecolor='blue', facecolor='lightblue')
    ax.add_patch(vehicle_rect)
    
    # Draw charging port
    port_x, port_y = vehicle.get_charging_port_position()
    port = Rectangle((port_x - 0.1, port_y - 0.1), 0.2, 0.2, 
                    linewidth=2, edgecolor='red', facecolor='red')
    ax.add_patch(port)
    
    # Draw charging arm
    arm_x, arm_y = (0, 0)
    arm_end_x = arm_x + 3
    arm_end_y = arm_y
    ax.plot([arm_x, arm_end_x], [arm_y, arm_end_y], 'g-', linewidth=3)
    
    ax.set_xlim(-1, 11)
    ax.set_ylim(-1, 16)
    ax.set_aspect('equal')
    ax.grid(True)
    ax.set_title('EV Charging Simulation')
    
    plt.show()

Why This Step?

Visualization helps us understand the spatial relationships and movement patterns in our system. While not essential for the core functionality, it provides valuable insights into how the robotic arm would operate in a real environment.

Summary

This tutorial demonstrated how to build a simulation of an automated EV charging system similar to Xiaomi's robotic arm. We created classes for vehicles and charging systems, implemented position detection and movement logic, and built a complete simulation that shows the charging process from detection to completion. The simulation showcases key concepts like vehicle detection, robotic arm movement, and charging management that are central to the technology described in the news article.

While this is a simplified simulation, it provides a foundation that could be extended with real sensors, more sophisticated path planning algorithms, and integration with actual EV charging hardware for practical implementation.

Source: TNW Neural

Related Articles