സീരിയൽ ലിങ്ക്#
ആമുഖം#
serial_link ക്ലാസ് റോബോട്ടുകൾക്കിടയിൽ റോ ബൈറ്റുകളുടെ ഒരു സ്ട്രീം അയയ്ക്കാൻ അനുവദിക്കുന്നു. റോബോട്ട്-ടു-റോബോട്ട് ആശയവിനിമയത്തിനായി ഇത് രൂപകൽപ്പന ചെയ്തിരിക്കുന്നു, അവിടെ ട്രാൻസ്മിറ്റിംഗ് ചെയ്യുന്നതും സ്വീകരിക്കുന്നതുമായ റോബോട്ട് ഡാറ്റ സ്ട്രീമിന്റെ ഉള്ളടക്കം മനസ്സിലാക്കുന്നു.
send ന്റെ ഓരോ ഉപയോഗവും ലിങ്ക് ചെയ്ത EXP ബ്രെയിനിന്റെ ക്യൂവിലേക്ക് ഡാറ്റ ചേർക്കുന്നു, കൂടാതെ ക്യൂ ആദ്യം വായിക്കുകയും ആദ്യം വായിക്കുകയും ചെയ്യുന്നു (FIFO). മറ്റ് EXP ബ്രെയിൻ ഉപയോഗങ്ങൾക്ക് ലഭിക്കുന്നതിന് മുമ്പ് ഒന്നിലധികം സന്ദേശങ്ങൾ അയച്ചാൽ, അവ സംഭരിക്കപ്പെടുകയും അവ അയച്ച ക്രമത്തിൽ ഓരോന്നായി തിരികെ നൽകുകയും ചെയ്യും. സന്ദേശങ്ങൾക്ക് ക്യൂ ചെയ്യാൻ കഴിയുന്നതിനാൽ, ഓരോ ലൂപ്പിലും ഒരേ സ്റ്റാറ്റസ് ആവർത്തിച്ച് അയയ്ക്കുന്നത് ബാക്ക്ലോഗ് സൃഷ്ടിച്ചേക്കാം; സമയ-നിർണ്ണായക യുക്തിക്ക്, മൂല്യങ്ങൾ മാറുമ്പോൾ മാത്രം അയയ്ക്കുക.
പ്രധാനം: രണ്ട് റോബോട്ടുകളും ഒരേ സമയം serial_link ഉപയോഗിക്കുന്ന പ്രോജക്ടുകൾ പ്രവർത്തിപ്പിക്കുന്നുണ്ടാകണം, അല്ലെങ്കിൽ ഡാറ്റയൊന്നും അയയ്ക്കുകയോ സ്വീകരിക്കുകയോ ചെയ്യില്ല.
ക്ലാസ് കൺസ്ട്രക്ടറുകൾ#
serial_link(
int32_t index,
const char *name,
linkType type,
bool isWired = false );
ക്ലാസ് ഡിസ്ട്രക്റ്റർ#
serial_link ഒബ്ജക്റ്റ് നശിപ്പിക്കുകയും അനുബന്ധ ഉറവിടങ്ങൾ പുറത്തുവിടുകയും ചെയ്യുന്നു.
~serial_link();
പാരാമീറ്ററുകൾ#
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
സന്ദേശ ലിങ്ക് ബന്ധിപ്പിച്ചിരിക്കുന്ന സ്മാർട്ട് പോർട്ട്, |
|
|
ഈ ലിങ്കിന്റെ പേര്. ഈ അദ്വിതീയ സ്ട്രിംഗ് വെക്സോസ് ഹാഷ് ചെയ്യുമ്പോൾ ഒരു അദ്വിതീയ ഐഡി സൃഷ്ടിക്കുന്ന തരത്തിൽ നീളമുള്ളതായിരിക്കണമെന്ന് ശുപാർശ ചെയ്യുന്നു. ഒരു മോശം ലിങ്ക് നാമം “വെക്സ്ലിങ്ക്” പോലുള്ള പൊതുവായ ഒന്നായിരിക്കും, കാരണം അത് മറ്റൊരു ടീം ഉപയോഗിച്ചേക്കാം. |
|
|
ലിങ്കിന്റെ തരം, ഒന്നുകിൽ
|
|
|
സീരിയൽ_ലിങ്ക് ഒബ്ജക്റ്റ് വയർഡ് ആണോ എന്ന് (ഡിഫോൾട്ട് ആയി
|
കുറിപ്പുകൾ#
VEXlink വയർലെസ്, വയർഡ് ആശയവിനിമയങ്ങളെ പിന്തുണയ്ക്കുന്നു, പവർ റൂട്ടിംഗ് പ്രശ്നങ്ങൾ തടയുന്നതിന് വയർഡ് കണക്ഷനുകൾ പരിഷ്കരിച്ച സ്മാർട്ട് കേബിൾ ശുപാർശ ചെയ്യുന്നു.
വയർലെസ് ആശയവിനിമയത്തിന്, ഓരോ റോബോട്ടിനും ഒരു സ്മാർട്ട് പോർട്ടുമായി ബന്ധിപ്പിച്ചിരിക്കുന്ന ഒരു V5 റോബോട്ട് റേഡിയോ ആവശ്യമാണ്.
ഒരു EXP കൺട്രോളറിന്റെ VEXnet റേഡിയോയ്ക്കൊപ്പം VEXlink റേഡിയോ ഉപയോഗിക്കാം, സംഘർഷങ്ങൾ ഒഴിവാക്കാൻ ഏറ്റവും ഉയർന്ന നമ്പറുള്ള സ്മാർട്ട് പോർട്ടുമായി ഇത് ബന്ധിപ്പിക്കണം.
ഒരു VEXlink സൃഷ്ടിക്കാൻ, രണ്ട് EXP ബ്രെയിനുകളും ഒരു V5 റോബോട്ട് റേഡിയോയുമായി ബന്ധിപ്പിച്ചിരിക്കണം.
ഉദാഹരണം#
റോബോട്ട് 1 നുള്ള കോഡ്
// Create a wireless link in Port 1 serial_link link = serial_link( PORT1, // index "VEXRoboticsLink123456789", // name linkType::manager, // type true); // isWiredറോബോട്ട് 2 നുള്ള കോഡ്
// Create a wireless link in Port 1 serial_link link = serial_link( PORT1, // index "VEXRoboticsLink123456789", // name linkType::worker, // type true); // isWired
അംഗ പ്രവർത്തനങ്ങൾ#
serial_link ക്ലാസ്സിൽ ഇനിപ്പറയുന്ന അംഗ ഫംഗ്ഷനുകൾ ഉൾപ്പെടുന്നു:
isLinked— EXP ബ്രെയിനുകൾ ജോടിയാക്കുകയും ഈ ലിങ്കിൽ ആശയവിനിമയം നടത്തുകയും ചെയ്യുന്നുണ്ടോ എന്ന് പരിശോധിക്കുന്നു.send— ജോടിയാക്കിയ തലച്ചോറിലേക്ക് ഒരു സന്ദേശം അയയ്ക്കുന്നു.receive— അടുത്ത ഇൻകമിംഗ് സന്ദേശത്തിനായി കാത്തിരുന്ന് തിരികെ നൽകുന്നു.received— ഒരു പുതിയ സന്ദേശം ലഭിക്കുമ്പോഴെല്ലാം വിളിക്കേണ്ട ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുന്നു.
ഏതെങ്കിലും serial_link അംഗ ഫംഗ്ഷനുകൾ വിളിക്കുന്നതിന് മുമ്പ്, താഴെ കാണിച്ചിരിക്കുന്നതുപോലെ ഒരു serial_link ഉദാഹരണം സൃഷ്ടിക്കണം:
റോബോട്ട് 1 നുള്ള കോഡ്
// Create a wireless link in Port 1 serial_link link = serial_link( PORT1, // index "VEXRoboticsLink123456789", // name linkType::manager, // type true); // isWiredറോബോട്ട് 2 നുള്ള കോഡ്
// Create a wireless link in Port 1 serial_link link = serial_link( PORT1, // index "VEXRoboticsLink123456789", // name linkType::worker, // type true); // isWired
isLinked#
ഒരു സീരിയൽ ലിങ്കിലെ EXP ബ്രെയിനുകൾ പരസ്പരം ജോടിയാക്കുന്നുണ്ടോ എന്ന് നൽകുന്നു.
Available Functionsbool isLinked();
ഈ ഫംഗ്ഷന് ഒരു പാരാമീറ്ററുകളും ഇല്ല.
Return ValuesEXP ബ്രെയിനുകൾ ബന്ധിപ്പിച്ചിട്ടുണ്ടോ എന്ന് സൂചിപ്പിക്കുന്ന ഒരു ബൂളിയൻ നൽകുന്നു:
true— The two EXP Brains are paired and communicating on this link.false— The two EXP Brains are not paired on this link.
കൂടുതൽ കോഡുകൾ പ്രവർത്തിപ്പിക്കുന്നതിന് മുമ്പ് ഒരു പ്രോജക്റ്റിന്റെ തുടക്കത്തിൽ EXP ബ്രെയിനുകൾ ബന്ധിപ്പിച്ചിട്ടുണ്ടെന്ന് ഉറപ്പാക്കുന്നത് എപ്പോഴും നല്ല രീതിയാണ്.
റോബോട്ട് 1 നുള്ള കോഡ്
// Create the link serial_link 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"); Brain.Screen.newLine(); Brain.Screen.print("Sending message..."); // Message to send const char* message = "Hello Robot 2"; // Send the message link.send((uint8_t*)message, strlen(message));
റോബോട്ട് 2 നുള്ള കോഡ്
// Create the link serial_link link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()) { wait(0.1, seconds); } Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); Brain.Screen.print("Waiting..."); // Buffer to store incoming bytes uint8_t buffer[32] = {0}; int32_t n = link.receive(buffer, sizeof(buffer) - 1); // Null-terminate if (n > 0) { buffer[n] = 0; // Display the message that was sent Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); Brain.Screen.print((char*)buffer); } else { Brain.Screen.newLine(); Brain.Screen.print("No message received"); }
send#
ജോടിയാക്കിയ തലച്ചോറിലേക്ക് ഒരു സന്ദേശം അയയ്ക്കുന്നു.
Available Functions1 — ഒരു ബൈറ്റ് ബഫർ ഉപയോഗിച്ച് ഒരു സന്ദേശം അയയ്ക്കുന്നു.
int32_t send( uint8_t *buffer, int32_t length );
Parameters2 — ഒരു പ്രതീക ബഫർ ഉപയോഗിച്ച് ഒരു സന്ദേശം അയയ്ക്കുന്നു.
int32_t send( const char *buffer, int32_t length );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റ് EXP ബ്രെയിനിലേക്ക് അയയ്ക്കേണ്ട ബഫർ. |
|
|
അയയ്ക്കേണ്ട ബഫറിന്റെ നീളം. |
അയച്ച ബൈറ്റുകളുടെ എണ്ണത്തെ പ്രതിനിധീകരിക്കുന്ന int32_t നൽകുന്നു.
റോബോട്ട് 1 നുള്ള കോഡ്
// Create the link serial_link link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()) { wait(0.1, seconds); } Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 1 - Manager"); // Track last sent state uint8_t lastState = 255; // impossible initial value // Tell Robot 2 when the screen is being pressed while (true) { uint8_t state = Brain.Screen.pressing() ? 1 : 0; // Only send if state changed if (state != lastState) { link.send(&state, 1); lastState = state; } wait(0.02, seconds); }
റോബോട്ട് 2 നുള്ള കോഡ്
// Create the link serial_link link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()) { wait(0.1, seconds); } Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); Brain.Screen.print("Waiting..."); // Track the last state uint8_t lastShown = 255; while (true) { // Variable stores 1 - pressed, 0 - not pressed uint8_t state = 0; int32_t n = link.receive(&state, 1, 200); // Only update screen if state changes if (n == 1 && state != lastShown) { Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); // Display text if Robot 1's screen is being pressed if (state == 1) { Brain.Screen.print("Manager IS being pressed!"); } else { Brain.Screen.print("Manager is NOT being pressed"); } lastShown = state; } wait(0.02, seconds); }
receive#
അടുത്ത ഇൻകമിംഗ് സന്ദേശത്തിനായി കാത്തിരുന്ന് തിരികെ നൽകുന്നു.
Available FunctionsParameters1 — ഓപ്ഷണൽ ടൈംഔട്ടുള്ള ഒരു പ്രതീക ബഫറിലേക്ക് ഒരു സന്ദേശം സ്വീകരിക്കുന്നു.
int32_t receive( char *buffer, int32_t length, int32_t timeoutMs = 500);
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
ലഭിച്ച സന്ദേശം സൂക്ഷിക്കുന്നതിനുള്ള ബഫർ. |
|
|
ബഫറിന്റെ നീളം. |
|
|
ക്യൂ ശൂന്യമാണെങ്കിൽ മാത്രം |
ലഭിച്ച ബൈറ്റുകളുടെ എണ്ണത്തെ പ്രതിനിധീകരിക്കുന്ന int32_t നൽകുന്നു.
receiveലഭിക്കുമ്പോൾ, ലിങ്ക് ചെയ്തിരിക്കുന്ന മറ്റൊരു EXP ബ്രെയിനിൽ നിന്നുള്ള അടുത്ത ക്യൂ സന്ദേശം തിരികെ ലഭിക്കും.സന്ദേശങ്ങൾ FIFO ക്രമത്തിലാണ് വായിക്കുന്നത് (പഴയതും വായിക്കാത്തതും ആദ്യം).
receiveവിളിക്കുമ്പോൾ ക്യൂ ശൂന്യമാണെങ്കിൽ, പുതിയ സന്ദേശത്തിനായി നിർദ്ദിഷ്ടtimeoutMsവരെ അത് കാത്തിരിക്കും.ആ വിൻഡോയിൽ ഒരു സന്ദേശവും വന്നില്ലെങ്കിൽ,
receive0തിരികെ നൽകുന്നു, തുടർന്ന് അയയ്ക്കുന്ന ഏതൊരു സന്ദേശവും അടുത്ത തവണreceiveഉപയോഗിക്കുമ്പോൾ വായിക്കാനുള്ള ക്യൂവിൽ തുടരും.
റോബോട്ട് 1 നുള്ള കോഡ്
// Create the link serial_link link(PORT1, "VEXRoboticsLink123456789", linkType::manager, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()) { wait(0.1, seconds); } Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 1 - Manager"); // Track last sent state uint8_t lastState = 255; // impossible initial value // Tell Robot 2 when the screen is being pressed while (true) { uint8_t state = Brain.Screen.pressing() ? 1 : 0; // Only send if state changed if (state != lastState) { link.send(&state, 1); lastState = state; } wait(0.02, seconds); }
റോബോട്ട് 2 നുള്ള കോഡ്
// Create the link serial_link link(PORT1, "VEXRoboticsLink123456789", linkType::worker, true); // Do not run code UNTIL the Brains are linked while (!link.isLinked()) { wait(0.1, seconds); } Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); Brain.Screen.print("Waiting..."); // Track the last state uint8_t lastShown = 255; while (true) { // Variable stores 1 - pressed, 0 - not pressed uint8_t state = 0; int32_t n = link.receive(&state, 1, 200); // Only update screen if state changes if (n == 1 && state != lastShown) { Brain.Screen.clearScreen(); Brain.Screen.setCursor(1, 1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); // Display text if Robot 1's screen is being pressed if (state == 1) { Brain.Screen.print("Manager IS being pressed!"); } else { Brain.Screen.print("Manager is NOT being pressed"); } lastShown = state; } wait(0.02, seconds); }
received#
EXP ബ്രെയിനിന് അയച്ച സന്ദേശം ലഭിക്കുമ്പോഴെല്ലാം വിളിക്കേണ്ട ഒരു ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുന്നു.
Available Functions1 — ലഭിക്കുന്ന ഓരോ സന്ദേശത്തിനും ഒരു കോൾബാക്ക് ഫംഗ്ഷൻ രജിസ്റ്റർ ചെയ്യുന്നു.
void received( void (* callback)(const char *, const char *, double) );
2 — ഒരു അധിക int32_t ഫീൽഡ് ഉൾപ്പെടുന്ന ഓരോ സന്ദേശത്തിനും ലഭിക്കുന്ന ഒരു കോൾബാക്ക് രജിസ്റ്റർ ചെയ്യുന്നു.
void received( void (* callback)(const char *, const char *, int32_t, double) );
3 — സന്ദേശവുമായി പൊരുത്തപ്പെടുന്ന പേരുള്ള ലഭിച്ച സന്ദേശങ്ങൾക്ക് മാത്രം ഒരു കോൾബാക്ക് അഭ്യർത്ഥിക്കുന്നു.
void received( const char *message, void (* callback)(const char *, const char *, double) );
Parameters4 — സന്ദേശ പേലോഡിൽ ഒരു അധിക int32_t ഫീൽഡ് ഉൾപ്പെടുന്ന സാഹചര്യത്തിൽ, സന്ദേശവുമായി പൊരുത്തപ്പെടുന്ന പേരുള്ള സ്വീകരിച്ച സന്ദേശങ്ങൾക്ക് മാത്രം അഭ്യർത്ഥിച്ച ഒരു കോൾബാക്ക് രജിസ്റ്റർ ചെയ്യുന്നു.
void received( const char *message, void (* callback)(const char *, const char *, int32_t, double) );
പാരാമീറ്റർ |
ടൈപ്പ് ചെയ്യുക |
വിവരണം |
|---|---|---|
|
|
പൊരുത്തപ്പെടേണ്ട സന്ദേശ നാമം (സ്ട്രിംഗ്). ലഭിച്ച സന്ദേശത്തിന്റെ പേര് ഈ മൂല്യവുമായി പൊരുത്തപ്പെടുമ്പോൾ, |
|
|
EXP ബ്രെയിനിന് |
ഈ ഫംഗ്ഷൻ ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.
Notesreceivedകോൾബാക്കുകൾ വിളിക്കുന്നു:
callback(message, linkname, index, value)
വാദം |
വിവരണം |
|---|---|
|
ലഭിച്ച സന്ദേശത്തിന്റെ പേര് (ഉദാഹരണത്തിന്, |
|
സന്ദേശം ലഭിച്ച ലിങ്ക് നാമം. |
|
സന്ദേശത്തോടൊപ്പം അയച്ച പൂർണ്ണസംഖ്യ മൂല്യം (നൽകിയിട്ടുണ്ടെങ്കിൽ). |
|
സന്ദേശത്തോടൊപ്പം അയച്ച ഫ്ലോട്ട് മൂല്യം (നൽകിയിട്ടുണ്ടെങ്കിൽ). |
റോബോട്ട് 1 നുള്ള കോഡ്
// Send left or right when pressed void screen_pressed() { if (Brain.Screen.xPosition() < 240) { link.send((uint8_t*)"left", 4); } else { link.send((uint8_t*)"right", 5); } } int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Create the link serial_link 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"); Brain.Screen.pressed(screen_pressed); }
റോബോട്ട് 2 നുള്ള കോഡ്
// Called when message received void received_callback(uint8_t *buffer, int32_t length) { char msg[32]; // Copy safely and null terminate int n = (length < 31) ? length : 31; memcpy(msg, buffer, n); msg[n] = '\0'; Brain.Screen.clearScreen(); Brain.Screen.setCursor(1,1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); // Display if Robot 1's screen is pressed on left or right if (strcmp(msg, "left") == 0) { Brain.Screen.print("Manager pressed LEFT"); } else if (strcmp(msg, "right") == 0) { Brain.Screen.print("Manager pressed RIGHT"); } } int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Create the link serial_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(received_callback); Brain.Screen.clearScreen(); Brain.Screen.setCursor(1,1); Brain.Screen.print("Robot 2 - Worker"); Brain.Screen.newLine(); Brain.Screen.print("Waiting..."); }