import time
import random
class RobotController:
def __init__(self, safe_distance=20.0):
self.safe_distance = safe_distance
self.is_running = True
print(“[INFO] Robot Controller Initialized. System Ready.”)
def read_ultrasonic_sensor(self):
# সেন্সর ডেটা সিমুলেশন (বাস্তবে এটি GPIO পিন থেকে ডেটা নিবে)
return round(random.uniform(5.0, 50.0), 2)
def move_forward(self):
print(“[ACTION] Moving Forward Straight… ⬆️”)
def change_direction(self):
print(“[WARNING] Obstacle Detected! Stopping…”)
print(“[ACTION] Turning Left 90 Degrees… ↩️”)
time.sleep(1) # টার্ন নেওয়ার জন্য বিরতি
def autonomous_loop(self):
try:
while self.is_running:
distance = self.read_ultrasonic_sensor()
print(f”[SENSOR] Distance to Obstacle: {distance} cm”)
if distance < self.safe_distance:
self.change_direction()
else:
self.move_forward()
time.sleep(0.5) # লুপ ডিলে
except KeyboardInterrupt:
self.is_running = False
print(“\n[STOP] Robot safely shut down.”)
# কোডটি রান করার জন্য:
if __name__ == “__main__”:
robot = RobotController(safe_distance=15.0)
# সিমুলেশন টেস্ট করার জন্য রান করুন (থামানোর জন্য Ctrl+C চাপুন)
# robot.autonomous_loop()