4 Replies Latest reply on Jan 12, 2016 4:52 PM by PabloM_Intel

    Intel galileo gen 1 board

    gopal1096

      hi. I am trying to measure speed with sharp IR distance sensor. But, I am unable to get accurate results. I am facing problems with taking time.I am using MRAA library and I am using putty with CPP coding.

       

          


              #include <mraa.hpp>    

               #include <iostream>

              #include <iomanip>

              #include<math.h>

              #include<sys/time.h>

              #include <unistd.h>

              #define VOLTS_PER_UNIT 0.0049

             

              using namespace std;

       

       

              double distance()

              {

                      uint16_t     adc_value;

                      double          volts;

                      double          d;

                      mraa::Aio*a3;

                      a3= new mraa::Aio(3);

                      adc_value       = a3 -> read();

                      volts           = adc_value * VOLTS_PER_UNIT;

                      d               = 60.495 * pow(volts, - 1.1904) ;

                      return d;

              }

       

       

              double timedifference_msec(struct timeval t0, struct timeval t1)

              {

          return (((t1.tv_sec - t0.tv_sec)*1000000) +(t1.tv_usec - t0.tv_usec))/1000;

              }

       

       

                      int main()

                      {

                      double  d1, d2,diff_dis;

                      double   speed;

                      struct timeval t0;

                      struct timeval t1;

                      double  t;

                      for(;;)

                      {

                      d1= distance();

                      cout<<"Distance"<<d1<<"CM"<<"\t";

                      gettimeofday(&t0, 0);

                      usleep(40000);

                      d2 = distance();

                      gettimeofday(&t1, 0);

                      t= (timedifference_msec(t0, t1))/1000;

                      diff_dis= abs(d1-d2);

      speed= diff_dis/t;

                      cout<< setprecision(3);

                      cout<< "Speed"<< speed<<"CM/Sec" <<"\n";

                      }

                      return MRAA_SUCCESS;

                      }

        • 1. Re: Intel galileo gen 1 board
          PabloM_Intel

          Hi gopal1096,

           

          We would appreciate if you could answer the following questions.

          • Could you please tell us which sensor you are using?
          • Which image are you using on your Galileo?
          • How are you connecting the IR sensor to the board?
          • Which version of MRAA are you using?

           

          I would also suggest you to check this guide which uses a similar proximity sensor, it can be helpful as a reference document (The Arduino board in the image should be interpreted as Galileo board).

           

          Regards,

          PabloM_Intel

          • 2. Re: Intel galileo gen 1 board
            gopal1096

            Hi....

            I am using Sharp 2Y0A02 F distance senosr and  mraa 0.8.1  devkit 2015.0.010 version. I connected sensor to analog pin 3( a3). Since the the Galileo runs slower than the arduino. I want to measure the exact time at each instant to get the accurate speed. right now I am not getting the exact time.oscill_arduinogalileo.jpg

            • 3. Re: Intel galileo gen 1 board
              BenKissBox

              Hi Gopal,

               

              take care of some of your assumptions. The Galileo does not run slower than the Arduino. It runs much, much faster, but in a complete different way.

               

              Arduino Uno or Mega : 8 bits processor running at 16MHz without operating system

              Galileo : 32 bits processor running at 400MHz with Linux

               

              You have to understand that the Galileo does not read the ADC in the same manner as the Arduino (it looks the same from programmer point of view, because of the library, but under the hood, it's completely different)

              On the Arduino, the ADC output is a simple register that is read directly by your program without any external access by the CPU core using the internal databus. It takes one or two CPU cycles and it's done.

              On the Galileo, the ADC is read over the SPI. So it takes time to retrieve the data, since it's a serial communication scheme. Moreover, the SPI communication interface can not be accessed directly from your code, because Linux is in the game, and it takes care of possible concurrent access (Linux is multitasking, do not forget it). The Linux kernel makes the SPI interface appear as a file for the library. That means that any attempt to read an analog input is in fact : opening a "file" (every device is a file with Linux), send a command, wait for the answer, close the file. This is extremely fast even if it appears as heavy to do. The problem is that you do not control when the Linux kernel will really read the analog value.

               

              That's probably where you have a problem (I do not know the sensor you use, so I can not guarantee that it is the explanation). If you need to measure precisely the time difference between two analog inputs, the Linux kernel will add some uncontrolled jitter and you will get false readouts. If it's the case with this sensor, then you will need to use a AVR based Arduino, on which there is no operating system and on which you can control very tightly the timing

               

              Benoit

              1 of 1 people found this helpful
              • 4. Re: Intel galileo gen 1 board
                PabloM_Intel

                Hi gopal1096,

                 

                Just as BenKissBox said, the conditions working with an Arduino board and an embedded platform running Linux or any other OS are quite different. However, among the things that you can try to improve your results would be to update mraa, update 0.9.0 is already available.

                 

                Regards,

                PabloM_Intel