وحدة التحكم#

مقدمة#

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

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

الإجراءات — إخراج نص أو مسح وحدة التحكم.

  • print — يعرض النص أو الأرقام أو قيم المتغيرات في وحدة التحكم.

  • new_line — ينقل مؤشر وحدة التحكم إلى بداية السطر التالي.

  • clear — يمسح جميع الصفوف في وحدة التحكم.

المُستقبِل — قراءة مُدخلات المستخدم.

  • input — ينتظر إدخال المستخدم ويعيد الاستجابة كنص.

المُعدِّل — تنسيق النص المطبوع.

  • set_print_color — يحدد اللون المستخدم للنص المطبوع في وحدة التحكم.

مراقبة — راقب قيمة المستشعر أو المتغير أثناء المشروع في علامة تبويب المراقبة في VEXcode.

  • monitor_sensor — يضيف قيمة واحدة أو أكثر من قيم المستشعر إلى علامة التبويب Monitor.

  • monitor_variable — يضيف متغيرًا واحدًا أو أكثر من المتغيرات المحددة مسبقًا إلى علامة التبويب Monitor.

الإجراءات#

print#

يعرض الأمر print نصًا أو أرقامًا أو قيمًا متغيرة في وحدة التحكم باستخدام موضع المؤشر الحالي.

استخدم تنسيق السلاسل النصية المخصص عندما تريد أن تتضمن الرسالة المطبوعة قيمًا من مشروعك، مثل النتيجة أو المؤقت أو قراءة المستشعر. راجع صفحة تنسيق السلاسل النصية لمزيد من المعلومات.

استخدم new_line عندما تريد أن تبدأ القيمة المطبوعة التالية في صف جديد.

Usage:
console.print(value, precision)

حدود

وصف

value

النص أو الرقم أو قيمة المتغير المراد عرضها في وحدة التحكم.

precision

اختياري. عدد المنازل العشرية التي سيتم عرضها عند طباعة رقم. القيمة الافتراضية هي 0، لذا تتم طباعة الأرقام بدون منازل عشرية.

def main():
    # Display a message in the Console
    console.print("Hello, robot!")

# Start threads — Do not delete
start_thread(main)

وحدة تحكم VEXcode، تعرض وحدة التحكم والنص "مرحباً أيها الروبوت!".

def main():
    # Display 1/3 with two decimals
    console.print(1 / 3, precision=2)

# Start threads — Do not delete
start_thread(main)

وحدة تحكم VEXcode، تعرض وحدة التحكم والنص "0.33".

new_line#

يؤدي الأمر new_line إلى نقل المؤشر إلى العمود 1 في الصف التالي في وحدة التحكم. ستظهر القيمة التالية المطبوعة في ذلك الصف.

استخدم هذه الطريقة عندما تريد أن تبدأ القيمة المطبوعة التالية في صف جديد.

Usage:
console.new_line()

حدود

وصف

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

def main():
    # Print on two lines
    console.print("Row 1")
    console.new_line()
    console.print("Row 2")

# Start threads — Do not delete
start_thread(main)

وحدة تحكم VEXcode، تعرض وحدة التحكم والنص "الصف 1" معروضًا في السطر الأول و"الصف 2" في السطر الثاني.

clear#

clear يمسح جميع الصفوف من وحدة التحكم.

Usage:
console.clear()

حدود

وصف

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

def main():
    # Display text, then clear it after two seconds
    console.print("This will disappear...")
    wait(2, SECONDS)
    console.clear()

# Start threads — Do not delete
start_thread(main)

المحصل#

input#

input ينتظر من المستخدم إدخال رد، ثم يعيد هذا الرد كنص.

يتوقف المشروع عند المدخل input() يتم إدخال استجابة في وحدة التحكم.

القيمة المُعادة من input() نص. لاستخدام الاستجابة كرقم، قم بتحويلها أولًا باستخدام int() () أو float()

Usage:
input()

حدود

وصف

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

# Ask for a name, then print a greeting
answer = input("What's your name?")
console.print("Hello, " + answer)

# Ask for a number, then use it in math
answer = input("Enter a number:")
number = float(answer)
console.print(number + 1)

المُعدِّل#

set_print_color#

يُحدد set_print_color لون النص المطبوع في وحدة التحكم بعد استخدام هذه الطريقة. عند بدء المشروع، يكون لون نص وحدة التحكم هو BLUE.

Usage:
console.set_print_color(color)

حدود

وصف

color

اللون المستخدم للنص المطبوع في وحدة التحكم:

  • BLACK
  • BLUE
  • GREEN
  • RED

def main():
    # Print text in different colors
    console.print("Default text color")
    console.new_line()
    console.set_print_color(RED)
    console.print("Red text color")

# Start threads — Do not delete
start_thread(main)

وحدة تحكم VEXcode، تعرض وحدة التحكم ونصًا أزرق اللون يقول "لون النص الافتراضي" معروضًا في السطر الأول ونصًا أحمر اللون يقول "لون النص الأحمر" في السطر الثاني.

شاشة#

monitor_sensor#

يُضيف الأمر monitor_sensor قيمة مستشعر واحد أو أكثر إلى علامة التبويب “المراقبة” في VEXcode. يتيح لك هذا مراقبة تغير قيم المستشعر أثناء تشغيل المشروع.

قم بتوفير قيمة كل مستشعر كسلسلة نصية.

Usage:
monitor_sensor(“sensor”)
monitor_sensor(“sensor1”, “sensor2”)

حدود

وصف

sensor

The sensor value to monitor, given as a string. To monitor more than one sensor value, separate each sensor value with a comma. Options include:

  • Timer
    • timer.time
  • Drivetrain
    • drivetrain.get_heading
    • drivetrain.get_rotation
    • drivetrain.get_velocity
    • drivetrain.get_yaw
    • drivetrain.get_roll
    • drivetrain.get_pitch
    • drivetrain.get_crashed
    • drivetrain.is_stopped
  • Motor
    • motor.get_position
    • motor.get_velocity
    • motor.get_current
    • motor.is_stopped
    • motor.is_moving
  • Inertial
    • inertial.get_rotation
    • inertial.get_heading
    • inertial.get_yaw
    • inertial.get_roll
    • inertial.get_pitch
    • inertial.get_accelerationX
    • inertial.get_accelerationY
    • inertial.get_accelerationZ
  • Bumper
    • bumper.is_pressed
  • Eye
    • eye.get_color
    • eye.get_hue
    • eye.get_brightness
    • eye.is_object_detected
    • eye.is_color_detected

# Build Used: Super Code Base 2.0
def main():
    # Monitor the rotation in the Monitor tab
    monitor_sensor("drivetrain.get_rotation")
    drivetrain.turn_for(RIGHT, 450)

# Start threads — Do not delete
start_thread(main)

# Build Used: Super Code Base 2.0
def main():
    # Monitor the rotation and heading in the Monitor tab
    monitor_sensor("drivetrain.get_rotation", "drivetrain.get_heading")
    drivetrain.turn_for(RIGHT, 450)

# Start threads — Do not delete
start_thread(main)

monitor_variable#

يُضيف الأمر monitor_variable متغيرًا واحدًا أو أكثر من المتغيرات المُعرّفة مسبقًا إلى علامة التبويب “المراقبة” في VEXcode. يتيح لك هذا مراقبة تغير قيمة المتغير أثناء تشغيل المشروع.

يجب أن تكون المتغيرات monitor_variable نصية.

Usage:
monitor_variable(“variable”)
monitor_variable(“variable1”, “variable2”)

حدود

وصف

variable

اسم متغير عام مُعرَّف مسبقًا للمراقبة، يُعطى كسلسلة نصية. لمراقبة أكثر من متغير، افصل بين أسماء المتغيرات بفاصلة.

# Build Used: Super Code Base 2.0
def main():
    # Monitor the amount of loops
    global loops
    monitor_variable("loops")

    # Drive in a square 3 times
    for loops in range(12):
        drivetrain.turn_for(RIGHT, 90, DEGREES)
        drivetrain.drive_for(FORWARD, 150, MM)

# Start threads — Do not delete
start_thread(main)

actions = 0

# Build Used: Super Code Base 2.0
def main():
    # Monitor the amount of loops and actions
    global loops, actions
    monitor_variable("loops", "actions")

    # Drive in a square 3 times
    for loops in range(12):
        drivetrain.turn_for(RIGHT, 90, DEGREES)
        drivetrain.drive_for(FORWARD, 150, MM)
        actions = actions + 2

# Start threads — Do not delete
start_thread(main)