6 Replies Latest reply on Mar 17, 2017 2:51 PM by Intel Corporation

    QT C++ to intel system studio iot edition c++

    JerwinPrabu

      I just started Intel system studio IOT c++ programming for Intel Edison Board. Earlier I have developed c++ programming in ARM board with QT Creator IDE. Now, I am using Intel Edison board for creating Autonomous Robot. Here libraries are different from other processor. I want to develop similar function in Intel system studio IOT. Is it possible to develop ? I didn't get any sample coding for websocket. Is it possible to use websocket in Intel system studio IOT edition ? because everywhere mentioned Intel XDK with websocket. I have a confusion.

      For example If I am using 2 DC motor for my Robot, how to write a code and how to differentiate Digital and Analog pins? Digital input and digital output ? I got stuck trying to understand the motor control for the DC motor. I've tried to look up resources but can't find one that adequately explains my problem. I can't understand. I have attached sample code. How to create a function declaration in Intel system studio IOT edition ?

      <

          pinMode(Motr1A, OUTPUT); // Right Motor Pins assignment
          pinMode(Motr1B, OUTPUT);
          pinMode(Motr1E, OUTPUT);

          pinMode(Motr2A, OUTPUT); // Left Motor Pins assignment
          pinMode(Motr2B, OUTPUT);
          pinMode(Motr2E, OUTPUT);

          softPwmCreate(Motr1E,0,50); // PWM Initialization
          softPwmCreate(Motr2E,0,50);  // PWM Initialization

      void Motion::Forward_Manual_Motion()
      {
          digitalWrite(Motr1A,HIGH);
          digitalWrite(Motr1B,LOW);
          digitalWrite(Motr2A,HIGH);
          digitalWrite(Motr2B,LOW);
          softPwmWrite(Motr2E, 15);
          softPwmWrite(Motr1E, 15);
      }

      void Motion::Left_Manual_Motion()

      {
          digitalWrite(Motr1A,HIGH);
          digitalWrite(Motr1B,LOW);
          digitalWrite(Motr2A,LOW);
          digitalWrite(Motr2B,HIGH);
          softPwmWrite(Motr2E,15);
          softPwmWrite(Motr1E,15);
      }

      void Motion::Right_Manual_Motion()
      {
          digitalWrite(Motr1A,LOW);
          digitalWrite(Motr1B,HIGH);
          digitalWrite(Motr2A,HIGH);
          digitalWrite(Motr2B,LOW);
          softPwmWrite(Motr2E,15);
          softPwmWrite(Motr1E,15);

      }

      For Sensor (For PIN declaration & ISR)

      #define TRIGGER_LEFT 7      // GPIO_7
      #define ECHO_LEFT 15        // GPIO_8

      uint32_t Start_Left=0,Stop_Left=0;
      uint32_t Time_Diff_Left=0;
      float Range_Left=0;
      volatile int Flag_Left=0;

          pinMode(TRIGGER_LEFT,OUTPUT);             // Left Pins assignment
          pinMode(ECHO_LEFT,INPUT);
          pullUpDnControl(ECHO_LEFT,PUD_DOWN);

      float SensorDistance::LeftDistance() // Sonar function for left distance calculation for SensorDistance class
      {
                  Start_Left=0;
                  Stop_Left= 0;
                  Flag_Left= 0;
                  digitalWrite(TRIGGER_LEFT,0);
                  delayMicroseconds(1);
                  digitalWrite(TRIGGER_LEFT,1);
                  delayMicroseconds(10);
                  digitalWrite(TRIGGER_LEFT,0);
                  return Range_Left;
      }

      void myInterruptleft(void) // Interrupt routine for left distance
      {                     // Called whenever the input pin toggles
          uint32_t timeTempleftultra=micros();
          if(Flag_Left==0) // first toggle? note the time
            {
                  Start_Left=timeTempleftultra;
                  Flag_Left=1;
            }
          else // second toggle? compute the distance
            {
                  Stop_Left=timeTempleftultra;
                  Flag_Left=0;
                  Time_Diff_Left=Stop_Left-Start_Left;
                  Range_Left=Time_Diff_Left/58.;
             }
        }

      For Websocket (cloud connected)

      void EchoClient::onConnected() //slot function to connect another slot function to receive data
      {
          if (!m_debug) //condition check for connection is there
          qDebug() << "WebSocket connected";
          connect(&m_webSocket, &QWebSocket::textMessageReceived,this, &EchoClient::onTextMessageReceived); //connect to another slot function
          //m_webSocket.sendTextMessage(QStringLiteral("Hello, world!"));
      }

      >

      How to change ? How to declare pin assignment ? Kindly help us to solve the problem. Awaiting for your reply.

        • 1. Re: QT C++ to intel system studio iot edition c++
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi JerwinPrabu,

          Thank you for contacting us. We’ll try to help you clear any doubts you may have.
          First, you’re right in thinking that libraries and code used in an ARM board won’t work on the Edison. This is because the architecture of both boards is different, so using the same code and libraries will likely produce incompatibility errors.

          The best approach is to start your project with the Edison using the resources available. The default libraries for the Intel® System Studio IoT Edition are MRAA and UPM. With these libraries you can create your own code to use the DC motors. If you take a look at https://github.com/intel-iot-devkit/upm , you can find the API documentation for the languages available and a list of supported UPM libraries and sensors. You can find the main link to the MRAA documentation here https://iotdk.intel.com/docs/master/mraa/ . Using different MRAA functions will allow you write your code and easily declare digital and analog pins and inputs and outputs.

          In regards to using websockets, I found a very useful guide: https://medium.com/@monkeytypewritr/control-your-intel-edison-in-realtime-with-websockets-f16e49b2b2c8#.ywe5j13jm . It’ll show you how to install the libraries that allow Websocket communication.

          Let us know if you found this useful.

          Regards,
          -Sergio A
           

          • 2. Re: QT C++ to intel system studio iot edition c++
            JerwinPrabu

            Dear Sergio A,

             

            Thanks for your favourable response. When I was started programming, I saw those libraries are already installed. I have confused because, they have given some specific sensors for upm library. whether that is applicable for all types of sensors or given sensors ? Already, I have referred those GitHub samples. I hope you will understand what problem I am facing with this examples. You have mentioned "Using different MRAA functions will allow you write your code and easily declare digital and analog pins and inputs and outputs".

             

            For example they have given HCSR04 Ultrasonic programming sample

            <

            upm::HCSR04 *sonar = NULL;

             

            void sig_handler(int signo)

            {

                printf("got signal\n");

                if (signo == SIGINT) {

                    printf("exiting application\n");

                    sonar->m_doWork = 1;

                }

            }

             

            //! [Interesting]

            int main(int argc, char **argv)

            {

                sonar = new upm::HCSR04(5, 6);

                signal(SIGINT, sig_handler);

                sleep(1);

             

                for(;;){

                    std::cout << "get distance" << std::endl;

                    double distance = sonar->getDistance(CM);

                    std::cout << "distance " << distance << std::endl;

                    sleep(5);

                }

                delete sonar;

                return 0;

            }

            upm::HCSR04 *sonar = NULL;

             

            void sig_handler(int signo)

            {

                printf("got signal\n");

                if (signo == SIGINT)

            {

                    printf("exiting application\n");

                    sonar->m_doWork = 1;

                }

            }

             

             

            //! [Interesting]

            int main(int argc, char **argv)

            {

                sonar = new upm::HCSR04(5, 6);

                signal(SIGINT, sig_handler);

                sleep(1);

             

                for(;;){

             

                    std::cout << "get distance" << std::endl;

                    double distance = sonar->getDistance(CM);

                    std::cout << "distance " << distance << std::endl;

                    sleep(5);

                }

                delete sonar;

                return 0;

            }

            >

             

            If you consider this given sample how can we understand digital input or output pin declaration, for echo, trigger pin declaration, without command how can we identify. I have give my sample code also, just compare, how can I differentiate ?

             

            <

            #define TRIGGER_LEFT 7      // GPIO_7

            #define ECHO_LEFT 15        // GPIO_8

             

            uint32_t Start_Left=0,Stop_Left=0;

            uint32_t Time_Diff_Left=0;

            float Range_Left=0;

            volatile int Flag_Left=0;

             

                pinMode(TRIGGER_LEFT,OUTPUT);             // Left Pins assignment

                pinMode(ECHO_LEFT,INPUT);

                pullUpDnControl(ECHO_LEFT,PUD_DOWN);

             

              float SensorDistance::LeftDistance() // Sonar function for left distance calculation for SensorDistance class

            {

                        Start_Left=0;

                        Stop_Left= 0;

                        Flag_Left= 0;

                        digitalWrite(TRIGGER_LEFT,0);

                        delayMicroseconds(1);

                        digitalWrite(TRIGGER_LEFT,1);

                        delayMicroseconds(10);

                        digitalWrite(TRIGGER_LEFT,0);

                        return Range_Left;

            }

             

             

            void myInterruptleft(void) // Interrupt routine for left distance

            {                     // Called whenever the input pin toggles

                uint32_t timeTempleftultra=micros();

                if(Flag_Left==0) // first toggle? note the time

                  {

                        Start_Left=timeTempleftultra;

                        Flag_Left=1;

                  }

                else // second toggle? compute the distance

                  {

                        Stop_Left=timeTempleftultra;

                        Flag_Left=0;

                        Time_Diff_Left=Stop_Left-Start_Left;

                        Range_Left=Time_Diff_Left/58.;

                   }

              }

            >

             

            You have given this link  https://medium.com/@monkeytypewritr/control-your-intel-edison-in-realtime-with-websockets-f16e49b2b2c8#.ywe5j13jm  websocket communication, I have seen that link earlier. They explained and given sample code for Intel XDK node.js javascript code for websocket communication. I didn't get any sample for Intel system studio c++ development. I hope you can understand the problem statement. Kindly help us to solve the problem, move further. A waiting for your possible response.

            • 3. Re: QT C++ to intel system studio iot edition c++
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              Hi

              Thanks for your reply.

              I’ve some questions and suggestions about some of your statements. Please see below:

              - “That is applicable for all types of sensors or given sensors” ?
              If you’re asking if this is the complete list of sensors supported then yes. That is the list of UPM libraries that can be used.

              -I see you mention you want to use the HCSR04. You can see the library for this sensor in the UPM github here https://github.com/intel-iot-devkit/upm/tree/master/src/hcsr04 . You’ll find valuable information in the .cxx and .hpp files

              - How can we understand digital input or output pin declaration, for echo, trigger pin declaration, without command how can we identify.
              From this message I understand that you want to have the same functions from the below sample code, and use them, or similar ones, in the code above, is this correct? Have you seen:
              https://iotdk.intel.com/docs/master/mraa/gpio_8h.html
              https://iotdk.intel.com/docs/master/mraa/classmraa_1_1_gpio.html
              Here you can find the functions you can use for gpios.

              I looked at the sample codes in the Intel System Studio and there’s no example about websockets in C++. We haven’t tried to import a websocket library in C++, so we can’t assure you this will work as expected, but you can check online for some options, such as https://github.com/eidheim/Simple-WebSocket-Server

              Regards,
              -Sergio
               

              1 of 1 people found this helpful
              • 4. Re: QT C++ to intel system studio iot edition c++
                Intel Corporation
                This message was posted on behalf of Intel Corporation

                Hi,

                Do you still need assistance with this thread?

                Regards,
                -Sergio A
                 

                • 5. Re: QT C++ to intel system studio iot edition c++
                  JerwinPrabu

                  Hi Sergio A,

                   

                           Thanks for your continuous support. I saw everything, whatever given by you. Still I am facing problem for multi threading, declaration, Library.  Just I would like to discuss with you in detail. Because I can't post source code in here.

                   

                           Can I get your email id for further discussion. That will help me solve problem easily, we can discuss about exact problem.

                  • 6. Re: QT C++ to intel system studio iot edition c++
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    Sure, if you want to receive support through email, you just have to fill this form https://supporttickets.intel.com/?lang=en-US . This way you’ll be able to share files with us privately. Once the form is filled, it’ll create a service ticket where we’ll continue to assist you.

                    Regards,
                    -Sergio