Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Invalid operands to binary expression Pin
Richard MacCutchan28-Apr-18 22:18
mveRichard MacCutchan28-Apr-18 22:18 
GeneralRe: Invalid operands to binary expression Pin
Member 1380291229-Apr-18 10:21
Member 1380291229-Apr-18 10:21 
GeneralRe: Invalid operands to binary expression Pin
Richard MacCutchan29-Apr-18 21:02
mveRichard MacCutchan29-Apr-18 21:02 
GeneralRe: Invalid operands to binary expression Pin
Member 1486266714-Jun-20 2:38
Member 1486266714-Jun-20 2:38 
GeneralRe: Invalid operands to binary expression Pin
Richard MacCutchan14-Jun-20 4:30
mveRichard MacCutchan14-Jun-20 4:30 
GeneralRe: Invalid operands to binary expression Pin
Member 1486266714-Jun-20 20:50
Member 1486266714-Jun-20 20:50 
GeneralRe: Invalid operands to binary expression Pin
Richard MacCutchan14-Jun-20 22:17
mveRichard MacCutchan14-Jun-20 22:17 
QuestionData packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Ahmad ZULKIPLEE24-Apr-18 23:26
Ahmad ZULKIPLEE24-Apr-18 23:26 
I hope that someone can help me.
            
I am currently working on developing a flight simulator with force feedback. To do the calculations of the force feedback, we need to know the position of vertical yoke that we are using. We use two potentiometers to detect the position of the yoke for roll and pitch. The potentiometers are connected with Arduino Uno that will change analog values to digital values:


Digital value of roll will be between [450: 650]
Digital value of pitch will be between [100: 340]

These values then will be sent to Raspberry Pi where we do the calculations of force feedback. I’m using the RS232 protocol (library developed by Teunis van Beelen [link]) to receive the data from Arduino.I'm using a usb cable to send data from Arduino To RPi.

I’m developing the code in Qt Creator in C++

My problem: I received the data packets from Arduino every 10ms, BUT, sometimes the packets are cut into two parts (see figure 1). I can say that for every 100 data packets sent, 6 will be cut. So I will receive 6 times incomplete data packets for the calculations. The "incomplete part" will come together with the next data packet.

For the time being, if the data was cut, the code will just "jump" the data packet and will not do any calculation. But, for optimisation purpose, I need to resolve this problem. By the way, the baudrate is the same for Arduino and RPi that is 115200. The whole program is being developed in C++, so it is not advisable to use pyserial because the program need to receive and calculate the force feedback within 10ms.

[figure1]

Can someone explains why and how did these happen? What do I need to do to resolve this problem?

My code in Arduino

C++
int pinpotRoulis=A0; //analog input 0
 int valpotRoulis=0;
 int valmancheRoulis=0;
 int mapRoulis =0;
 int pinpotTangage=A5; //analog input 0
 int valpotTangage=0;
 int valmancheTangage=0;
 int mapTangage =0;
 int voltage = 8;
void setup() {
  Serial.begin(115200);
  pinMode(voltage,OUTPUT);
  digitalWrite(voltage,HIGH);


}
void loop() {

    char dataToSend[20];

    valpotRoulis = analogRead(pinpotRoulis);       

    valpotTangage = analogRead(pinpotTangage);       

    sprintf(dataToSend, "R%dE T%dE", valpotRoulis, valpotTangage);
    Serial.println(dataToSend);
    printf("%s\n", dataToSend);

    delay(10);

}

My code in QtCreator in RPi :

C++
void MainWindow::getPotentiometreFFB(){

  do{
    n = RS232_PollComport(cport_nr, (unsigned char *) str_recv, (int)BUF_SIZE);
    i++;
  }while(n <= 0 && i < 1000000);

    if(n > 0){
      str_recv[n] = 0;
      printf("Received %i bytes: '%s'\n", n, str_recv);



      position = -1;
        // Récupération roulis
         for (int j = 0; j < n ; j++)
         {
            if(str_recv[j]=='R') {
               position = j;
                break;
            }
            position = -1;
         }
         /////////////modif////////
         if (position != -1) {
             for (int k = 0;k<5;k++)
            {
             valeur_R[k] = str_recv[position+k];
            }


            char * ptrsuite_1Chaine = NULL;
            ptrsuite_1Chaine = strchr(valeur_R, 'E');
            if (ptrsuite_1Chaine != NULL)
                {
                    sscanf(valeur_R,"R%dE",&valRoulis);

                    valRoulis = minMaxPotentiometre(450, 650, valRoulis);

                    m_data.roll_cmd = mappingPotentiometreRoulis(valRoulis);
            }
        }


         position = -1;
        //Récupération tangage
        for (int j = 0; j < n ; j++)
        {
           if(str_recv[j]=='T') {
              position = j;
               break;
           }
           position = -1;
        }
        if (position != -1) {
            for (int k = 0;k<5;k++)
            {
               valeur_T[k] = str_recv[position+k];
            }

            char * ptrsuite_2Chaine = NULL;
            ptrsuite_2Chaine = strchr(valeur_T, 'E');

            if (ptrsuite_2Chaine != NULL)
            {
                    sscanf(valeur_T,"T%dE",&valTangage);

                    valTangage = minMaxPotentiometre(100, 340, valTangage);

                    m_data.pitch_cmd = -mappingPotentiometreTangage(valTangage);
            }



        }

      cout<< "Val roulis :" << m_data.roll_cmd << endl;
      cout<< "Val tangage :" << m_data.pitch_cmd << endl;

      ui->roll_cmd->setValue(m_data.roll_cmd);
      ui->pitch_cmd->setValue(m_data.pitch_cmd);

    }else{
        cout << "No data Roulis tangage" << endl;
    }


}


Feel free to ask if you guys need more info from me.

Thank you very much
AnswerRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Jochen Arndt25-Apr-18 0:17
professionalJochen Arndt25-Apr-18 0:17 
GeneralRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Ahmad ZULKIPLEE25-Apr-18 2:15
Ahmad ZULKIPLEE25-Apr-18 2:15 
GeneralRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Jochen Arndt25-Apr-18 3:06
professionalJochen Arndt25-Apr-18 3:06 
AnswerRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
Richard MacCutchan25-Apr-18 0:19
mveRichard MacCutchan25-Apr-18 0:19 
AnswerRe: Data packet was cut when sending from Arduino Uno to Raspberry Pi 3 in C++ Pin
leon de boer25-Apr-18 15:05
leon de boer25-Apr-18 15:05 
QuestionFrom framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 3:16
Vaclav_23-Apr-18 3:16 
AnswerRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt23-Apr-18 3:59
professionalJochen Arndt23-Apr-18 3:59 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 4:17
Vaclav_23-Apr-18 4:17 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt23-Apr-18 4:24
professionalJochen Arndt23-Apr-18 4:24 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 8:08
Vaclav_23-Apr-18 8:08 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt23-Apr-18 10:28
professionalJochen Arndt23-Apr-18 10:28 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_23-Apr-18 13:39
Vaclav_23-Apr-18 13:39 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt23-Apr-18 21:21
professionalJochen Arndt23-Apr-18 21:21 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_24-Apr-18 12:16
Vaclav_24-Apr-18 12:16 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt24-Apr-18 21:07
professionalJochen Arndt24-Apr-18 21:07 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Vaclav_25-Apr-18 3:36
Vaclav_25-Apr-18 3:36 
GeneralRe: From framebuffer to SPI via ioctl in Linux Pin
Jochen Arndt25-Apr-18 4:20
professionalJochen Arndt25-Apr-18 4:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.