دالة run لبرنامج تحكم الطائرة بدون طيار - كتاب الذكاء الإصطناعي - الصف 12 - الفصل 1 - المملكة العربية السعودية

الكتاب: كتاب الذكاء الإصطناعي - الصف 12 - الفصل 1 | المادة: الذكاء الإصطناعي | المرحلة: الصف 12 | الفصل الدراسي: 1

الدولة: المملكة العربية السعودية | المنهج: المنهج السعودي - وزارة التعليم

الدرس: تنفيذ دالة التحكم الرئيسية للطائرة بدون طيار

📚 معلومات الصفحة

الكتاب: كتاب الذكاء الإصطناعي - الصف 12 - الفصل 1 | المادة: الذكاء الإصطناعي | المرحلة: الصف 12 | الفصل الدراسي: 1

الدولة: المملكة العربية السعودية | المنهج: المنهج السعودي - وزارة التعليم

نوع المحتوى: example

مستوى الصعوبة: متوسط

📝 ملخص الصفحة

تقدم هذه الصفحة مثالاً عملياً لدالة `run()` في برنامج تحكم الطائرة بدون طيار (الدرون). تحتوي الدالة على منطق التحكم الرئيسي الذي يدير عمليات الطيران والملاحة والكشف.

تبدأ الدالة بتهيئة المتغيرات الأساسية مثل فترات الوقت للضبط، واضطرابات المحاور (الانحراف، الميل، الانعراج)، ونقاط المرور للدوريات. يتم تحديد ارتفاع مستهدف للطائرة وإنشاء مجلد لتخزين الصور المكتشفة.

يحتوي الجزء الرئيسي من الدالة على حلقة while تقرأ بيانات المستشعرات باستمرار من IMU وGPS والجيروسكوب. عندما تصل الطائرة إلى الارتفاع المستهدف، تحسب الاضطرابات اللازمة للانتقال إلى نقاط المرور المحددة.

تتضمن الدالة أيضاً روتيناً لمعالجة الصور والكشف عن الأشكال البشرية كل 5 ثوانٍ، حيث تسترد صفيف الصورة من الكاميرا وتعالجها للكشف.

📋 المحتوى المنظم

📖 محتوى تعليمي مفصّل

نوع: محتوى تعليمي

بعد إضافة كل هذه الوظائف يجب أن تظهر الدالة ()run الخاصة ببرنامج المتحكم كما يلي:

نوع: محتوى تعليمي

def run(self): # time intervals used for adjustments in order to reach the target altitude t1 = self.getTime() # time intervals between each detection for human figures t2 = self.getTime() roll_disturbance = 0 pitch_disturbance = 0 yaw_disturbance = 0 # specifies the patrol coordinates waypoints = [[-30, 20], [-60, 30], [-75, 0], [-40, -10]] # target altitude of the drone in meters self.target_altitude = 8 # gets the current working directory cwd = os.getcwd() # sets the name of the folder where the images # with detected humans will be stored folder_name = "detected" # joins the current working directory and the new folder name folder_path = os.path.join(cwd, folder_name) if not os.path.exists(folder_path): # creates the folder if it doesn't exist already os.makedirs(folder_path) print(f"Folder \"detected\" created!") else: print(f"Folder \"detected\" already exists!") while self.step(self.time_step) != -1: # reads sensors roll, pitch, yaw = self.imu.getRollPitchYaw() x_pos, y_pos, altitude = self.gps.getValues() roll_acceleration, pitch_acceleration, _ = self.gyro.getValues() self.current_pose = [x_pos, y_pos, altitude, roll, pitch, yaw] if altitude > self.target_altitude - 1: # as soon as it reaches the target altitude, # computes the disturbances to go to the given waypoints if self.getTime() - t1 > 0.1: yaw_disturbance, pitch_disturbance = self.move_to_target( waypoints) t1 = self.getTime() # initiates the image processing and detection routine every 5 seconds if self.getTime() - t2 > 5.0: # retrieves image array from camera cameraImg = self.camera.getImageArray() # checks if image is successfully retrieved if cameraImg:

🔍 عناصر مرئية

Python run() function code listing

A block of Python code defining the `run` function for a controller program. It includes initialization of disturbance variables, definition of patrol waypoints, setting target altitude, managing a 'detected' folder for image storage, and a main loop. Inside the loop, it reads sensor data (IMU, GPS, Gyro), computes disturbances for navigation based on altitude and time intervals, and initiates image processing to retrieve camera data.

Ministry of Education Logo and Page Information

A logo featuring a green hexagonal pattern, accompanied by text in both Arabic and English. The Arabic text reads 'وزارة التعليم', followed by the number '333'. Below this, the English text 'Ministry of Education' is present, along with the years '2023 - 1445'.

📄 النص الكامل للصفحة

بعد إضافة كل هذه الوظائف يجب أن تظهر الدالة ()run الخاصة ببرنامج المتحكم كما يلي:def run(self): # time intervals used for adjustments in order to reach the target altitude t1 = self.getTime() # time intervals between each detection for human figures t2 = self.getTime()roll_disturbance = 0 pitch_disturbance = 0 yaw_disturbance = 0# specifies the patrol coordinates waypoints = [[-30, 20], [-60, 30], [-75, 0], [-40, -10]] # target altitude of the drone in meters self.target_altitude = 8# gets the current working directory cwd = os.getcwd() # sets the name of the folder where the images # with detected humans will be stored folder_name = "detected" # joins the current working directory and the new folder name folder_path = os.path.join(cwd, folder_name)if not os.path.exists(folder_path): # creates the folder if it doesn't exist already os.makedirs(folder_path) print(f"Folder \"detected\" created!") else: print(f"Folder \"detected\" already exists!")while self.step(self.time_step) != -1:# reads sensors roll, pitch, yaw = self.imu.getRollPitchYaw() x_pos, y_pos, altitude = self.gps.getValues() roll_acceleration, pitch_acceleration, _ = self.gyro.getValues() self.current_pose = [x_pos, y_pos, altitude, roll, pitch, yaw]if altitude > self.target_altitude - 1: # as soon as it reaches the target altitude, # computes the disturbances to go to the given waypoints if self.getTime() - t1 > 0.1: yaw_disturbance, pitch_disturbance = self.move_to_target( waypoints) t1 = self.getTime()# initiates the image processing and detection routine every 5 seconds if self.getTime() - t2 > 5.0:# retrieves image array from camera cameraImg = self.camera.getImageArray()# checks if image is successfully retrieved if cameraImg:--- VISUAL CONTEXT --- **FIGURE**: Python run() function code listing Description: A block of Python code defining the `run` function for a controller program. It includes initialization of disturbance variables, definition of patrol waypoints, setting target altitude, managing a 'detected' folder for image storage, and a main loop. Inside the loop, it reads sensor data (IMU, GPS, Gyro), computes disturbances for navigation based on altitude and time intervals, and initiates image processing to retrieve camera data. Context: This code example demonstrates the practical implementation of a drone's control logic, integrating various sensor inputs and decision-making processes for autonomous operation and data collection.