Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Intel Galileo Blueprints

You're reading from   Intel Galileo Blueprints Discover the true potential of the Intel Galileo board for building exciting projects in various domains such as home automation and robotics

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781785281426
Length 192 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Marco Schwartz Marco Schwartz
Author Profile Icon Marco Schwartz
Marco Schwartz
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Setting Up the Galileo Board and the Development Environment FREE CHAPTER 2. Creating a Weather Measurement and Data Logging Station 3. Controlling Outputs Using the Galileo Board 4. Monitoring Data Remotely 5. Interacting with Web APIs 6. Internet of Things with Intel Galileo 7. Controlling Your Galileo Projects from Anywhere 8. Displaying the Number of Unread Gmail E-mails on an LCD Screen 9. Automated Remote Gardening with Intel Galileo 10. Building a Complete Home Automation System 11. Building a Mobile Robot Controlled by the Intel Galileo Board 12. Controlling the Galileo Board from the Web in Real Time Using MQTT Index

Autonomous navigation


Now that we are sure that our robot is correctly wired, it's time to write an application for moving it around while avoiding obstacles in front of the robot. Here is the complete code for this part:

// Motor pins
int speed_motor1 = 6;  
int speed_motor2 = 5;
int direction_motor1 = 7;
int direction_motor2 = 4;

// Sensor pin
int distance_sensor = A0;

void setup(void)
{  
  // Start Serial
  Serial.begin(115200);
  
  // Go forward by default
  forward();
}

void loop() {  
  
  // Measure distance
  int distance = measure_distance(distance_sensor);
  
  // If obstacle in front
  if (distance < 10) {
  
    // Go backward
    backward();
    delay(2000);
    
    // Turn around
    left();
    delay(500);
    
    // Go forward again
    forward();
  }
  
}

// Forward
int forward() {
  
  send_motor_command(speed_motor1,direction_motor1,200,1);
  send_motor_command(speed_motor2,direction_motor2,200,1);
  return 1;
}

// Backward
int backward() {
  
  send_motor_command...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image