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

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

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

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

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

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

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

نوع المحتوى: درس تعليمي

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

📝 ملخص الصفحة

تتناول هذه الصفحة مقدمة برمجية للتحكم في الطائرة المسيرة باستخدام لغة Python. تبدأ بمكتبة برنامج التحكم التي تحتوي على فئة Robot (روبوت) التي توفر الطرائق اللازمة للتحكم في الطائرة المسيرة.

يتم استيراد عدة مكتبات أساسية مثل numpy للحسابات الرياضية، وos لإنشاء المجلدات، وcv2 لمعالجة الصور واكتشاف البشر، بالإضافة إلى PIL لإنشاء كائنات الصور وdatetime للتعامل مع التاريخ والوقت.

تتضمن الصفحة أيضًا دالة مساعدة تسمى clamp تستخدم لتقييم القيم ضمن نطاق محدد، وتعريف فئة Mavic التي ترث من فئة Robot وتحتوي على ثوابت تجريبية للتحكم في الطيران والاستقرار مثل K_VERTICAL_THRUST وK_VERTICAL_P وK_ROLL_P وK_PITCH_P.

يتم شرح طريقة التهيئة __init__ التي تقوم بتهيئة الطائرة المسيرة وتمكين الأجهزة المختلفة مثل الكاميرا ووحدة القصور الذاتي ونظام تحديد المواقع العالمي والجيروسكوب والمحركات.

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

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

مكتبة برنامج التحكم

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

تحتوي مكتبة برنامج المتحكم على فئة Robot (روبوت) التي ستستخدم طرائقها للتحكم في الطائرة المسيرة.

Import Statements

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

from controller import Robot import numpy as np # used for mathematic operations import os # used for folder creation import cv2 # used for image manipulation and human detection from PIL import Image # used for image object creation from datetime import datetime # used for date and time

استيراد المكتبات المطلوبة

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

استيراد المكتبات المطلوبة للحسابات والمعالجة.

Auxiliary Function

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

# auxiliary function used for calculations def clamp(value, value_min, value_max): return min(max(value, value_min), value_max)

Mavic Class and Constants

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

class Mavic (Robot): # constants of the drone used for flight # thrust for the drone to lift K_VERTICAL_THRUST = 68.5 # vertical offset the drone uses as targets for stabilization K_VERTICAL_OFFSET = 0.6 K_VERTICAL_P = 3.0 # P constant of the vertical PID K_ROLL_P = 50.0 # P constant of the roll PID K_PITCH_P = 30.0 # P constant of the pitch PID MAX_YAW_DISTURBANCE = 0.4 MAX_PITCH_DISTURBANCE = -1 # precision between the target position and the drone position in meters target_precision = 0.5

استخدام الثوابت (Constants)

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

تُستخدم الثوابت (Constants) الموجودة بشكل تجريبي لحساب الطيران والاستقرار.

Initialization Method

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

def __init__(self): # initializes the drone and sets the time interval between updates of the simulation Robot.__init__(self) self.time_step = int(self.getBasicTimeStep()) # gets and enables devices self.camera = self.getDevice("camera") self.camera.enable(self.time_step) self.imu = self.getDevice("inertial unit") self.imu.enable(self.time_step) self.gps = self.getDevice("gps") self.gps.enable(self.time_step) self.gyro = self.getDevice("gyro") self.gyro.enable(self.time_step) self.camera_pitch_motor = self.getDevice("camera pitch") self.camera_pitch_motor.setPosition(0.7) self.front_left_motor = self.getDevice("front left propeller") self.front_right_motor = self.getDevice("front right propeller") self.rear_left_motor = self.getDevice("rear left propeller") self.rear_right_motor = self.getDevice("rear right propeller") motors = [self.front_left_motor, self.front_right_motor, self.rear_left_motor, self.rear_right_motor] for motor in motors: # mass initialization of the four motors motor.setPosition(float('inf')) motor.setVelocity(1)

Footer Information

نوع: METADATA

وزارة التعليم 321 Ministry of Education 2023 - 1447

🔍 عناصر مرئية

مكتبة برنامج التحكم

An Arabic callout box with an arrow pointing to the Python import statements, explaining that the controller program library contains the Robot class whose methods will be used to control the drone.

استيراد المكتبات المطلوبة

An Arabic callout box with an arrow pointing to the Python import statements (numpy, os, cv2, PIL, datetime), explaining that these are the required libraries for calculations and processing.

استخدام الثوابت (Constants)

An Arabic callout box with an arrow pointing to the constant definitions within the `Mavic` class (e.g., K_VERTICAL_THRUST, K_VERTICAL_P, K_ROLL_P, K_PITCH_P), explaining that these experimentally derived constants are used for flight and stability calculations.

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

--- SECTION: مكتبة برنامج التحكم --- تحتوي مكتبة برنامج المتحكم على فئة Robot (روبوت) التي ستستخدم طرائقها للتحكم في الطائرة المسيرة.--- SECTION: Import Statements --- from controller import Robot import numpy as np # used for mathematic operations import os # used for folder creation import cv2 # used for image manipulation and human detection from PIL import Image # used for image object creation from datetime import datetime # used for date and time--- SECTION: استيراد المكتبات المطلوبة --- استيراد المكتبات المطلوبة للحسابات والمعالجة.--- SECTION: Auxiliary Function --- # auxiliary function used for calculations def clamp(value, value_min, value_max): return min(max(value, value_min), value_max)--- SECTION: Mavic Class and Constants --- class Mavic (Robot):# constants of the drone used for flight # thrust for the drone to lift K_VERTICAL_THRUST = 68.5 # vertical offset the drone uses as targets for stabilization K_VERTICAL_OFFSET = 0.6 K_VERTICAL_P = 3.0 # P constant of the vertical PID K_ROLL_P = 50.0 # P constant of the roll PID K_PITCH_P = 30.0 # P constant of the pitch PID MAX_YAW_DISTURBANCE = 0.4 MAX_PITCH_DISTURBANCE = -1 # precision between the target position and the drone position in meters target_precision = 0.5--- SECTION: استخدام الثوابت (Constants) --- تُستخدم الثوابت (Constants) الموجودة بشكل تجريبي لحساب الطيران والاستقرار.--- SECTION: Initialization Method --- def __init__(self): # initializes the drone and sets the time interval between updates of the simulation Robot.__init__(self) self.time_step = int(self.getBasicTimeStep())# gets and enables devices self.camera = self.getDevice("camera") self.camera.enable(self.time_step)self.imu = self.getDevice("inertial unit") self.imu.enable(self.time_step)self.gps = self.getDevice("gps") self.gps.enable(self.time_step)self.gyro = self.getDevice("gyro") self.gyro.enable(self.time_step)self.camera_pitch_motor = self.getDevice("camera pitch") self.camera_pitch_motor.setPosition(0.7)self.front_left_motor = self.getDevice("front left propeller") self.front_right_motor = self.getDevice("front right propeller") self.rear_left_motor = self.getDevice("rear left propeller") self.rear_right_motor = self.getDevice("rear right propeller") motors = [self.front_left_motor, self.front_right_motor, self.rear_left_motor, self.rear_right_motor] for motor in motors: # mass initialization of the four motors motor.setPosition(float('inf')) motor.setVelocity(1)--- SECTION: Footer Information --- 2023 - 1447--- VISUAL CONTEXT --- **ANNOTATION**: مكتبة برنامج التحكم Description: An Arabic callout box with an arrow pointing to the Python import statements, explaining that the controller program library contains the Robot class whose methods will be used to control the drone. Context: Explains the purpose of the `from controller import Robot` line in the Python code.**ANNOTATION**: استيراد المكتبات المطلوبة Description: An Arabic callout box with an arrow pointing to the Python import statements (numpy, os, cv2, PIL, datetime), explaining that these are the required libraries for calculations and processing. Context: Explains the general purpose of the import block for various functionalities like mathematics, file operations, image processing, and time handling.**ANNOTATION**: استخدام الثوابت (Constants) Description: An Arabic callout box with an arrow pointing to the constant definitions within the `Mavic` class (e.g., K_VERTICAL_THRUST, K_VERTICAL_P, K_ROLL_P, K_PITCH_P), explaining that these experimentally derived constants are used for flight and stability calculations. Context: Explains the role of defined constants in the drone's control system, specifically for flight and stabilization parameters.

🎴 بطاقات تعليمية للمراجعة

عدد البطاقات: 5 بطاقة لهذه الصفحة

ما هي الفئة الرئيسية الموجودة في مكتبة برنامج التحكم (Controller library) المستخدمة للتحكم في الطائرة المسيرة؟

الإجابة: الفئة الرئيسية هي `Robot`.

الشرح: تُستخدم فئة `Robot` في مكتبة برنامج التحكم للوصول إلى وظائف التحكم المختلفة الخاصة بالطائرة المسيرة، مثل تمكين وتشغيل الأجهزة والتحكم في المحركات.

تلميح: ابحث عن الفئة التي تم استيرادها للتحكم في الطائرة المسيرة.

اذكر بعض المكتبات الأساسية التي يتم استيرادها للتعامل مع الحسابات ومعالجة الصور في هذا البرنامج.

الإجابة: تشمل المكتبات الأساسية `numpy` (للعمليات الرياضية)، `os` (لإنشاء المجلدات)، `cv2` (لمعالجة الصور والكشف عن البشر)، `PIL` (لإنشاء كائنات الصور)، و `datetime` (للتاريخ والوقت).

الشرح: يتم استيراد هذه المكتبات لتوفير وظائف ضرورية لتشغيل البرنامج، مثل إجراء العمليات الحسابية المعقدة، ومعالجة البيانات المرئية، وإدارة الملفات، وتسجيل الوقت.

تلميح: انظر إلى العبارات التي تبدأ بـ `import` في بداية الكود.

ما هو الغرض من الدالة المساعدة `clamp`؟

الإجابة: الدالة `clamp` تُستخدم لتحديد قيمة ما ضمن نطاق معين بين حد أدنى وحد أقصى. فهي تضمن أن القيمة المدخلة لا تتجاوز الحدود المحددة.

الشرح: هذه الدالة مفيدة لضمان أن القيم المستخدمة في حسابات التحكم (مثل سرعة المحرك أو زاوية الميل) تظل ضمن الحدود التشغيلية الآمنة والمقبولة للطائرة المسيرة.

تلميح: فكر في كيفية الحد من قيمة معينة لتبقى ضمن نطاق محدد.

ما هي بعض الثوابت (Constants) الهامة المعرفة داخل فئة `Mavic` وكيف تُستخدم؟

الإجابة: من الثوابت الهامة: `K_VERTICAL_THRUST` (قوة الدفع الرأسية للإقلاع)، `K_VERTICAL_OFFSET` (الإزاحة الرأسية للتحكم في الاستقرار)، `K_VERTICAL_P`, `K_ROLL_P`, `K_PITCH_P` (ثوابت PID للتحكم في الارتفاع، الانحراف، والميل)، و `target_precision` (الدقة المستهدفة للموقع). تُستخدم هذه الثوابت في حسابات الطيران والاستقرار.

الشرح: تُستخدم هذه الثوابت كمعاملات في خوارزميات التحكم لضبط سلوك الطائرة المسيرة، مما يضمن الطيران المستقر والدقيق.

تلميح: ابحث عن المتغيرات المعرفة في مستوى الفئة (class level) والتي تبدأ عادةً بـ `K_` أو تشير إلى قيم ثابتة.

ما هي الأجهزة التي يتم تمكينها (enable) داخل دالة `__init__` لفئة `Mavic`؟

الإجابة: يتم تمكين الأجهزة التالية: `camera` (الكاميرا)، `imu` (وحدة القياس بالقصور الذاتي)، `gps` (نظام تحديد المواقع العالمي)، و `gyro` (الجيروسكوب).

الشرح: تمكين هذه الأجهزة يسمح للفئة بالحصول على بيانات حسية حيوية من الطائرة المسيرة، مثل الصور، وبيانات التسارع والدوران، والموقع الجغرافي، والتي تُستخدم في عمليات الملاحة والتحكم.

تلميح: ابحث عن استدعاءات `self.getDevice(...)` متبوعة بـ `.enable(self.time_step)`.