ത്രെഡുകൾ#
ആമുഖം#
ഒരേ പ്രോഗ്രാമിൽ ഒരേസമയം ഒന്നിലധികം ജോലികൾ പ്രവർത്തിപ്പിക്കാൻ ത്രെഡുകൾ VEX AIR ഡ്രോൺ കൺട്രോളറിനെ അനുവദിക്കുന്നു. അവ മൾട്ടിടാസ്കിംഗ് പ്രാപ്തമാക്കുന്നു, ഇത് VEX AIR ഡ്രോണിനെ ഒരേ സമയം സ്വതന്ത്ര പ്രവർത്തനങ്ങൾ നടത്താൻ അനുവദിക്കുന്നു.
കുറിപ്പ്: ഒരു ത്രെഡിനൊപ്പം ഉപയോഗിക്കുന്നതിന് നിങ്ങൾ ആദ്യം ഒരു ഫംഗ്ഷൻ നിർവചിക്കണം.
കൺസ്ട്രക്ടർ – പുതിയ ത്രെഡുകൾ സൃഷ്ടിക്കുകയും ആരംഭിക്കുകയും ചെയ്യുക.
Thread– പ്രധാന പ്രോഗ്രാമിനൊപ്പം സമാന്തരമായി നിർദ്ദിഷ്ട ഫംഗ്ഷൻ പ്രവർത്തിപ്പിക്കുന്ന ഒരു പുതിയ ത്രെഡ് ആരംഭിക്കുന്നു.
കൺസ്ട്രക്ടർ#
Thread#
Thread ഒരു ത്രെഡ് സൃഷ്ടിക്കുകയും ആരംഭിക്കുകയും ചെയ്യുന്നു. നിങ്ങൾ ഒരു ത്രെഡ് സൃഷ്ടിക്കുമ്പോൾ, അത് ആവശ്യമില്ലാത്തപ്പോൾ നിർത്താൻ നിങ്ങൾക്ക് അതിന് പേര് നൽകാം.
ഉപയോഗം:
my_thread = Thread(my_function)
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
|
ഓപ്ഷണൽ. പുതിയ ത്രെഡിന് ഒരു പേര്. |
|
മുമ്പ് നിർവചിച്ച ഒരു ഫംഗ്ഷന്റെ പേര്. |
Note: A function must always be defined before it is called.
# Only play sounds when the drone moves laterally
def moving_sounds():
while True:
if drone.is_move_active():
controller.sound.play(LOOPING)
while controller.sound.is_active():
wait(50, MSEC)
wait(5, MSEC)
# Run moving_sounds at the same time
moving_sounds_thread = Thread(moving_sounds)
# Fly the drone using the controller
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)