Click here to Skip to main content
15,867,568 members
Articles / Artificial Intelligence / Machine Learning
Article

How-To Intel® IoT Technology Code Samples: Line following robot in C++

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
20 Jun 2016CPOL7 min read 9.1K   6  
This line following robot application is part of a series of how-to Intel® IoT Technology code sample exercises using the Intel® IoT Developer Kit, Intel® Edison board, cloud platforms, APIs, and other technologies.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Get access to the new Intel® IoT Developer Kit, a complete hardware and software solution that allows developers to create exciting new solutions with the Intel® Galileo and Intel® Edison boards. Visit the Intel® Developer Zone for IoT.

This line following robot application is part of a series of how-to Intel® IoT Technology code sample exercises using the Intel® IoT Developer Kit, Intel® Edison board, cloud platforms, APIs, and other technologies.

From this exercise, developers will learn how to:

  • Connect the Intel® Edison board, which is a computing platform designed for prototyping and producing IoT and wearable computing products.
  • Interface with the Intel® Edison board IO and sensor repository using MRAA and UPM from the Intel® IoT Developer Kit, this a complete hardware and software solution to help developers explore the IoT and implement innovative projects.
  • Run these code samples in the Intel® System Studio IoT Edition (Eclipse* IDE for C/C++ and Java* development) for creating applications that interact with sensors and actuators, enabling a quick start for developing software for the Intel® Edison or Intel® Galileo board.
  • Set up a web application server to store line detection data using Azure Redis Cache* from Microsoft* Azure*, Redis Store* from IBM* Bluemix*, or ElastiCache* using Redis* from Amazon Web Services*, different cloud services for connecting IoT solutions including data analysis, machine learning, and a variety of productivity tools to simplify the process of connecting your sensors to the cloud and getting your IoT project up and running quickly.

What it is

Using an Intel® Edison board, this project lets you create a line following robot that:

  • continuously checks the line finder sensor;
  • moves forward if on the line, using stepper motors;
  • tries to pivot to find the line if not on it, using stepper motors;
  • logs events from the line finder sensor, using cloud-based data storage.

How it works

The line finder robot uses two attached motors to attempt to follow a line while keeping track of it with the Line Finder sensor. If on the line, it moves forward. Otherwise, it pivots in place, trying to locate the line, using the Line Finder sensor.

Optionally, it can also store system events using the Intel IoT Examples Datastore running in your own Microsoft* Azure*, IBM* Bluemix*, or AWS* account.

Hardware requirements

Grove* Robotics Kit containing:

  1. Intel® Edison board with an Arduino* breakout board
  2. Grove* Base Shield V2
  3. Grove* Line Finder
  4. Stepper Motor Controller & Stepper Motor (x2)

Software requirements

  1. Intel® System Studio IoT Edition (Eclipse* IDE for C/C++ and Java* development)
  2. Microsoft* Azure*, IBM* Bluemix*, or AWS* account

How to set up

To begin, clone the How-To Intel® IoT Technology code samples repository with Git* on your computer as follows:

$ git clone https://github.com/intel-iot-devkit/how-to-code-samples.git

Want to download a .zip file? In your web browser, go to https://github.com/intel-iot-devkit/how-to-code-samples and click the Download ZIP button at the lower right. Once the .zip file is downloaded, uncompress it, and then use the files in the directory for this example.

Adding the program to Eclipse*

In Eclipse*, select Import Wizard to import an existing project into the workspace as follows:

  1. From the main menu, select File > Import.
    Image 1
  2. The Import Wizard dialog box opens. Select General > Existing Project into Workspace and click Next.
    Image 2
  3. Click Select root directory and then the associated Browse button to locate the directory that contains the project files.
    Image 3
  4. Under Projects, select the directory with the project files you'd like to import and click OK and then Finish to import the files into Eclipse*.
    Image 4
  5. Your main .cpp program is now displayed in your workspace under the src folder.
    Image 5

Connecting the Grove* sensors

You need to have a Grove* Base Shield V2 connected to an Arduino*-compatible breakout board to plug all the Grove* devices into the Grove* Base Shield V2. Make sure you have the tiny VCC switch on the Grove* Base Shield V2 set to 5V.

You need to power the Intel® Edison board with the external power adapter that comes with your starter kit, or else substitute an external 12V 1.5A power supply. You can also use an external battery, such as a 5V USB battery.

In addition, you need a breadboard and additional 5V power supply to provide power to both the motors. Note: you need a separate battery or power supply for the motors. You cannot use the same power supply for both the Intel® Edison board and the motors, so you need either 2 batteries or 2 power supplies in total.

  1. Plug each of the stepper motor controllers into 4 pins on the Arduino* breakout board, for it to be able to be controlled. Connect stepper motor controller #1 to pins 4, 5, 6, and 7, and stepper motor controller #2 to pins 9, 10, 11, and 12. Connect both the controllers to ground (GND), to the 5V power coming from the Arduino* breakout board (VCC), and to the separate 5V power for the motors (VM).
    Image 6
  2. Plug one end of a Grove* cable into the Grove* Line Finder, and connect the other end to the D2 port on the Grove* Base Shield V2.

Intel® Edison board setup

This example uses the restclient-cpp library to perform REST calls to the remote data server. The code can be found in thelib directory. The restclient-cpp library requires the libcurl package, which is already installed on the Intel® Edison board by default.

Datastore server setup

Optionally, you can store the data generated by this sample program in a backend database deployed using Microsoft* Azure*, IBM* Bluemix*, or AWS*, along with Node.js*, and a Redis* data store.

For information on how to set up your own cloud data server, go to:

https://github.com/intel-iot-devkit/intel-iot-examples-datastore

Connecting your Intel® Edison board to Eclipse*

  1. In the bottom left corner, right-click anywhere on the Target SSH Connections tab and select New > Connection.
    Image 7
  2. The Intel® IoT Target Connection window appears. In the Filter field, type the name of your board.
    Image 8
  3. In the Select one of the found connections list, select your device name and click OK.
    Image 9
  4. On the Target SSH Connections tab, right-click your device and select Connect.
    Image 10

If prompted for the username and password, the username is root and the password is whatever you specified when configuring the Intel® Edison board.

Running the example with the cloud server

To run the example with the optional backend data store, you need to set the SERVER and AUTH_TOKEN environment variables. You can do this in Eclipse* as follows:

  1. From the Run menu, select Run Configurations.
    The Run Configurations dialog box is displayed.
  2. Under C/C++ Remote Application, click doorbell.
    This displays the information for the application.
  3. In the Commands to execute before application field, add the environment variables so it looks like this, except using the server and authentication token that correspond to your own setup:

    chmod 755 /tmp/line-follower; export SERVER="http://intel-examples.azurewebsites.net/logger/line-follower"; export AUTH_TOKEN="YOURTOKEN"
  4. Click Apply to save your new environment variables.

Now, when you run your program using the Run button, it should be able to call your server to save the data right from the Intel® Edison board.

Running the code on the Intel® Edison board

When you're ready to run the example, click Run at the top menu bar in Eclipse*.

Image 11

This compiles the program using the Cross G++ Compiler, links it using the Cross G++ Linker, transfers the binary to the Intel® Edison board, and then executes it on the board itself.

After running the program, you should see output similar to the one in the image below.

Image 12

For a complete list of the 18 How-To Intel® IoT Technology code samples in C++, go to this Intel® Developer Zone blog post 18 How-To Intel® IoT Technology Code Samples Now Available in C++.

For a complete list of the 18 How-To Intel® IoT Technology code samples in JavaScript*, go to this Intel® Developer Zone blog post Announcing 18 New How-To Intel® IoT Technology Code Samples.

For more details about this code sample, go to GitHub*.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
You may know us for our processors. But we do so much more. Intel invents at the boundaries of technology to make amazing experiences possible for business and society, and for every person on Earth.

Harnessing the capability of the cloud, the ubiquity of the Internet of Things, the latest advances in memory and programmable solutions, and the promise of always-on 5G connectivity, Intel is disrupting industries and solving global challenges. Leading on policy, diversity, inclusion, education and sustainability, we create value for our stockholders, customers and society.
This is a Organisation

42 members

Comments and Discussions

 
-- There are no messages in this forum --