I have been having issues with transmitting data from one brain to another I have looked over the C++ guide and found that it’s message link and serial link support is not accurate in several ways all I am trying to do is send two int from one brain to another I have also had this weird thing happen in the code were the brain screen prints regularly on the receiving end and after a while replaces the first three characters with zeros.
the code for both programs is down below.
sender code
#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include "vex.h"
using namespace vex;
// Brain should be defined by default
brain Brain;
// START V5 MACROS
#define waitUntil(condition) \
do { \
wait(5, msec); \
} while (!(condition))
#define repeat(iterations) \
for (int iterator = 0; iterator < iterations; iterator++)
// END V5 MACROS
// Robot configuration code.
controller Controller1 = controller(primary);
// generating and setting random seed
void initializeRandomSeed(){
int systemTime = Brain.Timer.systemHighResolution();
double batteryCurrent = Brain.Battery.current();
double batteryVoltage = Brain.Battery.voltage(voltageUnits::mV);
// Combine these values into a single integer
int seed = int(batteryVoltage + batteryCurrent * 100) + systemTime;
// Set the seed
srand(seed);
}
void vexcodeInit() {
//Initializing random seed.
initializeRandomSeed();
}
// Helper to make playing sounds from the V5 in VEXcode easier and
// keeps the code cleaner by making it clear what is happening.
void playVexcodeSound(const char *soundName) {
printf("VEXPlaySound:%s\n", soundName);
wait(5, msec);
}
// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
#pragma endregion VEXcode Generated Robot Configuration
// Include the V5 Library
#include "vex.h"
// Allows for easier use of the VEX Library
using namespace vex;
float myVariable;
// "when started" hat block
int whenStarted1() {
return 0;
}
message_link link1 = message_link(PORT9, "link", linkType::manager);
message_link link2 = message_link(PORT9, "link", linkType::manager);
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
while (1) {
int Left = Controller1.Axis3.position();
int Right = Controller1.Axis2.position();
if (Left == 0) {
link1.send("a",6);
}
else if (Left > 0) {
if (Left > 25) {
link1.send("b",8);
}
link1.send("c",10);
}
else {
if (Left > -25) {
link1.send("d",12);
}
}
if (Right == 0) {
link2.send("a",7);
}
else if (Right > 0) {
if (Left > 25) {
link2.send("b",9);
}
link2.send("c",11);
}
else {
if (Right > -25) {
link2.send("d",13);
}
}
}
}
Receiver code.
#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include "vex.h"
using namespace vex;
// Brain should be defined by default
brain Brain;
// START V5 MACROS
#define waitUntil(condition) \
do { \
wait(5, msec); \
} while (!(condition))
#define repeat(iterations) \
for (int iterator = 0; iterator < iterations; iterator++)
// END V5 MACROS
// Robot configuration code.
motor Motor9 = motor(PORT9, ratio18_1, false);
motor Motor20 = motor(PORT20, ratio18_1, false);
// generating and setting random seed
void initializeRandomSeed(){
int systemTime = Brain.Timer.systemHighResolution();
double batteryCurrent = Brain.Battery.current();
double batteryVoltage = Brain.Battery.voltage(voltageUnits::mV);
// Combine these values into a single integer
int seed = int(batteryVoltage + batteryCurrent * 100) + systemTime;
// Set the seed
srand(seed);
}
void vexcodeInit() {
//Initializing random seed.
initializeRandomSeed();
}
// Helper to make playing sounds from the V5 in VEXcode easier and
// keeps the code cleaner by making it clear what is happening.
void playVexcodeSound(const char *soundName) {
printf("VEXPlaySound:%s\n", soundName);
wait(5, msec);
}
#pragma endregion VEXcode Generated Robot Configuration
// Include the V5 Library
#include "vex.h"
// Allows for easier use of the VEX Library
using namespace vex;
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
float drive1 = 0;
float drive2 = 0;
message_link link1 = message_link(PORT10, "link", linkType::worker);
message_link link2 = message_link(PORT10, "link", linkType::worker);
while (1) {
if (link1.receive("a",30)) {
float drive1 = 0;
}
else if (link1.receive("c",30)) {
if (link1.receive("d",30)) {
float drive1 = 100;
}
else {
float drive1 = 25;
}
}
else {
if (link1.receive("d",30)) {
float drive1 = -25;
}
else {
float drive1 = -100;
}
}
if (link2.receive("a",30)) {
float drive2 = 0;
}
else if (link2.receive("c",30)) {
if (link2.receive("b",30)) {
float drive2 = 100;
}
else {
float drive2 = 25;
}
}
else {
if (link1.receive("d",30)) {
float drive2 = -25;
}
else {
float drive2 = -100;
}
}
if (drive1 == 0 ) {
Brain.Screen.print("instruction right off sent");
}
Brain.Screen.setCursor(3, 3);
if (drive2 == 0) {
Brain.Screen.print("instruction left off sent");
}
Brain.Screen.setCursor(1, 1);
Motor9.setVelocity(drive1, percent);
Motor20.setVelocity(drive2, percent);
Motor9.spin(forward);
Motor20.spin(forward);
}
}