സന്ദേശ ലിങ്ക്#
ആമുഖം#
message_link ക്ലാസ് രണ്ട് EXP ബ്രെയിനുകളെ ഓപ്ഷണൽ ചെറിയ ഡാറ്റ ഉപയോഗിച്ച് ഷോർട്ട് സ്ട്രിംഗ് സന്ദേശങ്ങൾ അയച്ചുകൊണ്ട് ആശയവിനിമയം നടത്താൻ അനുവദിക്കുന്നു. ഇത് റോബോട്ട്-ടു-റോബോട്ട് ഏകോപനത്തിനായി രൂപകൽപ്പന ചെയ്തിരിക്കുന്നു - ദിനചര്യകൾ ആരംഭിക്കുക, സെൻസർ ഫലങ്ങൾ പങ്കിടുക, അല്ലെങ്കിൽ മറ്റൊരു റോബോട്ടിൽ പെരുമാറ്റങ്ങൾ ട്രിഗർ ചെയ്യുക എന്നിവ പോലെ.
send ന്റെ ഓരോ ഉപയോഗവും ലിങ്ക് ചെയ്ത EXP ബ്രെയിനിന്റെ ക്യൂവിലേക്ക് ഒരു സന്ദേശം ചേർക്കുന്നു, കൂടാതെ ക്യൂ ആദ്യം വായിക്കുകയും ആദ്യം പുറത്തുവരികയും ചെയ്യുന്നു (FIFO). മറ്റ് EXP ബ്രെയിൻ receive ഉപയോഗിക്കുന്നതിന് മുമ്പ് ഒന്നിലധികം സന്ദേശങ്ങൾ അയച്ചാൽ, അവ സൂക്ഷിച്ച് അവ അയച്ച ക്രമത്തിൽ ഓരോന്നായി തിരികെ നൽകും. സന്ദേശങ്ങൾക്ക് ക്യൂ ചെയ്യാൻ കഴിയുന്നതിനാൽ, ഓരോ ലൂപ്പിലും ഒരേ സ്റ്റാറ്റസ് ആവർത്തിച്ച് അയയ്ക്കുന്നത് ബാക്ക്ലോഗ് സൃഷ്ടിച്ചേക്കാം; സമയ-നിർണ്ണായക യുക്തിക്ക്, മൂല്യങ്ങൾ മാറുമ്പോൾ മാത്രം അയയ്ക്കുക.
പ്രധാനം: രണ്ട് റോബോട്ടുകളും ഒരേ സമയം message_link ഉപയോഗിക്കുന്ന പ്രോജക്ടുകൾ പ്രവർത്തിപ്പിക്കുന്നുണ്ടാകണം, അല്ലെങ്കിൽ സന്ദേശങ്ങളൊന്നും അയയ്ക്കുകയോ സ്വീകരിക്കുകയോ ചെയ്യില്ല.
ക്ലാസ് കൺസ്ട്രക്ടറുകൾ#
message_link(
int32_t index,
const char *name,
linkType type,
bool isWired = false );
ക്ലാസ് ഡിസ്ട്രക്റ്റർ#
message_link ഒബ്ജക്റ്റ് നശിപ്പിക്കുകയും അനുബന്ധ ഉറവിടങ്ങൾ പുറത്തുവിടുകയും ചെയ്യുന്നു.
virtual ~message_link();
പാരാമീറ്ററുകൾ#
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
V5 റേഡിയോ അല്ലെങ്കിൽ സ്മാർട്ട് കേബിൾ ബന്ധിപ്പിച്ചിരിക്കുന്ന സ്മാർട്ട് പോർട്ട്, |
|
|
സന്ദേശ ലിങ്കിന്റെ പേര്. |
|
|
ലിങ്കിന്റെ തരം, ഒന്നുകിൽ
|
|
|
message_link ഒബ്ജക്റ്റ് വയർഡ് ആണോ എന്ന്.
|
ഉദാഹരണം#
റോബോട്ട് 1 നുള്ള കോഡ്
// Create a wireless link in Port 1 message_link link = message_link( PORT1, // index "VEXRoboticsLink123456789", // name linkType::manager, // type true); // isWiredറോബോട്ട് 2 നുള്ള കോഡ്
// Create a wireless link in Port 1 message_link link = message_link( PORT1, // index "VEXRoboticsLink123456789", // name linkType::worker, // type true); // isWired
അംഗ പ്രവർത്തനങ്ങൾ#
message_link ക്ലാസ്സിൽ ഇനിപ്പറയുന്ന അംഗ ഫംഗ്ഷനുകൾ ഉൾപ്പെടുന്നു:
isLinked— ഈ ബ്രെയിൻ അതിന്റെ ജോടിയാക്കിയ ബ്രെയിനുമായി സജീവമായി ബന്ധിപ്പിച്ചിട്ടുണ്ടോ എന്ന് നൽകുന്നു.send— ജോടിയാക്കിയ തലച്ചോറിലേക്ക് ഒരു സന്ദേശം അയയ്ക്കുന്നു.receive— അടുത്ത ഇൻകമിംഗ് സന്ദേശത്തിനായി കാത്തിരുന്ന് തിരികെ നൽകുന്നു.received— ഒരു പുതിയ സന്ദേശം ലഭിക്കുമ്പോഴെല്ലാം വിളിക്കേണ്ട ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുന്നു.
ഏതെങ്കിലും message_link അംഗ ഫംഗ്ഷനുകൾ വിളിക്കുന്നതിന് മുമ്പ്, താഴെ കാണിച്ചിരിക്കുന്നതുപോലെ ഒരു message_link ഉദാഹരണം സൃഷ്ടിക്കണം:
റോബോട്ട് 1 നുള്ള കോഡ്
// Create a wireless link in Port 1 message_link link = message_link( PORT1, // index "VEXRoboticsLink123456789", // name linkType::manager, // type true); // isWiredറോബോട്ട് 2 നുള്ള കോഡ്
// Create a wireless link in Port 1 message_link link = message_link( PORT1, // index "VEXRoboticsLink123456789", // name linkType::worker, // type true); // isWired
isLinked#
ഒരു MessageLink-ലെ EXP ബ്രെയിനുകൾ പരസ്പരം ജോടിയാക്കപ്പെട്ടിട്ടുണ്ടോ എന്ന് isLinked രീതി നൽകുന്നു.
bool isLinked();
ഈ ഫംഗ്ഷന് ഒരു പാരാമീറ്ററുകളും ഇല്ല.
Return Valuesഈ ഫംഗ്ഷൻ ഒരു ബൂളിയൻ മൂല്യം നൽകുന്നു.
true– രണ്ട് EXP തലച്ചോറുകളും ഈ ലിങ്കിൽ ജോടിയാക്കപ്പെടുകയും ആശയവിനിമയം നടത്തുകയും ചെയ്യുന്നു.false– ഈ ലിങ്കിൽ രണ്ട് EXP ബ്രെയിനുകളും ജോടിയാക്കിയിട്ടില്ല.
കൂടുതൽ കോഡുകൾ പ്രവർത്തിപ്പിക്കുന്നതിന് മുമ്പ് ഒരു പ്രോജക്റ്റിന്റെ തുടക്കത്തിൽ EXP ബ്രെയിനുകൾ ബന്ധിപ്പിച്ചിട്ടുണ്ടെന്ന് ഉറപ്പാക്കുന്നത് എപ്പോഴും നല്ല രീതിയാണ്.
Examplesറോബോട്ട് 1 നുള്ള കോഡ്
// Tell the other robot when the screen is being pressed // Create the link message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()){ 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(0.05, seconds); }റോബോട്ട് 2 നുള്ള കോഡ്
// Display if the other robot's screen is being pressed // Create the link message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()){ wait(0.1, seconds); } // Continuously check if Robot 1 has sent "pressed" while (true){ Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); char msg[32] = {0}; // buffer for incoming message int32_t n = link.receive(msg, sizeof(msg), 100); // wait up to 100ms if (n > 0 && strcmp(msg, "pressed") == 0) { Brain.Screen.newLine(); Brain.Screen.print("Manager is being pressed!"); } wait(0.05, seconds); }
send#
ലിങ്ക് കണക്ഷനിലൂടെ ഒരു സന്ദേശം അയയ്ക്കുന്നു.
Available FunctionsParameters1 — ഒരു സന്ദേശ സ്ട്രിംഗ് അയയ്ക്കുന്നു.
int32_t send( const char *message );2 —
doubleഉള്ള ഒരു സന്ദേശ സ്ട്രിംഗ് അയയ്ക്കുന്നു.int32_t send( const char *message, double value );3 —
int32_tഉംdoubleഉള്ള ഒരു സന്ദേശ സ്ട്രിംഗ് അയയ്ക്കുന്നു.int32_t send( const char *message, int32_t index, double value );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റേ EXP ബ്രെയിനിലേക്ക് അയയ്ക്കേണ്ട സന്ദേശം. |
|
|
ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിനിലേക്ക് അയയ്ക്കേണ്ട ഒരു പൂർണ്ണസംഖ്യ. |
|
|
ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിനിലേക്ക് അയയ്ക്കേണ്ട ഒരു ഇരട്ടി. ഇരട്ടികൾ 4 ദശാംശ സ്ഥാനങ്ങളിലേക്ക് ഫോർമാറ്റ് ചെയ്തിരിക്കുന്നു; കുറച്ച് ദശാംശങ്ങൾ നൽകിയിട്ടുണ്ടെങ്കിൽ, 4 കാണിക്കുന്നത് വരെ പിന്നിലുള്ള പൂജ്യങ്ങൾ ചേർക്കും. |
ഈ ഫംഗ്ഷൻ ഒരു മൂല്യങ്ങളും തിരികെ നൽകുന്നില്ല.
Notesmessage ലിങ്ക് ചെയ്ത EXP ബ്രെയിനിന് അതേ സന്ദേശം ലഭിക്കും.
value (നൽകിയിട്ടുണ്ടെങ്കിൽ index ) ഉൾപ്പെടുത്തിയാൽ, സ്വീകരിക്കുന്ന തലച്ചോറിന് ഈ ക്രമത്തിൽ എല്ലാ ഫീൽഡുകളും സംയോജിപ്പിക്കുന്ന ഒരൊറ്റ എൻകോഡ് ചെയ്ത സന്ദേശം ലഭിക്കും: .message_index_value
link.send(“string”, 1, 2.55) .string_1_2.5500.
റോബോട്ട് 1 നുള്ള കോഡ്
// Tell the other robot when the screen is being pressed // Create the link message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()){ 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(0.05, seconds); }റോബോട്ട് 2 നുള്ള കോഡ്
// Display if the other robot's screen is being pressed // Create the link message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()){ wait(0.1, seconds); } // Continuously check if Robot 1 has sent "pressed" while (true){ Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); char msg[32] = {0}; // buffer for incoming message int32_t n = link.receive(msg, sizeof(msg), 100); // wait up to 100ms if (n > 0 && strcmp(msg, "pressed") == 0) { Brain.Screen.newLine(); Brain.Screen.print("Manager is being pressed!"); } wait(0.05, seconds); }
receive#
ലിങ്ക് കണക്ഷനിൽ നിന്ന് ഒരു സന്ദേശം സ്വീകരിക്കുന്നു.
Available Functionsint32_t receive(
char *buffer,
int32_t length,
int32_t timeoutMs = 500 );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
ലഭിച്ച സന്ദേശം സൂക്ഷിക്കുന്നതിനുള്ള ബഫർ. |
|
|
ബഫറിന്റെ നീളം. |
|
|
ക്യൂ ശൂന്യമാണെങ്കിൽ മാത്രം |
ഈ ഫംഗ്ഷൻ ലഭിച്ച ബൈറ്റുകളുടെ എണ്ണം തിരികെ നൽകുന്നു.
Notesreceiveലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിനിൽ നിന്നുള്ള അടുത്ത ക്യൂ ചെയ്ത സന്ദേശം തിരികെ നൽകുന്നു. സന്ദേശങ്ങൾ FIFO ക്രമത്തിലാണ് വായിക്കുന്നത് (പഴയതും വായിക്കാത്തതും ആദ്യം).receiveവിളിക്കുമ്പോൾ ക്യൂ ശൂന്യമാണെങ്കിൽ, ഒരു പുതിയ സന്ദേശത്തിനായി നിർദ്ദിഷ്ടreceiveവരെ അത് കാത്തിരിക്കും. ആ വിൻഡോയിൽ ഒരു സന്ദേശവും വന്നില്ലെങ്കിൽ,receive0തിരികെ നൽകുന്നു, തുടർന്ന് അയച്ച ഏതൊരു സന്ദേശവും അടുത്ത തവണtimeoutഉപയോഗിക്കുമ്പോൾ വായിക്കേണ്ട ക്യൂവിൽ തന്നെ തുടരും.ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിൻ ഒരു
stringമാത്രമേ അയച്ചിട്ടുള്ളൂവെങ്കിൽ,receiveആ കൃത്യമായ സ്ട്രിംഗ് തിരികെ നൽകുന്നു.ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിൻ ഒരു പൂർണ്ണസംഖ്യയും/അല്ലെങ്കിൽ ഫ്ലോട്ടും അയച്ചാൽ,
receiveഎല്ലാ ഫീൽഡുകളും ഈ ക്രമത്തിൽ സംയോജിപ്പിക്കുന്ന ഒരു എൻകോഡ് ചെയ്ത സ്ട്രിംഗ് തിരികെ നൽകുന്നു:.string_integer_floatഉദാഹരണത്തിന്, ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിൻ
link.send(“string”, 1, 2.55)ഉപയോഗിക്കുന്നുവെങ്കിൽ,link.receive()ഉപയോഗിക്കുന്നത്.string_1_2.5500പോലുള്ള ഒരു എൻകോഡ് ചെയ്ത സ്ട്രിംഗ് തിരികെ നൽകുന്നു. സന്ദേശ നാമം, പൂർണ്ണസംഖ്യ, ഫ്ലോട്ട് മൂല്യങ്ങൾ എന്നിവ എക്സ്ട്രാക്റ്റ് ചെയ്യുന്നതിന് നിങ്ങൾക്ക് ഈ എൻകോഡ് ചെയ്ത സ്ട്രിംഗ് വിഭജിക്കാം (ചുവടെയുള്ള ഉദാഹരണങ്ങൾ കാണുക).മാനുവൽ സ്പ്ലിറ്റിംഗ്/പാഴ്സിംഗ് ഒഴിവാക്കാൻ നിങ്ങൾ ആഗ്രഹിക്കുന്നുവെങ്കിൽ, ഒരു പ്രത്യേക സന്ദേശ നാമത്തിനായി ഒരു ഹാൻഡ്ലറെ രജിസ്റ്റർ ചെയ്യുന്നതിന്
receivedഉപയോഗിക്കുക; അയച്ച മൂല്യങ്ങൾ ആർഗ്യുമെന്റുകളായി ഹാൻഡ്ലറിന് ലഭിക്കും.
link.send(“string”, 1, 2.55) .string_1_2.5500.
റോബോട്ട് 1 നുള്ള കോഡ്
// Tell the other robot when the screen is being pressed // Create the link message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()){ 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(0.05, seconds); }റോബോട്ട് 2 നുള്ള കോഡ്
// Display if the other robot's screen is being pressed // Create the link message_link link = message_link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()){ wait(0.1, seconds); } // Continuously check if Robot 1 has sent "pressed" while (true){ Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); char msg[32] = {0}; // buffer for incoming message int32_t n = link.receive(msg, sizeof(msg), 100); // wait up to 100ms if (n > 0 && strcmp(msg, "pressed") == 0) { Brain.Screen.newLine(); Brain.Screen.print("Manager is being pressed!"); } wait(0.05, seconds); }
received#
EXP ബ്രെയിനിന് അയച്ച സന്ദേശം ലഭിക്കുമ്പോഴെല്ലാം വിളിക്കേണ്ട ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുന്നു.
Available FunctionsParameters1 എല്ലാ ലഭിച്ച സന്ദേശങ്ങൾക്കും ഒരു കോൾബാക്ക് രജിസ്റ്റർ ചെയ്യുന്നു (സന്ദേശം + മൂല്യം).
void received( void (* callback)(const char *, const char *, double) );2 എല്ലാ ലഭിച്ച സന്ദേശങ്ങൾക്കും (സന്ദേശം + സൂചിക + മൂല്യം) ഒരു കോൾബാക്ക് രജിസ്റ്റർ ചെയ്യുന്നു.
void received( void (* callback)(const char *, const char *, int32_t, double) );3 ഒരു പ്രത്യേക സന്ദേശത്തിനായി (സന്ദേശം + മൂല്യം) ഒരു കോൾബാക്ക് രജിസ്റ്റർ ചെയ്യുന്നു.
void received( const char *message, void (* callback)(const char *, const char *, double) );4 ഒരു പ്രത്യേക സന്ദേശത്തിനായി (സന്ദേശം + സൂചിക + മൂല്യം) ഒരു കോൾബാക്ക് രജിസ്റ്റർ ചെയ്യുന്നു.
void received( const char *message, void (* callback)(const char *, const char *, int32_t, double) );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
കേൾക്കേണ്ട സന്ദേശത്തിന്റെ പേര്. ഒഴിവാക്കിയാൽ, ലഭിച്ച എല്ലാ സന്ദേശങ്ങൾക്കും കോൾബാക്ക് പ്രവർത്തിക്കും. |
|
ഫംഗ്ഷൻ പോയിന്റർ |
ഒരു സന്ദേശം ലഭിക്കുമ്പോൾ നടപ്പിലാക്കുന്ന ഒരു ഫംഗ്ഷൻ. |
ഈ ഫംഗ്ഷൻ ഒരു മൂല്യങ്ങളും തിരികെ നൽകുന്നില്ല.
Callback Signature1 അയച്ചയാളുടെ പേര്, സന്ദേശത്തിന്റെ പേര്, മൂല്യം എന്നിവ സ്വീകരിക്കുന്നു.
void callback(const char *, const char *, double)2 അയച്ചയാളുടെ പേര്, സന്ദേശത്തിന്റെ പേര്, സൂചിക, മൂല്യം എന്നിവ സ്വീകരിക്കുന്നു.
void callback(const char *, const char *, int32_t, double)
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|
1st |
അയച്ചയാളുടെ ലിങ്ക് പേര്. |
2nd |
സന്ദേശ നാമം ലഭിച്ചു. |
|
സന്ദേശവുമായി ബന്ധപ്പെട്ട സൂചിക. |
|
സന്ദേശവുമായി ബന്ധപ്പെട്ട മൂല്യം. |
റോബോട്ട് 1 നുള്ള കോഡ്
// Send whether screen is pressed on left or right void screen_pressed() { if (Brain.Screen.xPosition() < 240) { link.send("left"); } else { link.send("right"); } } int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Create the link message_link link(PORT1, "LeftRightLink", linkType::manager, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()) { wait(0.1, seconds); } Brain.Screen.print("Robot 1 - Manager"); Brain.Screen.pressed(screen_pressed); while (true) { wait(10, msec); } }റോബോട്ട് 2 നുള്ള കോഡ്
// Create variable to track where screen is pressed int lastPress = 0; // Update the variable whenever a new message is received void message_received(const char* message, const char* linkname, double timestamp) { if (strcmp(message, "left") == 0) lastPress = 1; if (strcmp(message, "right") == 0) lastPress = 2; } int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Create the link message_link link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()) { wait(0.1, seconds); } link.received(message_received); // Display if Robot 1's screen was pressed on the left or right while (true) { Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); if (lastPress == 1) { Brain.Screen.print("Manager pressed LEFT"); } else if (lastPress == 2) { Brain.Screen.print("Manager pressed RIGHT"); } else { Brain.Screen.print("Waiting..."); } wait(0.1, seconds); } }