File size: 1,381 Bytes
a9587f9
c4b3cc5
21154f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404aa40
 
21154f7
404aa40
21154f7
404aa40
 
 
21154f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

import gradio as gr

# AI decision function
def ai_robot_simulator(distance):
    # AI decision logic
    if distance > 25:
        action = "Moving Forward πŸš—"
        robot_movement = "πŸ€– ➑️ ➑️ ➑️ Moving Forward..."
    elif 10 < distance <= 25:
        action = "Slowing Down ⚠️"
        robot_movement = "πŸ€– ➑️ ⚠️ Slowing Down..."
    else:
        action = "STOP + Turning Right πŸ”„"
        robot_movement = "πŸ€– β›” πŸ”„ Turning Right to Avoid Obstacle..."
    
    # Arduino logic code to show
    arduino_code = """
if (distance > 25) {
    moveForward();
} else if (distance > 10) {
    slowDown();
} else {
    stopRobot();
    turnRight();
}
"""
    # Return all outputs
    return f"Distance: {distance} cm", action, robot_movement, arduino_code

# Gradio interface
iface = gr.Interface(
    fn=ai_robot_simulator,
    inputs=gr.Slider(minimum=0, maximum=100, step=1, label="Set Distance from Obstacle (cm)"),
    outputs=[
        gr.Textbox(label="Sensor Reading"),
        gr.Textbox(label="AI Decision"),
        gr.Textbox(label="Robot Movement Simulation"),
        gr.Code(label="Arduino Logic")
    ],
    title="πŸ€– AI Obstacle Avoiding Robot Simulator",
    description="Interactive simulation of an Arduino AI robot with ultrasonic sensor. Move the slider to simulate obstacle distance."
)

# Launch the app
iface.launch()