وحدة التحكم#

مقدمة#

يتميز جهاز التحكم بالطائرات بدون طيار VEX AIR بتصميم يحتوي على 12 زرًا وعصا تحكم مزدوجة. تتيح هذه المدخلات للطائرة بدون طيار اكتشاف ضغطات الأزرار وحركات عصا التحكم، مما يوفر تحكمًا تفاعليًا وسريع الاستجابة.

فيما يلي قائمة بجميع الطرق المتاحة:

أجهزة الاستقبال – قراءة حالة الزر، وعصا التحكم، والاتصال.

  • pressing – يتم إرجاع ما إذا كان يتم الضغط على زر معين حاليًا.

  • position – تُرجع موضع عصا التحكم على طول محور محدد.

  • is_drone_connected – تُرجع ما إذا كان جهاز التحكم متصلاً بالطائرة بدون طيار.

  • get_battery_level – تُرجع مستوى بطارية وحدة التحكم.

الاستجابة للتغييرات في إدخال الأزرار أو عصا التحكم.

  • pressed – يقوم بتشغيل وظيفة عند الضغط على زر محدد.

  • released – يقوم بتشغيل وظيفة عند تحرير زر محدد.

  • changed – يقوم بتشغيل وظيفة عندما يتغير موضع عصا التحكم على طول محور محدد.

المحصلون#

pressing#

يؤدي الضغط على pressing تشير إلى ما إذا كان زر معين على وحدة التحكم مضغوطًا حاليًا. يجب استدعاء هذه الطريقة على كائن زر محدد، مثل button5 (انظر القائمة الكاملة لكائنات الأزرار أدناه).

  • True - يتم الضغط على الزر المحدد.

  • False - الزر المحدد غير مضغوط.

طريقة الاستخدام:
يمكن استخدام أحد الأزرار الثمانية المتاحة، المرقمة من 5 إلى 12، مع هذه الطريقة، كما هو موضح أدناه:

زر

يأمر

button5

controller.button5.pressing() — Button 5

button6

controller.button6.pressing() — Button 6

button7

controller.button7.pressing() — Button 7

button8

controller.button8.pressing() — Button 8

button9

controller.button9.pressing() — Button 9

button10

controller.button10.pressing() — Button 10

button11

controller.button11.pressing() — Button 11

button12

controller.button12.pressing() — Button 12

جهاز تحكم طائرة بدون طيار VEX AIR يوضح الأزرار من 5 إلى 12. يقع الزران 5 و6 في الجزء الخلفي من الجانب الأيمن لجهاز التحكم، بشكل عمودي على عصا التحكم. يقع الزران 7 و8 في نفس الموضع على الجانب الأيسر. تقع الأزرار من 9 إلى 12 على السطح السفلي لجهاز التحكم، حيث يقع الزر 9 في الزاوية العلوية اليمنى فوق الزر 10، ويقع الزر 11 في الزاوية العلوية اليسرى فوق الزر 12.

حدود

وصف

لا تحتوي هذه الطريقة على أي معلمات.

# Take a picture when button 5 is pressed.
drone.take_off(climb_to=500)
while True:
    # Fly using the controller sticks
    drone.move_with_vectors(
        forward=controller.axis4.position(),
        rightward=controller.axis3.position(),
        upward=controller.axis1.position(),
        rotation=controller.axis2.position()
    )

    # Capture an image from the forward camera when button 5 is pressed.
    if controller.button5.pressing():
        drone.camera.capture_image(FORWARD_CAMERA)

    wait(5, MSEC)

position#

position تُرجع موضع المحور المحدد لعصا التحكم، كنسبة مئوية من -100% إلى 100%.

طريقة الاستخدام:

يمكن استخدام أحد المحاور الأربعة المتاحة مع هذه الطريقة، وهي مرقمة من 1 إلى 4.

محور

يأمر

axis1

controller.axis1.position() — المحور الرأسي لعصا التحكم اليسرى

axis2

controller.axis2.position() — المحور الأفقي لعصا التحكم اليسرى

axis3

controller.axis3.position() — المحور الأفقي لعصا التحكم اليمنى

axis4

controller.axis4.position() — المحور الرأسي لعصا التحكم اليمنى

جهاز تحكم طائرة بدون طيار من نوع VEX AIR مع تمييز تسميات المحورين 1 و2 حول عصا التحكم اليسرى، وتسميات المحورين 3 و4 حول عصا التحكم اليمنى.

حدود

وصف

لا تحتوي هذه الطريقة على أي معلمات.

# Climb when the left joystick is moved up.
drone.take_off(climb_to=500)
while True:
    if controller.axis1.position() > 0:
        drone.climb(direction=UP, velocity=50)
    else:
        drone.hover()
    wait(5, MSEC)

is_drone_connected#

is_drone_connected تُرجع قيمة منطقية تشير إلى ما إذا كانت الطائرة بدون طيار متصلة أم لا.

  • True - الطائرة بدون طيار متصلة.

  • False - الطائرة بدون طيار غير متصلة.

طريقة الاستخدام:

controller.is_drone_connected()

حدود

وصف

لا تحتوي هذه الطريقة على أي معلمات.

# Print controller connection status on screen.
while True:
    if controller.is_drone_connected():
        controller.screen.clear_screen()
        controller.screen.set_cursor(1, 1)
        controller.screen.print("Controller connected")
    wait(0.5, SECONDS)

get_battery_level#

get_battery_level تُرجع مستوى بطارية وحدة التحكم، كنسبة مئوية من 0% إلى 100%.

طريقة الاستخدام:

controller.get_battery_level()

حدود

وصف

لا تحتوي هذه الطريقة على أي معلمات.

# Show controller's battery level.
if controller.get_battery_level() > 50:
    controller.screen.print("Battery level ok")
else:
    controller.screen.print("Battery level low")

معاودة الاتصال#

pressed#

pressed runs a function when the specified button is pressed. Once it is used, the function will run automatically each time that button is pressed.

طريقة الاستخدام:
يمكن استخدام واحد من الأزرار الثمانية المتاحة مع هذه الطريقة، المرقمة من 5 إلى 12.

زر

يأمر

button5

controller.button5.pressing() — Button 5

button6

controller.button6.pressing() — Button 6

button7

controller.button7.pressing() — Button 7

button8

controller.button8.pressing() — Button 8

button9

controller.button9.pressing() — Button 9

button10

controller.button10.pressing() — Button 10

button11

controller.button11.pressing() — Button 11

button12

controller.button12.pressing() — Button 12

جهاز تحكم طائرة بدون طيار VEX AIR يوضح الأزرار من 5 إلى 12. يقع الزران 5 و6 في الجزء الخلفي من الجانب الأيمن لجهاز التحكم، بشكل عمودي على عصا التحكم. يقع الزران 7 و8 في نفس الموضع على الجانب الأيسر. تقع الأزرار من 9 إلى 12 على السطح السفلي لجهاز التحكم، حيث يقع الزر 9 في الزاوية العلوية اليمنى فوق الزر 10، ويقع الزر 11 في الزاوية العلوية اليسرى فوق الزر 12.

حدود

وصف

callback

A previously defined function to run each time the specified button is pressed.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Events with Parameters for more information.

# Take a picture when button 5 is pressed.
def take_picture():
    drone.camera.capture_image(FORWARD_CAMERA)

# Run take_picture each time button 5 is pressed.
controller.button5.pressed(take_picture)

# Fly using the controller sticks.
drone.take_off(climb_to=500)
while True:
    drone.move_with_vectors(
        forward=controller.axis4.position(),
        rightward=controller.axis3.position(),
        upward=controller.axis1.position(),
        rotation=controller.axis2.position()
    )
    wait(5, MSEC)

released#

released runs a function when the specified button is released. Once it is used, the function will run automatically each time that button is released.

طريقة الاستخدام:
يمكن استخدام واحد من الأزرار الثمانية المتاحة مع هذه الطريقة، المرقمة من 5 إلى 12.

زر

يأمر

button5

controller.button5.pressing() — Button 5

button6

controller.button6.pressing() — Button 6

button7

controller.button7.pressing() — Button 7

button8

controller.button8.pressing() — Button 8

button9

controller.button9.pressing() — Button 9

button10

controller.button10.pressing() — Button 10

button11

controller.button11.pressing() — Button 11

button12

controller.button12.pressing() — Button 12

جهاز تحكم طائرة بدون طيار VEX AIR يوضح الأزرار من 5 إلى 12. يقع الزران 5 و6 في الجزء الخلفي من الجانب الأيمن لجهاز التحكم، بشكل عمودي على عصا التحكم. يقع الزران 7 و8 في نفس الموضع على الجانب الأيسر. تقع الأزرار من 9 إلى 12 على السطح السفلي لجهاز التحكم، حيث يقع الزر 9 في الزاوية العلوية اليمنى فوق الزر 10، ويقع الزر 11 في الزاوية العلوية اليسرى فوق الزر 12.

حدود

وصف

callback

A previously defined function to run each time the specified button is released.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

# Take a picture when button 5 is released.
def take_picture():
    drone.camera.capture_image(FORWARD_CAMERA)

# Run take_picture each time button 5 is released.
controller.button5.released(take_picture)

# Fly using the controller sticks.
drone.take_off(climb_to=500)
while True:
    drone.move_with_vectors(
        forward=controller.axis4.position(),
        rightward=controller.axis3.position(),
        upward=controller.axis1.position(),
        rotation=controller.axis2.position()
    )
    wait(5, MSEC)

changed#

يُشغّل الأمر changed عند تغيير موضع عصا التحكم على طول المحور المحدد. وبمجرد استخدامه، سيتم تشغيل الوظيفة تلقائيًا في كل مرة يتغير فيها موضع عصا التحكم على طول ذلك المحور.

طريقة الاستخدام:

يمكن استخدام أحد المحاور الأربعة المتاحة مع هذه الطريقة، وهي مرقمة من 1 إلى 4.

محور

يأمر

axis1

controller.axis1.position() — المحور الرأسي لعصا التحكم اليسرى

axis2

controller.axis2.position() — المحور الأفقي لعصا التحكم اليسرى

axis3

controller.axis3.position() — المحور الأفقي لعصا التحكم اليمنى

axis4

controller.axis4.position() — المحور الرأسي لعصا التحكم اليمنى

جهاز تحكم طائرة بدون طيار من نوع VEX AIR مع تمييز تسميات المحورين 1 و2 حول عصا التحكم اليسرى، وتسميات المحورين 3 و4 حول عصا التحكم اليمنى.

حدود

وصف

callback

A previously defined function to run each time the joystick’s position changes along the specified axis.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

# Move forward when the left joystick moves.
def on_axis1_changed():
    drone.move_for(direction=0, distance=200, velocity=50, units=MM)

drone.take_off(climb_to=500)
controller.axis1.changed(on_axis1_changed)