Aller au contenu


Photo
- - - - -

Vigibot Pi arduino Serial Communication Example


3 réponses à ce sujet

#1 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 8 388 messages
  • Gender:Male
  • Location:Anglet
  • Interests:Robotique, Entrepreneuriat, Innovation, Programmation, Résolution de problème, Recherche de solutions, Mécanique, Electronique, Créer, Concevoir

Posté 03 décembre 2019 - 03:30

This is a simple code example for serial communication between pi and arduino or other board with vigibot protocole with default remote configuration : 

/*
 * Vigibot Pi to Arduino Uart default remote configuration example by Mike118
 */


// Meta Type : 

typedef struct {
 union {
  struct {
   uint16_t x;
   uint16_t y;
  };
  uint16_t coordonnees[2];
  uint8_t bytes[4];
 };
} Point;

typedef struct {
 union {
  struct {
   int8_t x;
   int8_t y;
   int8_t z;
  };
  uint8_t bytes[3];
 };
} Vitesses;


// CONFIG 

#define PISERIAL Serial
#define NBPOSITIONS 2
#define FAILSAFE 250 // ms


// TTS 

#define TTSBUFFERSIZE 255  
uint8_t ttsBuffer[TTSBUFFERSIZE];
uint8_t ttsCurseur = 0;


// TX

#define TXFRAMESIZE (NBPOSITIONS * 4 + 15)

typedef struct {
 union {
  struct {
   uint8_t sync[2];               // 2
   Point positions[NBPOSITIONS];  // NBPOSITIONS * 4
   uint16_t val16[2];             // 2 * 2
   uint8_t choixCameras;          // 1
   Vitesses vitesses;             // 3
   uint8_t interrupteurs;         // 1
   uint8_t val8[4];               // 4
  };

  uint8_t bytes[TXFRAMESIZE];
 };
} TrameTx;


// RX

#define RXFRAMESIZE (NBPOSITIONS * 4 + 7)

typedef struct {
 union {
  struct {                       // Sizes
   uint8_t sync[2];              // 2
   Point positions[NBPOSITIONS]; // NBPOSITIONS * 4
   uint8_t choixCameras;         // 1
   Vitesses vitesses;            // 3
   uint8_t interrupteurs;        // 1
  };

  uint8_t bytes[RXFRAMESIZE];
 };
} TrameRx;


TrameTx trameTx;
TrameRx trameRx;

uint32_t lastTrameTimestamp = millis();

void setup() {
  PISERIAL.begin(115200);
  // add all your init here
}


void loop() {
  
  if(readPiSerial()) {
    // each time we receive a full trame run repeatedly:
    // use values inside trameRx to tell your robot how to move ...
    // trameRx.vitesses.x , trameRx.vitesses.y, trameRx.vitesses.z 
    // trameRx.positions[i].x trameRx.positions[i].y  etc.... 
    
    writePiSerial();
    lastTrameTimestamp = millis();
  }

  if( millis() - lastTrameTimestamp > FAILSAFE ) {
    // Stop the robot in case the robot lost connection with the Pi
  } else {
    // put your main code here, to run repeatedly:
    // avoid abstacle, run speed ...
  }
}


bool readPiSerial() {
 uint8_t current;
 static uint8_t lastType = 0;
 static uint8_t n = 0;
 static uint8_t frame[RXFRAMESIZE];

 while(PISERIAL.available()) {
  current = PISERIAL.read();

  switch(n) {

   case 0:
    if(current == '$')
     n = 1;
    break;

   case 1:
    if(current != 'T' && lastType == 'T')
     writeTtsBuffer('\0');

    if(current == 'S' || current == 'T') {
     lastType = current;
     n = 2;
    } else
     n = 0;
    break;

    default:
    frame[n++] = current;

    if(n == RXFRAMESIZE) {

     if(lastType == 'T') {

      for(uint8_t i = 2; i < RXFRAMESIZE; i++)
       writeTtsBuffer(frame[i]);

     } else if(lastType == 'S') {

      for(uint8_t p = 0; p < RXFRAMESIZE; p++)
       trameRx.bytes[p] = frame[p];

     }
     n = 0;
     return true;
    }

  }
 }

 return false;
}

void writePiSerial() {
 // Header, do not modify
 trameTx.sync[0] = '$';
 trameTx.sync[1] = 'R';  

 // modify the feedback according your need. By default we copy the trameRx content ... 
 for(uint8_t i = 0; i < NBPOSITIONS; i++) {
  trameTx.positions[i].x = trameRx.positions[i].x;
  trameTx.positions[i].y = trameRx.positions[i].y;
 }
 trameTx.val16[0] = 0;   // Voltage (will be updated by Raspberry pi)
 trameTx.val16[1] = 0;   // Percent (will be updated by Raspberry pi)
 trameTx.choixCameras = trameRx.choixCameras;
 trameTx.vitesses.x = trameRx.vitesses.x;
 trameTx.vitesses.y = trameRx.vitesses.y;
 trameTx.vitesses.z = trameRx.vitesses.z;
 trameTx.interrupteurs = trameRx.interrupteurs;
 trameTx.val8[0] = 0;   // CPU load (will be updated by Raspberry pi)
 trameTx.val8[1] = 0;   // Soc temp (will be updated by Raspberry pi)
 trameTx.val8[2] = 0;   // link (will be updated by Raspberry pi)
 trameTx.val8[3] = 0;   // RSSI (will be updated by Raspberry pi)

 for( uint8_t i = 0; i < TXFRAMESIZE; i++)
  PISERIAL.write(trameTx.bytes[i]);
}

void displayTtsBuffer (uint8_t * ttsBuffer, uint8_t bufferSize) {
  // you can modify this function to display text on a screen depending on your hardware...
  for( uint8_t i = 0; i < bufferSize; i++)
    Serial.write(ttsBuffer[i]);
  Serial.println("");
}

void writeTtsBuffer( uint8_t ttsChar) {
  static uint8_t ttsCurseur = 0;
  if( ttsCurseur < TTSBUFFERSIZE && ttsChar != '\0') {
    ttsBuffer[ttsCurseur] = ttsChar;
    ttsCurseur ++;
  }
  if( ttsCurseur == TTSBUFFERSIZE || ttsChar == '\0') {
    displayTtsBuffer (ttsBuffer, ttsCurseur);
    ttsCurseur = 0;
  }
}
   

Note : 

 

EN

You will need to activate devCommande to tell the raspberryPi to send data to the arduino and devTelemetrie if you want the Pi to read information sent by the arduino on Vigibot.

To connect your arduino to the Pi, you need to connect Arduino TX pin on Pi RX pin and Arduino Rx pin on TX Pi pin. 
Plus, you need to connect ground between Arduino and Pi .

 

Warning: 
Pi is working with a 3.3V logic level. If using a 5V arduino board ( like uno, nano or mega) you should use a logic level converter 

 

 

FR

Vous devrez activer devCommande pour dire à la Raspberry pi d'envoyer des données à l'arduino et devTelemetrie pour dire à la Raspberry pi de lire les informations envoyée par l'arduino sur Vigibot. 

Pour relier une arduino à un pi en Serial il faut connecter le TX de l'arduino au RX de la raspberry pi et inversement le RX de l'arduino au TX de la raspberry pi. 
De plus, la masse de l'arduino et de la raspberry pi doit être commune...

 

Attention rappel : 
La raspberry pi est en niveau logique 3.3V. 
Si vous utilisez une arduino en 5V (arduino uno, mega, nano ) il faudra utiliser un convertisseur de niveau logique


 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 

 

Les réalisations de Mike118  

 

 

 


#2 Marmont

Marmont

    Nouveau membre

  • Membres
  • 2 messages

Posté 04 décembre 2019 - 03:02

Hello here,

I have tested the code with a pololu zumo, work like a charm!

 

The advantage here is if you have a robot wich is already driven by arduino, it can be easily modified to work with vigibot:

 

1) Connect the UART :

  • Ardu.pin0 RX <-> PI GPIO14 TX
  • Ardu.pin1 TX <-> PI GPIO15 RX
  • GND <-> GND

2) Modify the code above to work with your bot, in the main loop you can get the most importants variables:

trameRx.vitesses.y -> Speed in main axis of the robot send by the server

trameRx.vitesses.z - Rotation around the vertical axis send by the server

 

With theses moves requests you can program your motors to feet the particularity of the robot. Here the exemple with a classical differential driven robot, the Zumo.

    // mixage pour obtenir les vitesses moteurs
    left_speed = (trameRx.vitesses.y * MAX_SPEED / SPEED_RANGE) - (trameRx.vitesses.z * MAX_SPEED / SPEED_RANGE);
    right_speed = (trameRx.vitesses.y * MAX_SPEED / SPEED_RANGE) + (trameRx.vitesses.z * MAX_SPEED / SPEED_RANGE);

    // Saturation des vitesses
    left_speed = min(max(left_speed, -MAX_SPEED), MAX_SPEED);
    right_speed = min(max(right_speed, -MAX_SPEED), MAX_SPEED);

Then you can send the right speed to your motors, in my case: (I use a library to drive the zumo)

    ZumoMotors::setSpeeds(left_speed, right_speed);

Here the complete code :

/*
 * Vigibot Pi to Arduino Uart default remote configuration example by Mike118
 * Completed by Marmont to work with a Zumo
 */

#include <ZumoShield.h>

// Meta Type :

typedef struct {
 union {
  struct {
   uint16_t x;
   uint16_t y;
  };
  uint16_t coordonnees[2];
  uint8_t bytes[4];
 };
} Point;

typedef struct {
 union {
  struct {
   int8_t x;
   int8_t y;
   int8_t z;
  };
  uint8_t bytes[3];
 };
} Vitesses;


// CONFIG

#define PISERIAL Serial
#define NBPOSITIONS 2
#define FAILSAFE 250 // ms

#define MAX_SPEED              400 // max motor speed
#define SPEED_RANGE            128 //

// TTS

#define TTSBUFFERSIZE 255  
uint8_t ttsBuffer[TTSBUFFERSIZE];
uint8_t ttsCurseur = 0;


// TX

#define TXFRAMESIZE (NBPOSITIONS * 4 + 15)

typedef struct {
 union {
  struct {
   uint8_t sync[2];               // 2
   Point positions[NBPOSITIONS];  // NBPOSITIONS * 4
   uint16_t val16[2];             // 2 * 2
   uint8_t choixCameras;          // 1
   Vitesses vitesses;             // 3
   uint8_t interrupteurs;         // 1
   uint8_t val8[4];               // 4
  };

  uint8_t bytes[TXFRAMESIZE];
 };
} TrameTx;


// RX

#define RXFRAMESIZE (NBPOSITIONS * 4 + 7)

typedef struct {
 union {
  struct {                       // Sizes
   uint8_t sync[2];              // 2
   Point positions[NBPOSITION];  // NBPOSITIONS * 4
   uint8_t choixCameras;         // 1
   Vitesses vitesses;            // 3
   uint8_t interrupteurs;        // 1
  };

  uint8_t bytes[RXFRAMESIZE];
 };
} TrameRx;


TrameTx trameTx;
TrameRx trameRx;

uint32_t lastTrameTimestamp = millis();

void setup() {
  PISERIAL.begin(115200);
 
 
  // add all your init here
}


void loop() {
 
  if(readPiSerial()) {
    // each time we receive a full trame run repeatedly:
    // use values inside TrameRx to tell your robot how to move ...
    // trameRx.vitesses.x , trameRx.vitesses.y, trameRx.vitesses.z
    // trameRx.positions[i].x trameRx.positions[i].y  etc....
    
    writePiSerial();
    lastTrameTimestamp = millis();
  }

  if( millis() - lastTrameTimestamp > FAILSAFE ) {
    // Stop the robot in case the robot lost connection with the Pi
  } else {

    int left_speed, right_speed;
    
    // mixage pour obtenir les vitesses moteurs
    left_speed = (trameRx.vitesses.y * MAX_SPEED / SPEED_RANGE) - (trameRx.vitesses.z * MAX_SPEED / SPEED_RANGE);
    right_speed = (trameRx.vitesses.y * MAX_SPEED / SPEED_RANGE) + (trameRx.vitesses.z * MAX_SPEED / SPEED_RANGE);

    // Saturation des vitesse
    left_speed = min(max(left_speed, -MAX_SPEED), MAX_SPEED);
    right_speed = min(max(right_speed, -MAX_SPEED), MAX_SPEED);

    ZumoMotors::setSpeeds(left_speed, right_speed);
  }
}

bool readPiSerial() {
 uint8_t current;
 static uint8_t lastType = 0;
 static uint8_t n = 0;
 static uint8_t frame[RXFRAMESIZE];

 while(PISERIAL.available()) {
  current = PISERIAL.read();

  switch(n) {

   case 0:
    if(current == '$')
     n = 1;
    break;

   case 1:
    if(current != 'T' && lastType == 'T')
     writeTtsBuffer('\0');

    if(current == 'S' || current == 'T') {
     lastType = current;
     n = 2;
    } else
     n = 0;
    break;

    default:
    frame[n++] = current;

    if(n == RXFRAMESIZE) {

     if(lastType == 'T') {

      for(uint8_t i = 2; i < RXFRAMESIZE; i++)
       writeTtsBuffer(frame[i]);

     } else if(lastType == 'S') {

      for(uint8_t p = 0; p < RXFRAMESIZE; p++)
       trameRx.bytes[p] = frame[p];

     }
     n = 0;
     return true;
    }

  }
 }

 return false;
}

void writePiSerial() {
 // Header, do not modify
 trameTx.sync[0] = '$';
 trameTx.sync[1] = 'R';  

 // modify the feedback according your need. By default we copy the trameRx content ...
 for(uint8_t i = 0; i < NBPOSITIONS; i++) {
  trameTx.positions[i].x = trameRx.positions[i].x;
  trameTx.positions[i].y = trameRx.positions[i].y;
 }
 trameTx.val16[0] = 0;   // Voltage
 trameTx.val16[1] = 0;   // Percent
 trameTx.choixCameras = trameRx.choixCameras;
 trameTx.vitesses.x = trameRx.vitesses.x;
 trameTx.vitesses.y = trameRx.vitesses.y;
 trameTx.vitesses.z = trameRx.vitesses.z;
 trameTx.interrupteurs = trameRx.interrupteurs;
 trameTx.val8[0] = 0;   // CPU load
 trameTx.val8[1] = 0;   // Soc temp 
 trameTx.val8[2] = 0;   // link
 trameTx.val8[3] = 0;   // RSSI

 for( uint8_t i = 0; i < TXFRAMESIZE; i++)
  PISERIAL.write(trameTx.bytes[i]);
}

void displayTtsBuffer (uint8_t * ttsBuffer, uint8_t bufferSize) {
  // you can modify this function to display text on a screen depending on your hardware...
  for( uint8_t i = 0; i < bufferSize; i++)
    Serial.write(ttsBuffer[i]);
  Serial.println("");
}

void writeTtsBuffer( uint8_t ttsChar) {
  static uint8_t ttsCurseur = 0;
  if( ttsCurseur < TTSBUFFERSIZE && ttsChar != '\0') {
    ttsBuffer[ttsCurseur] = ttsChar;
    ttsCurseur ++;
  }
  if( ttsCurseur == TTSBUFFERSIZE || ttsChar == '\0') {
    displayTtsBuffer (ttsBuffer, ttsCurseur);
    ttsCurseur = 0;
  }
}

Very easy, very fonctionnal, a lot more functionnality to investigate!

Thk to mikes118 for the great work.

Marmont



#3 Snyp54

Snyp54

    Nouveau membre

  • Membres
  • 26 messages

Posté 10 janvier 2020 - 10:14

Hi all,

With Mike118 ( and only Mike118 ^^ ), we have make a code for use FEETECH SCS15 servo to work with Vigibot.

 

The full code

/*
 * Vigibot Pi to Arduino Uart default remote configuration example by Mike118
 */

#include <SCServo.h>
SCSCL sc;

int uint16toSCS15( uint16_t value ) {
  return (value - 32768)* 512 * 180 / (100 * 32768) + 512;
}

// Meta Type : 

typedef struct {
 union {
  struct {
   uint16_t x;
   uint16_t y;
  };
  uint16_t coordonnees[2];
  uint8_t bytes[4];
 };
} Point;

typedef struct {
 union {
  struct {
   int8_t x;
   int8_t y;
   int8_t z;
  };
  uint8_t bytes[3];
 };
} Vitesses;


// CONFIG 

#define PISERIAL Serial
#define NBPOSITIONS 2
#define FAILSAFE 100 // ms


// TTS 

#define TTSBUFFERSIZE 255  
uint8_t ttsBuffer[TTSBUFFERSIZE];
uint8_t ttsCurseur = 0;


// TX

#define TXFRAMESIZE (NBPOSITIONS * 4 + 15)

typedef struct {
 union {
  struct {
   uint8_t sync[2];               // 2
   Point positions[NBPOSITIONS];  // NBPOSITIONS * 4
   uint16_t val16[2];             // 2 * 2
   uint8_t choixCameras;          // 1
   Vitesses vitesses;             // 3
   uint8_t interrupteurs;         // 1
   uint8_t val8[4];               // 4
  };

  uint8_t bytes[TXFRAMESIZE];
 };
} TrameTx;


// RX

#define RXFRAMESIZE (NBPOSITIONS* 4 + 7)

typedef struct {
 union {
  struct {                        // Sizes
   uint8_t sync[2];               // 2
   Point positions[NBPOSITIONS];  // NBPOSITIONS * 4
   uint8_t choixCameras;          // 1
   Vitesses vitesses;             // 3
   uint8_t interrupteurs;         // 1
  };

  uint8_t bytes[RXFRAMESIZE];
 };
} TrameRx;


TrameTx trameTx;
TrameRx trameRx;

uint32_t lastTrameTimestamp = millis();
Point oldPositions[NBPOSITIONS];        // NBPOSITIONS * 4

void setup() {
  PISERIAL.begin(115200);
  // add all your init here
  Serial1.begin(1000000);
  sc.pSerial = &Serial1;
}


void loop() {
  
  if(readPiSerial()) {
    // each time we receive a full trame run repeatedly:
    // use values inside TrameRx to tell your robot how to move ...
    // TrameRx.vitesses.x , TrameRx.vitesses.y, TrameRx.vitesses.z 
    // TrameRx.positions[i].x TrameRx.positions[i].y  etc.... 
    
    //          SERVID | conversion Position      |    Speed

    if(oldPositions[0].x != trameRx.positions[0].x) {
      sc.WritePos(1, uint16toSCS15(trameRx.positions[0].x), 200);
      oldPositions[0].x = trameRx.positions[0].x;
    }

    if(oldPositions[0].y != trameRx.positions[0].y) {
      sc.WritePos(2, uint16toSCS15(trameRx.positions[0].y), 200);
      oldPositions[0].y = trameRx.positions[0].y;
    }

    if(oldPositions[1].x != trameRx.positions[1].x) {
      sc.WritePos(3, uint16toSCS15(trameRx.positions[1].x), 200);
      oldPositions[1].x = trameRx.positions[1].x;
    }

    if(oldPositions[1].y != trameRx.positions[1].y) {
      sc.WritePos(4, uint16toSCS15(trameRx.positions[1].y), 200);
      oldPositions[1].y = trameRx.positions[1].y;
    }
    
    writePiSerial();
    lastTrameTimestamp = millis();
    
  }

  if( millis() - lastTrameTimestamp > FAILSAFE ) {
    // Stop the robot in case the robot lost connection with the Pi
  } else {
    // put your main code here, to run repeatedly:
    // avoid abstacle, run speed ...
  }
}



bool readPiSerial() {
 uint8_t current;
 static uint8_t lastType = 0;
 static uint8_t n = 0;
 static uint8_t frame[RXFRAMESIZE];

 while(PISERIAL.available()) {
  current = PISERIAL.read();

  switch(n) {

   case 0:
    if(current == '$')
     n = 1;
    break;

   case 1:
    if(current != 'T' && lastType == 'T')
     writeTtsBuffer('\0');

    if(current == 'S' || current == 'T') {
     lastType = current;
     n = 2;
    } else
     n = 0;
    break;

    default:
    frame[n++] = current;

    if(n == RXFRAMESIZE) {

     if(lastType == 'T') {

      for(uint8_t i = 2; i < RXFRAMESIZE; i++)
       writeTtsBuffer(frame[i]);

     } else if(lastType == 'S') {

      for(uint8_t p = 0; p < RXFRAMESIZE; p++)
       trameRx.bytes[p] = frame[p];

     }
     n = 0;
     return true;
    }

  }
 }

 return false;
}

void writePiSerial() {
 // Header, do not modify
 trameTx.sync[0] = '$';
 trameTx.sync[1] = 'R';  

 // modify the feedback according your need. By default we copy the trameRx content ... 
 for(uint8_t i = 0; i < NBPOSITIONS; i++) {
  trameTx.positions[i].x = trameRx.positions[i].x;
  trameTx.positions[i].y = trameRx.positions[i].y;
 }
 trameTx.val16[0] = 0;   // Voltage
 trameTx.val16[1] = 0;   // Percent
 trameTx.choixCameras = trameRx.choixCameras;
 trameTx.vitesses.x = trameRx.vitesses.x;
 trameTx.vitesses.y = trameRx.vitesses.y;
 trameTx.vitesses.z = trameRx.vitesses.z;
 trameTx.interrupteurs = trameRx.interrupteurs;
 trameTx.val8[0] = 0;   // CPU load
 trameTx.val8[1] = 0;   // Soc temp
 trameTx.val8[2] = 0;   // link
 trameTx.val8[3] = 0;   // RSSI

 for( uint8_t i = 0; i < TXFRAMESIZE; i++)
  PISERIAL.write(trameTx.bytes[i]);
}

void displayTtsBuffer (uint8_t * ttsBuffer, uint8_t bufferSize) {
  // you can modify this function to display text on a screen depending on your hardware...
  for( uint8_t i = 0; i < bufferSize; i++)
    Serial.write(ttsBuffer[i]);
  Serial.println("");
}

void writeTtsBuffer( uint8_t ttsChar) {
  static uint8_t ttsCurseur = 0;
  if( ttsCurseur < TTSBUFFERSIZE && ttsChar != '\0') {
    ttsBuffer[ttsCurseur] = ttsChar;
    ttsCurseur ++;
  }
  if( ttsCurseur == TTSBUFFERSIZE || ttsChar == '\0') {
    displayTtsBuffer (ttsBuffer, ttsCurseur);
    ttsCurseur = 0;
  }
}

Add SCS Library and convert 0 65535 -> -180° à 180° to 0 1023 -> -100° à 100°:

#include <SCServo.h>
SCSCL sc;

int uint16toSCS15( uint16_t value ) {
  return (value - 32768)* 512 * 180 / (100 * 32768) + 512;
}

Configure ID servo with POSITIONS: ( sc.WritePos(IDSERVO, uint16toSCS15(trameRx.positions[0].y), 200);

if(oldPositions[0].x != trameRx.positions[0].x) {
 sc.WritePos(1, uint16toSCS15(trameRx.positions[0].x), 200);
 oldPositions[0].x = trameRx.positions[0].x;
}

if(oldPositions[0].y != trameRx.positions[0].y) {
 sc.WritePos(2, uint16toSCS15(trameRx.positions[0].y), 200);
 oldPositions[0].y = trameRx.positions[0].y;
}

if(oldPositions[1].x != trameRx.positions[1].x) {
 sc.WritePos(3, uint16toSCS15(trameRx.positions[1].x), 200);
 oldPositions[1].x = trameRx.positions[1].x;
}

if(oldPositions[1].y != trameRx.positions[1].y) {
 sc.WritePos(4, uint16toSCS15(trameRx.positions[1].y), 200);
 oldPositions[1].y = trameRx.positions[1].y;
}
    

And voila!



#4 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 8 388 messages
  • Gender:Male
  • Location:Anglet
  • Interests:Robotique, Entrepreneuriat, Innovation, Programmation, Résolution de problème, Recherche de solutions, Mécanique, Electronique, Créer, Concevoir

Posté 13 février 2020 - 09:29

How to add your custom return value ? 

Chose if you want return a val8  ( 8bits value ) or a val16 ( 16bits value ) 

For example I want add a voltage value as val8. 

 

=> I will need to configure vigibot to activate devCommande and devTelemetrie  and add a val8 in RX config 

=> I will need to modify the arduino code to add my val8 in the trameTx structure and update TXFRAMESIZE. 

#define TXFRAMESIZE (NBPOSITIONS * 4 + 16)   // NBPOSITIONS * 4 + 15 by default + 1 for the val8 added

typedef struct {
 union {
  struct {
   uint8_t sync[2];               // 2
   Point positions[NBPOSITIONS];  // NBPOSITIONS * 4
   uint16_t val16[2];             // 2 * 2
   uint8_t choixCameras;          // 1
   Vitesses vitesses;             // 3
   uint8_t interrupteurs;         // 1
   uint8_t val8[5];               // 4 by default => Now set to 5 = 4 +1
  };

  uint8_t bytes[TXFRAMESIZE];
 };
} TrameTx;

Then I will be able to make the line : 

trameTx.val8[4] = yourCustomValue;  // change yourCustomValue according your need.

See a full code example here : https://www.robot-ma...gibot/?p=107522

 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 

 

Les réalisations de Mike118  

 

 

 




Répondre à ce sujet



  


0 utilisateur(s) li(sen)t ce sujet

0 members, 0 guests, 0 anonymous users