66
Makeweekend Robotics

Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Embed Size (px)

DESCRIPTION

Arduino is a very good programming language widely use for casual robotics.

Citation preview

Page 1: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Makeweekend Robotics

Page 2: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

TANDEMIC

WE BUILD TECHNOLOGY TO MAKE THE WORLD A

BETTER PLACE

Page 3: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

THANKS

Page 4: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

The Challenges

Page 5: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

The Challenges

1. The Water Drone Challenge2. The Awesomeness Challenge

But pick something...

• That you can build in 1-2 days

• Where you can get the necessary supplies over the weekend

Page 6: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Water Drone Challenge

Launch into the waterFollow a course pathIn less than 10 minutes

Winners...Are fastestAutonomous, self-powered with the battery and

single motorDon't sink or explode, deviate from the course

Page 7: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Awesomeness Challenge

Autonomous - instructions from Arduino board

Winners...Make us go wow!Must work during the demo session

Page 8: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Prize for Speed Challenge (x5)

The 3pi robot is designed to excel in line-following and maze-solving competitions

Page 9: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Prize for Awesomeness challenge (X5)

Zumo Bot - To compete in sumo bot competitions.

Page 10: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Where you can find supplies

Outdoor hardware station - outsideAnything that is not electronicCutting and drilling stuff -- work bench outside

(wood, pipes, etc)

Food - outsideProgramming, soldering, electronics - at

your tables

Page 11: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Recommended Process

Program & buildCheck with Sky / ChrisTest in kiddie pool

Page 12: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Makeweekend Robotics

How2 Arduino + Hardware

Christopher Hrabia (Chris)[email protected]

Page 13: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

The Agenda

• Arduino• Setup• IDE introduction• Arduino programming• Hardware setup• Useful things• Additional requirements• Further information

Page 14: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Arduino

Page 15: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Arduino

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software.

Page 16: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Setup

Page 17: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Setup

• Install Arduino-IDEo Unzip arduino-1.0.4-windows.zip

• Insert the USB cable into the Arduino and your computer

• If the drivers are not automatically detected, you find them inside the extracted folder

• Open the Arduino.exe

Page 18: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

IDE Introduction

Page 19: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Arduino IDE

Editor

BuildFlas

h

Error

Page 20: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Configuration

Page 21: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Configuration

Page 22: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Load Basic example

Page 23: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Arduino Programming

Page 24: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Sketch

• A sketch is the name that Arduino uses for a program. It's the unit of code that is uploaded to and run on an Arduino board.

http://arduino.cc/en/Tutorial/Sketch

Page 25: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Example

Page 26: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

General:

• Statements are closed with a ;

• Curly brackets define a scope { }

http://arduino.cc/en/Tutorial/HomePage

Page 27: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Variables: Named place to store information of a specific type

• Different types: int, char, long, float,boolean

• Declare and define: int x;

• Store data on a variable: x=10;

• Use a variable:y=x+x;

http://www.arduino.cc/en/Reference/VariableDeclaration

Page 28: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 29: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Functions: Reusable/Recallable piece of code

• Functions define an own scope

• Declare and define:Name(Parametertype parametername, ...){

Functionbody}

• Call function:Name(variable or value to pass if any);

http://arduino.cc/en/Reference/FunctionDeclaration

Page 30: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 31: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Special functions:Setup:

The setup function is called once on power up of the Arduino. This is the place to initialize and setup your environment.

Loop:Loop is called endless in a "Loop" as long your device is powered. Here you place the program logic.

Page 32: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 33: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Objects: Objects combine functions and variables to an own stateful object, described by classes. The object behavior is defined by the functions, the state by the variable content.

• Created with declaration and definition similar to basic variable typesClassname objectname;

• Use . operator to access object variables and functions: objectname.function();

Page 34: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 35: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Control structures:Conditions:

• if (x<10) {...} else{...}Loops:

• while (x<10){...}

• for(int i=0; i<10;i++){...break;...continue;..}

• switch(variable){case 1: ... break;}

http://www.cplusplus.com/doc/tutorial/control/

Page 36: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 37: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 38: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 39: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Variable arrays: An array is a collection of variables that can be accessed with an index number.

Declaration and definition:int myInts[6];

Declaration, definition and initialization:int myPins[] = {2, 4, 8, 3, 6};int mySensVals[6] = {2, 4, -8, 3, 2};char message[6] = "hello";

Use: myInts[5]=myInts[4]+2;http://arduino.cc/en/Reference/Array

http://arduino.cc/en/Reference/Array

Page 40: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 41: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Libraries

• Libraries in the Arduino world are reusable code snippets, which usually encapsulate complex hardware access or algorithms

Install:

• Copy library directory into the libraries folder of your Arduino IDE

• Restart the IDE

• Use: Menu - Sketch - Import Library

http://arduino.cc/en/Reference/Libraries

Page 42: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

C\C++ with Arduino

Page 43: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Hardware Setup

Page 44: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Brushless motor

Page 45: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Propeller

Page 46: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Servo

Page 47: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

LiPo-Battery

Page 48: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Sonar - Ultrasonic-Range-Finder

Page 49: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Hardware setup

Signal

VCC 5V

GND

Brushless-Motor

ESC

Order

either way

ArduinoVin

GND

Pin9

ServoSignal

VCC 5V

GND

Pin10 5V GND

Sonar

GND ECHO TRG VCC

GND Pin12 Pin13 5V

Signal

VCC 5V

GND

Brushless-Motor

ESC

LiPo-Battery

Order

either way

- +

ArduinoVin

GND

Pin9

ServoSignal

VCC 5V

GND

Pin10 5V GND

Sonar

GND ECHO TRG VCC

GND Pin12 Pin13 5V

Page 50: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Useful Things

Page 51: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

How to control brushless motors and servos

• Brushless motors are controlled by ESC

• ESC and servos are controlled by a PWM signal

• Arduino Servo library generates PWM signals

• ESC will not use the full rangeof 180°

• For usage, check example code of Servo library

Page 52: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

How to control brushless motors and servos

Page 53: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

How to use the sonar

Page 54: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

How to deal with time

• Get timestamp in milliseconds:o int now = millis();

• Delay or wait for a while:o delay(1000);o Will not affect Servo/Brushless PWM

generation

Page 55: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Debug practise

• Use Serial Monitor to read write outs created by your device while it is connected to usb

• Serial Monitor: Arduino-IDE -> Tools -> Serial Monitor (CTRL+SHIFT+M)

Page 56: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Debug practise

• Print text: o Serial.print("TESTTEXT");o Serial.println("TESTTEXT")

;

• Print variableo Serial.print(variablename)

;o Serial.println(variablenam

e);

Page 57: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

General tips

Good programmers are not reinventing the wheel, copy and paste is king!

But be careful,

and learn from your copies!

Page 58: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Additional requirements

Page 59: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Requirements

• Shut off engines after 10 seconds of full collision, sonar distance below 10cm

• Shut off engines after 3min of runtime

Page 60: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Requirements

Design boat/vehicle

Assemble/Solder electronics

Program Drone

Quality control at help desk before plugging in

the battery

Test vehicle in water pool before inserting

electronics

Put everything together

Dry testing without propeller

First supervised test in pool without

propeller

Test with propeller in pool

Test in lake

Page 61: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Further Information

Page 62: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Further information

• Examples included in the Arduino IDE

• Arduino tutorials:

http://arduino.cc/en/Tutorial/Sketch

http://www.ladyada.net/learn/arduino/index.html

• Simple sonar example projects:

http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/

http://tutorial.cytron.com.my/2012/10/11/testing-ultrasonic-ranging-module-sn-hc-sr04/

• Sonar libararies:

https://code.google.com/p/arduino-new-ping/

http://freecode.com/projects/hc-sr04-ultrasonic-arduino-library

Page 63: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

Further information

• Controlling a brushless motor and ESC with Arduino:

http://techvalleyprojects.blogspot.com/2012/06/arduino-control-escmotor-tutorial.html

Page 64: Makeweekend 2013 Robotics - Arduino and Hardware Introduction

The URL for the forum

moot.it/makeweekened

Page 65: Makeweekend 2013 Robotics - Arduino and Hardware Introduction
Page 66: Makeweekend 2013 Robotics - Arduino and Hardware Introduction