حركة#
مقدمة#
Motors control how parts of a robot move. Motors can be used to raise an arm, turn a claw, spin a wheel, or move another part of a build. Two motors can work together as a drivetrain to move and turn the whole robot.
يتم ضبط كل محرك في نافذة الأجهزة. قد تختلف أسماء المحركات باختلاف الإصدار. على سبيل المثال، يحتوي إصدار Competition Advanced 2.0 على محرك باسم arm_motorقد يستخدم الروبوت المخصص أسماء محركات مختلفة.
افتراضياً، يُشغّل الخيار FORWARD (للخلف) المحرك عكس اتجاه عقارب الساعة، بينما يُشغّل الخيار REVERSE (للعكس) المحرك مع اتجاه عقارب الساعة. إذا تم ضبط المحرك على الدوران العكسي في نافذة الأجهزة، فسيتم عكس هذه الاتجاهات.
توجد طرق عديدة لبرمجة المحركات. فيما يلي قائمة بجميع طرق الحركة:
الإجراءات — إيقاف المحركات وتدويرها.
spin— يدور المحرك للأمام أو للخلف إلى الأبد.spin_for— يدور محركًا لمسافة محددة.spin_to_position— يدور المحرك إلى موضع محدد.stop— يوقف المحرك عن الدوران.
المُعدِّلات — اضبط إعدادات المحرك.
set_velocity— يخبر المحرك بمدى سرعة دورانه.set_max_torque— يحدد مدى قوة الدفع المسموح بها للمحرك أثناء الدوران.set_position— يغير موضع المحرك الحالي إلى قيمة جديدة.set_stopping— يحدد كيفية توقف المحرك عن الحركة: عن طريق الكبح أو الانزلاق أو الثبات.set_timeout— يحدد مقدار الوقت الذي سيحاول فيه المحرك إنهاء الحركة.
أجهزة الجلب - تحقق من حالة المحرك.
get_position— يعيد الموضع الحالي للمحرك.get_velocity— تُرجع هذه الدالة مدى سرعة دوران المحرك، كنسبة مئوية من -100% إلى 100%.get_current— تُرجع مقدار الطاقة التي يستخدمها المحرك من البطارية، كنسبة مئوية من 0% إلى 100%.is_stopped— تُرجع ما إذا كان المحرك قد انتهى من الحركة، كقيمة منطقية.is_moving— تُرجع ما إذا كان المحرك يدور، كقيمة منطقية.
الإجراءات#
spin#
spin يُدير المحرك للأمام أو للخلف باستمرار. سيستمر المحرك في الدوران حتى يتم إعطاؤه إجراءً آخر، مثل الدوران في اتجاه مختلف أو التوقف.
Usage:
arm_motor.spin(direction)
حدود |
وصف |
|---|---|
|
اتجاه دوران المحرك: |
# Build Used: Competition Advanced 2.0
def main():
# Raise the ArmMotor, then stop
arm_motor.spin(REVERSE)
wait(1, SECONDS)
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
spin_for#
spin_for spins a motor for a specific distance. The spin is relative to the current position of the motor. The project will wait until the motor is done spinning before the next line of code runs.
Usage:
arm_motor.spin_for(direction, angle, units, wait)
حدود |
وصف |
|---|---|
|
اتجاه دوران المحرك: |
|
المسافة التي يدورها المحرك. |
|
اختياري. وحدة المسافة: |
|
اختياري. |
# Build Used: Competition Advanced 2.0
def main():
# Raise and lower the ArmMotor
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
arm_motor.spin_for(FORWARD, 180, DEGREES)
# Start threads — Do not delete
start_thread(main)
spin_to_position#
spin_to_position يقوم بتدوير المحرك إلى موضع محدد.
A motor’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. At the beginning of a project, the motor position is set to 0 degrees. The motor position can also be set using the set_position method.
قيم الموضع مطلقة. وهذا يعني أن اتجاه الدوران يعتمد على الموضع الحالي للمحرك.
على سبيل المثال، إذا بدأ المحرك من زاوية صفر درجة ثم دار إلى زاوية 720 درجة، فسيدور دورتين للأمام. وإذا دار بعد ذلك إلى زاوية 360 درجة، فسيدور دورة واحدة للخلف، لأن 360 درجة أقل من 720 درجة.
Usage:
arm_motor.spin_to_position(angle, units, wait)
حدود |
وصف |
|---|---|
|
قيمة الموضع الذي سيدور إليه المحرك. |
|
اختياري. وحدة تحديد الموضع: |
|
اختياري. |
# Build Used: Competition Advanced 2.0
def main():
# Return ArmMotor to 0 degrees after raising
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
arm_motor.spin_to_position(0, DEGREES)
# Start threads — Do not delete
start_thread(main)
stop#
stop يوقف دوران المحرك.
Usage:
arm_motor.stop()
حدود |
وصف |
|---|---|
لا تحتوي هذه الطريقة على أي معلمات. |
# Build Used: Competition Advanced 2.0
def main():
# Raise the ArmMotor
arm_motor.spin(REVERSE)
wait(1, SECONDS)
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
المتحولون#
set_velocity#
يُحدد set_velocity سرعة دوران المحرك. كلما زادت النسبة المئوية، زادت سرعة دوران المحرك، وكلما انخفضت، قلت سرعة دورانه.
يبدأ كل مشروع بدوران كل محرك بسرعة 50% بشكل افتراضي.
ملاحظة: السرعة العالية تجعل المحرك يدور أسرع، لكنها قد تكون أقل دقة. السرعة المنخفضة تجعل المحرك يدور أبطأ، لكنها قد تكون أكثر دقة.
Usage:
arm_motor.set_velocity(velocity)
حدود |
وصف |
|---|---|
|
سرعة الدوران من 0% إلى 100%. يمكن أن تكون هذه القيمة عددًا |
# Build Used: Competition Advanced 2.0
def main():
# Move the ArmMotor at different velocities
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
# Move slow
arm_motor.set_velocity(20)
arm_motor.spin_for(FORWARD, 180, DEGREES)
wait(1, SECONDS)
# Move fast
arm_motor.set_velocity(100)
arm_motor.spin_for(REVERSE, 180, DEGREES)
# Start threads — Do not delete
start_thread(main)
set_max_torque#
عزم الدوران هو قوة دوران. وهو يوضح مدى قوة الدفع أو السحب التي يمكن للمحرك أن يقوم بها عند دورانه.
set_max_torque يحدد أقصى عزم دوران يُسمح للمحرك باستخدامه.
نسبة أعلى تسمح للمحرك بالدفع بقوة أكبر، كما هو الحال عند رفع جسم ثقيل. أما نسبة أقل فتحدّ من قوة الدفع التي يمكن للمحرك القيام بها. وهذا يساعد على حماية الروبوت في حال تعطل المحرك أو وصوله إلى أقصى مدى يمكنه التحرك فيه.
يبدأ كل مشروع بعزم دوران كل محرك بنسبة 50% بشكل افتراضي.
Usage:
arm_motor.set_max_torque(value)
حدود |
وصف |
|---|---|
|
أقصى عزم دوران يمكن للمحرك استخدامه يتراوح من 0% إلى 100%. يمكن أن يكون هذا عددًا |
# Build Used: Competition Advanced 2.0
def main():
# Move the ArmMotor at different torques
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
# Move with less torque
arm_motor.set_max_torque(20)
arm_motor.spin_for(FORWARD, 180, DEGREES)
wait(1, SECONDS)
# Move with maximum torque
arm_motor.set_max_torque(100)
arm_motor.spin_for(REVERSE, 180, DEGREES)
# Start threads — Do not delete
start_thread(main)
set_position#
موضع المحرك هو مقدار دورانه، ويُقاس بالدرجات DEGREES أو TURNS. الدورة الواحدة تساوي 360 درجة. يُغيّر set_position موضع المحرك الحالي إلى قيمة جديدة.
على سبيل المثال، إذا دار المحرك بزاوية 180 درجة، فإن ضبط الموضع على 0 درجة سيعيد ضبط هذا الموضع من 180 إلى 0 درجة. بعد ذلك، يمكن للمحرك أن يدور إلى مواضع بناءً على هذه القيمة الجديدة.
Usage:
arm_motor.set_position(position, units)
حدود |
وصف |
|---|---|
|
قيمة الموضع المراد ضبطها للمحرك. |
|
اختياري. وحدة تحديد الموضع: |
# Build Used: Competition Advanced 2.0
def main():
# Return ArmMotor to 0 degrees after raising
arm_motor.set_position(0, DEGREES)
arm_motor.spin_for(REVERSE, 180, DEGREES)
wait(1, SECONDS)
arm_motor.spin_to_position(0, DEGREES)
# Start threads — Do not delete
start_thread(main)
set_stopping#
set_stopping يحدد كيفية توقف المحرك عن الحركة: عن طريق الكبح، أو الانزلاق، أو الثبات.
Usage:
arm_motor.set_stopping(mode)
حدود |
وصف |
|---|---|
|
كيفية توقف المحرك:
|
على سبيل المثال، إذا تم استخدام إصدار Competition Advanced 2.0 وتم ضبط قيمة arm_motor على HOLD، فسيثبت المحرك الذراع في موضعها الحالي حتى تحدث حركة أخرى للذراع. هذا يعني أن المحرك سيعمل ضد الجاذبية لإبقاء الذراع في الهواء إذا توقف المحرك والذراع مرفوعة.
إذا لم يتم استخدام هذه الطريقة، فسيستخدم المحرك BRAKE عند التوقف.
# Build Used: Competition Advanced 2.0
def main():
# Move the ArmMotor, then coast to a stop
arm_motor.set_velocity(20)
arm_motor.set_stopping(COAST)
arm_motor.spin(REVERSE)
wait(1, SECONDS)
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
set_timeout#
يُحدد set_timeout المدة الزمنية التي سيحاول فيها المحرك إكمال الحركة. إذا لم يتمكن المحرك من إكمالها خلال هذه المدة، فسيتوقف عن المحاولة وينتقل إلى السطر التالي من التعليمات البرمجية. هذا يمنع المحرك من التوقف أثناء الحركة.
Usage:
arm_motor.set_timeout(value, units)
حدود |
وصف |
|---|---|
|
مقدار الوقت الذي يمكن للمحرك أن يحاول فيه إنهاء الحركة. يمكن أن يكون هذا عددًا صحيحًا موجبًا |
|
اختياري. وحدة الوقت: |
# Build Used: Competition Advanced 2.0
def main():
# Move ArmMotor as far as possible for 1 second before resetting
arm_motor.set_position(0, DEGREES)
arm_motor.set_timeout(1, SECONDS)
arm_motor.spin_for(REVERSE, 180, DEGREES)
arm_motor.spin_to_position(0, DEGREES)
# Start threads — Do not delete
start_thread(main)
المحصلون#
get_position#
A motor’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. get_position returns the motor’s current position.
في بداية المشروع، يتم ضبط موضع المحرك على صفر درجة. إذا دار المحرك دورة كاملة للأمام، فسيكون الموضع 360 درجة أو دورة واحدة. أما إذا دار المحرك في الاتجاه المعاكس، فسيكون الموضع سالباً.
Usage:
arm_motor.get_position(units)
حدود |
وصف |
|---|---|
|
اختياري. وحدة إعادة موضع المحرك: |
# Build Used: Competition Advanced 2.0
def main():
# Display how far the ArmMotor moves after one second
arm_motor.set_position(0, DEGREES)
console.print("Start: ")
console.print(arm_motor.get_position(DEGREES))
console.new_line()
arm_motor.spin(REVERSE)
wait(1, SECONDS)
arm_motor.stop()
console.print("After: ")
console.print(arm_motor.get_position(DEGREES))
# Start threads — Do not delete
start_thread(main)
get_velocity#
get_velocity تُرجع سرعة دوران المحرك، كنسبة مئوية من -100% إلى 100%.
تشير القيمة الموجبة إلى أن المحرك يدور للأمام. وتشير القيمة السالبة إلى أن المحرك يدور للخلف.
Usage:
arm_motor.get_velocity()
حدود |
وصف |
|---|---|
لا تحتوي هذه الطريقة على أي معلمات. |
# Build Used: Competition Advanced 2.0
def main():
# Display the ArmMotor's velocity when it moves
console.print("Resting: ")
console.print(arm_motor.get_velocity())
console.new_line()
arm_motor.spin(REVERSE)
wait(1, SECONDS)
console.print("Moving: ")
console.print(arm_motor.get_velocity())
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
get_current#
get_current تُرجع مقدار الطاقة التي يستخدمها المحرك من البطارية، كنسبة مئوية من 0% إلى 100%.
تشير قيمة التيار الأعلى إلى أن المحرك يستهلك طاقة أكبر. قد يحدث هذا عندما يرفع المحرك شيئًا ثقيلًا، أو يدفع جسمًا ما، أو يحاول التحرك وهو عالق.
Usage:
arm_motor.get_current()
حدود |
وصف |
|---|---|
لا تحتوي هذه الطريقة على أي معلمات. |
# Build Used: Competition Advanced 2.0
def main():
# Display the motor's current when it moves
console.print("Resting: ")
console.print(arm_motor.get_current())
console.new_line()
arm_motor.spin(REVERSE)
wait(1, SECONDS)
console.print("Moving: ")
console.print(arm_motor.get_current())
arm_motor.stop()
# Start threads — Do not delete
start_thread(main)
is_stopped#
تُشير القيمة المنطقية is_stopped . ويمكن استخدام هذه القيمة للتحكم في توقيت سلوكيات أخرى بناءً على حركة المحرك.
True— انتهى المحرك من الحركة.False— المحرك لا يزال يتحرك.
تعمل هذه الطريقة جنبًا إلى جنب مع طرق الحركة التالية التي تحتوي على المعلمة wait : spin_for و spin_to_position.
Usage:
arm_motor.is_stopped()
حدود |
وصف |
|---|---|
لا تحتوي هذه الطريقة على أي معلمات. |
# Build Used: Competition Advanced 2.0
def main():
# Turn the Eye Sensor's light on while ArmMotor is moving
arm_motor.spin_for(REVERSE, 180, DEGREES, wait=False)
wait(0.1, SECONDS)
while True:
if arm_motor.is_stopped():
eye.set_light(OFF)
else:
eye.set_light(ON)
# Start threads — Do not delete
start_thread(main)
is_moving#
تُشير القيمة المنطقية is_moving . ويمكن استخدام هذه القيمة للتحكم في توقيت سلوكيات أخرى بناءً على حركة المحرك.
True— المحرك يدور.False— المحرك لا يدور.
تعمل هذه الطريقة جنبًا إلى جنب مع طرق الحركة التالية التي تحتوي على المعلمة wait : spin_for و spin_to_position.
Usage:
arm_motor.is_moving()
حدود |
وصف |
|---|---|
لا تحتوي هذه الطريقة على أي معلمات. |
# Build Used: Competition Advanced 2.0
def main():
# Turn the Eye Sensor's light on while ArmMotor is moving
arm_motor.spin_for(REVERSE, 180, DEGREES, wait=False)
wait(0.1, SECONDS)
while True:
if arm_motor.is_moving():
eye.set_light(ON)
else:
eye.set_light(OFF)
# Start threads — Do not delete
start_thread(main)