സന്ദേശ ലിങ്ക്#
ആമുഖം#
മെസേജ് ലിങ്ക് രണ്ട് EXP ബ്രെയിനുകളെ ഓപ്ഷണൽ ചെറിയ ഡാറ്റ ഉപയോഗിച്ച് ഷോർട്ട് സ്ട്രിംഗ് സന്ദേശങ്ങൾ അയച്ചുകൊണ്ട് ആശയവിനിമയം നടത്താൻ അനുവദിക്കുന്നു. റോബോട്ട്-ടു-റോബോട്ട് ഏകോപനത്തിനായി ഇത് രൂപകൽപ്പന ചെയ്തിരിക്കുന്നു - ദിനചര്യകൾ ആരംഭിക്കുക, സെൻസർ ഫലങ്ങൾ പങ്കിടുക, അല്ലെങ്കിൽ മറ്റൊരു റോബോട്ടിൽ പെരുമാറ്റങ്ങൾ ട്രിഗർ ചെയ്യുക എന്നിവ പോലെ.
send ന്റെ ഓരോ ഉപയോഗവും ലിങ്ക് ചെയ്ത EXP ബ്രെയിനിന്റെ ക്യൂവിലേക്ക് ഒരു സന്ദേശം ചേർക്കുന്നു, കൂടാതെ ക്യൂ ആദ്യം വായിക്കുകയും ആദ്യം പുറത്തുവരികയും ചെയ്യുന്നു (FIFO). മറ്റ് EXP ബ്രെയിൻ receive ഉപയോഗിക്കുന്നതിന് മുമ്പ് ഒന്നിലധികം സന്ദേശങ്ങൾ അയച്ചാൽ, അവ സൂക്ഷിച്ച് അവ അയച്ച ക്രമത്തിൽ ഓരോന്നായി തിരികെ നൽകും. സന്ദേശങ്ങൾക്ക് ക്യൂ ചെയ്യാൻ കഴിയുന്നതിനാൽ, ഓരോ ലൂപ്പിലും ഒരേ സ്റ്റാറ്റസ് ആവർത്തിച്ച് അയയ്ക്കുന്നത് ബാക്ക്ലോഗ് സൃഷ്ടിച്ചേക്കാം; സമയ-നിർണ്ണായക യുക്തിക്ക്, മൂല്യങ്ങൾ മാറുമ്പോൾ മാത്രം അയയ്ക്കുക.
പ്രധാനം: രണ്ട് റോബോട്ടുകളും ഒരേ സമയം MessageLink ഉപയോഗിക്കുന്ന പ്രോജക്ടുകൾ പ്രവർത്തിപ്പിക്കുന്നുണ്ടാകണം, അല്ലെങ്കിൽ സന്ദേശങ്ങളൊന്നും അയയ്ക്കുകയോ സ്വീകരിക്കുകയോ ചെയ്യില്ല.
ഈ പേജിൽ ഉദാഹരണ MessageLink നാമമായി link ഉപയോഗിക്കുന്നു. ആവശ്യാനുസരണം നിങ്ങളുടെ സ്വന്തം കോൺഫിഗർ ചെയ്ത പേര് ഉപയോഗിച്ച് അത് മാറ്റിസ്ഥാപിക്കുക.
ലഭ്യമായ രീതികളുടെ ഒരു ലിസ്റ്റ് താഴെ കൊടുക്കുന്നു:
is_linked– ഈ ബ്രെയിൻ അതിന്റെ ജോടിയാക്കിയ ബ്രെയിനുമായി സജീവമായി ബന്ധിപ്പിച്ചിട്ടുണ്ടോ എന്ന് നൽകുന്നു.send– ജോടിയാക്കിയ തലച്ചോറിലേക്ക് ഒരു സന്ദേശം അയയ്ക്കുന്നു.receiveലഭിക്കുന്നു – അടുത്ത ഇൻകമിംഗ് സന്ദേശത്തിനായി കാത്തിരുന്ന് തിരികെ നൽകുന്നു.received– ഒരു പുതിയ സന്ദേശം ലഭിക്കുമ്പോഴെല്ലാം വിളിക്കേണ്ട ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുന്നു.
ഒരു ലിങ്ക് സൃഷ്ടിക്കുക#
രണ്ട് EXP ബ്രെയിനുകളിലും ഒരു മെസേജ് ലിങ്ക് സൃഷ്ടിക്കുക, അങ്ങനെ അവയ്ക്കിടയിൽ ഒരു ആശയവിനിമയ ചാനൽ സ്ഥാപിക്കുക - V5 റോബോട്ട് റേഡിയോകൾ ഉപയോഗിച്ച് വയർലെസ് ആയിട്ടോ അല്ലെങ്കിൽ ഒരു വയർഡ് സ്മാർട്ട് കേബിൾ വഴിയോ - അങ്ങനെ റോബോട്ടുകൾക്ക് പരസ്പരം സന്ദേശങ്ങൾ അയയ്ക്കാൻ കഴിയും.
MessageLink(smartport, name, linktype, wired)
പാരാമീറ്റർ |
വിവരണം |
|---|---|
|
ഈ ലിങ്കിനായി ഉപയോഗിക്കുന്ന സ്മാർട്ട് പോർട്ട് - V5 റോബോട്ട് റേഡിയോ ബന്ധിപ്പിച്ചിരിക്കുന്ന പോർട്ട് (വയർലെസ്) അല്ലെങ്കിൽ സ്മാർട്ട് കേബിൾ പ്ലഗ് ചെയ്തിരിക്കുന്ന (വയർഡ്). |
|
ഈ ലിങ്ക് ഒരു സ്ട്രിംഗായി നൽകേണ്ട അദ്വിതീയ നാമം. |
|
ഈ ലിങ്ക് ജോഡിക്ക് ഈ ബ്രെയിൻ ഉപയോഗിക്കുന്ന റോൾ. ഓരോ ജോഡിയിലും ഒരു മാനേജർ ഉം ഒരു വർക്കർ ഉം ഉണ്ടായിരിക്കണം:
|
|
ഓപ്ഷണൽ. ഈ ലിങ്ക് വയർ ആണോ വയർലെസ് ആണോ എന്നത് പരിഗണിക്കാതെ തന്നെ:
|
റോബോട്ട് 1 നുള്ള കോഡ്
""" Create a wireless link in Port 1 name: VEXRoboticsLink123456789 linktype: Manager """ link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER)റോബോട്ട് 2 നുള്ള കോഡ്
""" Create a wireless link in Port 1 name: VEXRoboticsLink123456789 linktype: Worker """ link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER)
ലഭ്യമായ രീതികൾ#
നിങ്ങളുടെ മെസേജ് ലിങ്ക് സജ്ജീകരിച്ച് ബ്രെയിൻസ് ലിങ്ക് ചെയ്തുകഴിഞ്ഞാൽ, സന്ദേശങ്ങൾ അയയ്ക്കാനും സ്വീകരിക്കാനും അവയോട് പ്രതികരിക്കാനും താഴെയുള്ള രീതികൾ നിങ്ങൾക്ക് ഉപയോഗിക്കാം.
is_linked#
is_linked രീതി ഒരു MessageLink-ലെ EXP ബ്രെയിനുകൾ പരസ്പരം ജോടിയാക്കുന്നുണ്ടോ എന്ന് നൽകുന്നു.
True– രണ്ട് EXP തലച്ചോറുകളും ഈ ലിങ്കിൽ ജോടിയാക്കപ്പെടുകയും ആശയവിനിമയം നടത്തുകയും ചെയ്യുന്നു.False– ഈ ലിങ്കിൽ രണ്ട് EXP ബ്രെയിനുകളും ജോടിയാക്കിയിട്ടില്ല.
കുറിപ്പ്: കൂടുതൽ കോഡ് പ്രവർത്തിപ്പിക്കുന്നതിന് മുമ്പ് ഒരു പ്രോജക്റ്റിന്റെ തുടക്കത്തിൽ EXP ബ്രെയിനുകൾ ലിങ്ക് ചെയ്തിട്ടുണ്ടെന്ന് ഉറപ്പാക്കുന്നത് എപ്പോഴും നല്ല രീതിയാണ്.
Usage:
link.is_linked()
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
ഈ രീതിക്ക് പാരാമീറ്ററുകൾ ഇല്ല. |
റോബോട്ട് 1 നുള്ള കോഡ്
# Tell the other robot when the screen is being pressed # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") # Continuously send if the screen is being pressed while True: if brain.screen.pressing(): link.send("pressed") else: link.send("released") wait(50, MSEC)റോബോട്ട് 2 നുള്ള കോഡ്
# Display if the other robot's screen is being pressed # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) # Continuously check if Robot 1 has sent "pressed" while True: brain.screen.clear_screen() brain.screen.set_cursor(1, 1) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() if link.receive() == "pressed": brain.screen.new_line() brain.screen.print("Manager is being pressed!") wait(50, MSEC)
send#
send മറ്റൊരു ലിങ്ക് ചെയ്ത EXP ബ്രെയിനിലേക്ക് ഒരു സ്ട്രിംഗ് കൂടാതെ/അല്ലെങ്കിൽ ഒരു പൂർണ്ണസംഖ്യ കൂടാതെ/അല്ലെങ്കിൽ ഫ്ലോട്ട് അയയ്ക്കുന്നു.
Usage:
send(string, integer, float)
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
|
ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റ് EXP ബ്രെയിനിലേക്ക് അയയ്ക്കേണ്ട സ്ട്രിംഗ്. |
|
ഓപ്ഷണൽ. ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിനിലേക്ക് അയയ്ക്കേണ്ട ഒരു പൂർണ്ണസംഖ്യ. |
|
ഓപ്ഷണൽ. ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിനിലേക്ക് അയയ്ക്കേണ്ട ഒരു ഫ്ലോട്ട്. ഫ്ലോട്ടുകൾ 4 ദശാംശ സ്ഥാനങ്ങളിലേക്ക് ഫോർമാറ്റ് ചെയ്തിരിക്കുന്നു; കുറച്ച് ദശാംശങ്ങൾ നൽകിയിട്ടുണ്ടെങ്കിൽ, 4 കാണിക്കുന്നത് വരെ പിന്നിലുള്ള പൂജ്യങ്ങൾ ചേർക്കും. |
string മാത്രം അയച്ചാൽ, ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റ് EXP ബ്രെയിനിന് ആ കൃത്യമായ സ്ട്രിംഗ് ലഭിക്കും.
integer ഉം/അല്ലെങ്കിൽ float ഉം ഉൾപ്പെടുത്തിയാൽ, സ്വീകരിക്കുന്ന തലച്ചോറിന് എല്ലാ ഫീൽഡുകളും ഈ ക്രമത്തിൽ സംയോജിപ്പിക്കുന്ന ഒരു എൻകോഡ് ചെയ്ത സ്ട്രിംഗ് ലഭിക്കും: .string_integer_float
ഉദാഹരണം: link.send(“string”, 1, 2.55) .string_1_2.5500.
റോബോട്ട് 1 നുള്ള കോഡ്
# Tell the other robot when the screen is being pressed # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") # Continuously send if the screen is being pressed while True: if brain.screen.pressing(): link.send("pressed") else: link.send("released") wait(50, MSEC)റോബോട്ട് 2 നുള്ള കോഡ്
# Display if the other robot's screen is being pressed # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) # Continuously check if Robot 1 has sent "pressed" while True: brain.screen.clear_screen() brain.screen.set_cursor(1, 1) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() if link.receive() == "pressed": brain.screen.new_line() brain.screen.print("Manager is being pressed!") wait(50, MSEC)
റോബോട്ട് 1 നുള്ള കോഡ്
# Tell the other robot where the screen was pressed # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") brain.screen.next_row() brain.screen.print("Tap to send circles") # Send the coordinates whenever the screen is pressed while True: if brain.screen.pressing(): x = brain.screen.x_position() y = brain.screen.y_position() link.send("touch", x, y) wait(10, MSEC)റോബോട്ട് 2 നുള്ള കോഡ്
# Draw a circle where Robot 1's screen was pressed # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 2 - Worker") while True: # Get the full encoded string circle_coordinates = link.receive(200) if circle_coordinates: # Split the encoded string by _ parts = circle_coordinates.split("_") if len(parts) == 3: # Convert the coordinates back into numbers x = float(parts[1]) y = float(parts[2]) brain.screen.set_fill_color(Color.WHITE) brain.screen.draw_circle(x, y, 20) wait(10, MSEC)
receive#
receive ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിനിൽ നിന്നുള്ള അടുത്ത ക്യൂ ചെയ്ത സന്ദേശം തിരികെ നൽകുന്നു. സന്ദേശങ്ങൾ FIFO ക്രമത്തിലാണ് വായിക്കുന്നത് (പഴയതും വായിക്കാത്തതും ആദ്യം). receive വിളിക്കുമ്പോൾ ക്യൂ ശൂന്യമാണെങ്കിൽ, ഒരു പുതിയ സന്ദേശത്തിനായി നിർദ്ദിഷ്ട receive വരെ അത് കാത്തിരിക്കും. ആ വിൻഡോയിൽ ഒരു സന്ദേശവും വന്നില്ലെങ്കിൽ, receive timeoutനൽകുന്നു, തുടർന്ന് അയച്ച ഏതൊരു സന്ദേശവും അടുത്ത തവണ None ഉപയോഗിക്കുമ്പോൾ വായിക്കേണ്ട ക്യൂവിൽ തന്നെ തുടരും.
ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിൻ ഒരു stringമാത്രമേ അയച്ചിട്ടുള്ളൂവെങ്കിൽ, receive ആ കൃത്യമായ സ്ട്രിംഗ് തിരികെ നൽകുന്നു.
ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിൻ ഒരു പൂർണ്ണസംഖ്യയും/അല്ലെങ്കിൽ ഫ്ലോട്ടും അയച്ചാൽ, receive എല്ലാ ഫീൽഡുകളും ഈ ക്രമത്തിൽ സംയോജിപ്പിക്കുന്ന ഒരു എൻകോഡ് ചെയ്ത സ്ട്രിംഗ് തിരികെ നൽകുന്നു: .string_integer_float
ഉദാഹരണത്തിന്, ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിൻ link.send(“string”, 1, 2.55)ഉപയോഗിക്കുന്നുവെങ്കിൽ, link.receive() ഉപയോഗിക്കുന്നത് .string_1_2.5500പോലുള്ള ഒരു എൻകോഡ് ചെയ്ത സ്ട്രിംഗ് തിരികെ നൽകുന്നു. സന്ദേശ നാമം, പൂർണ്ണസംഖ്യ, ഫ്ലോട്ട് മൂല്യങ്ങൾ എന്നിവ എക്സ്ട്രാക്റ്റ് ചെയ്യുന്നതിന് നിങ്ങൾക്ക് ഈ എൻകോഡ് ചെയ്ത സ്ട്രിംഗ് വിഭജിക്കാം (ചുവടെയുള്ള ഉദാഹരണങ്ങൾ കാണുക).
മാനുവൽ സ്പ്ലിറ്റിംഗ്/പാഴ്സിംഗ് ഒഴിവാക്കാൻ നിങ്ങൾ ആഗ്രഹിക്കുന്നുവെങ്കിൽ, ഒരു പ്രത്യേക സന്ദേശ നാമത്തിനായി ഒരു ഹാൻഡ്ലറെ രജിസ്റ്റർ ചെയ്യുന്നതിന് received ഉപയോഗിക്കുക; അയച്ച മൂല്യങ്ങൾ ആർഗ്യുമെന്റുകളായി ഹാൻഡ്ലറിന് ലഭിക്കും.
Usage:
receive(timeout)
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
|
ഓപ്ഷണൽ. ക്യൂ ശൂന്യമാണെങ്കിൽ മാത്രം |
റോബോട്ട് 1 നുള്ള കോഡ്
# Tell the other robot when the screen is being pressed # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") # Continuously send if the screen is being pressed while True: if brain.screen.pressing(): link.send("pressed") else: link.send("released") wait(50, MSEC)റോബോട്ട് 2 നുള്ള കോഡ്
# Display if the other robot's screen is being pressed # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) # Continuously check if Robot 1 has sent "pressed" while True: brain.screen.clear_screen() brain.screen.set_cursor(1, 1) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() if link.receive() == "pressed": brain.screen.new_line() brain.screen.print("Manager is being pressed!") wait(50, MSEC)
റോബോട്ട് 1 നുള്ള കോഡ്
# Send a math problem for the other Brain to solve # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") """ Change whether to "add" or "subtract", then what numbers to use in the operation. """ link.send("add", 7, 2.5)റോബോട്ട് 2 നുള്ള കോഡ്
# Solve the math problem that the other Brain sends # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() math_problem = link.receive() if math_problem: # Split the encoded string by _ parts = math_problem.split("_") if len(parts) == 3: # Remove the . from the beginning of the string operator = "".join([c for c in parts[0] if c.isalpha()]) # Separate out the numbers for the operation a = int(parts[1]) b = float(parts[2]) # Use what operator was sent if operator == "add": result = a + b elif operator == "subtract": result = a - b # If neither add or subtract is sent, do nothing else: pass brain.screen.print("Result = ", result)
received#
received EXP ബ്രെയിൻ അയച്ച സന്ദേശം സ്വീകരിക്കുമ്പോഴെല്ലാം വിളിക്കേണ്ട ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുന്നു.
Usage:
link.received(message, arg)
പാരാമീറ്ററുകൾ |
വിവരണം |
|---|---|
|
പൊരുത്തപ്പെടേണ്ട സന്ദേശ നാമം (സ്ട്രിംഗ്). ലഭിച്ച സന്ദേശത്തിന്റെ പേര് ഈ മൂല്യവുമായി പൊരുത്തപ്പെടുമ്പോൾ, |
|
A previously defined function that runs when the EXP Brain receives a message matching |
received കോൾബാക്കുകൾ വിളിക്കുന്നു:
കോൾബാക്ക് ഒപ്പ്:
callback(message, linkname, index, value)
വാദം |
വിവരണം |
|---|---|
|
ലഭിച്ച സന്ദേശത്തിന്റെ പേര് (ഉദാഹരണത്തിന്, |
|
സന്ദേശം ലഭിച്ച ലിങ്ക് നാമം. |
|
സന്ദേശത്തോടൊപ്പം അയച്ച പൂർണ്ണസംഖ്യ മൂല്യം (നൽകിയിട്ടുണ്ടെങ്കിൽ). |
|
സന്ദേശത്തോടൊപ്പം അയച്ച ഫ്ലോട്ട് മൂല്യം (നൽകിയിട്ടുണ്ടെങ്കിൽ). |
റോബോട്ട് 1 നുള്ള കോഡ്
# Send a math problem for the other Brain to solve # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.MANAGER) # Do not run code UNTIL the Brains are linked while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 1 - Manager") """ Change whether to "add" or "subtract", then what numbers to use in the operation. """ link.send("add", 7, 2.5)റോബോട്ട് 2 നുള്ള കോഡ്
# Solve the math problem that the other Brain sends # Create the link link = MessageLink(Ports.PORT1, "VEXRoboticsLink123456789", VexlinkType.WORKER) while not link.is_linked(): wait(0.1, SECONDS) brain.screen.print("Robot 2 - Worker") brain.screen.next_row() # add if "add" is received def add_cmd(message, linkname, a, b): result = a + b brain.screen.print("Result = ", result) # subtract if ""subtract" is received def subtract_cmd(message, linkname, a, b): result = a - b brain.screen.print("Result = ", result) # Create event handlers for "add" and "subtract" link.received("add", add_cmd) link.received("subtract", subtract_cmd)