Upload
lew-yew-ken
View
24
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Arduino is a very good programming language widely use for casual robotics.
Citation preview
Makeweekend Robotics
TANDEMIC
WE BUILD TECHNOLOGY TO MAKE THE WORLD A
BETTER PLACE
THANKS
The Challenges
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
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
Awesomeness Challenge
Autonomous - instructions from Arduino board
Winners...Make us go wow!Must work during the demo session
Prize for Speed Challenge (x5)
The 3pi robot is designed to excel in line-following and maze-solving competitions
Prize for Awesomeness challenge (X5)
Zumo Bot - To compete in sumo bot competitions.
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
Recommended Process
Program & buildCheck with Sky / ChrisTest in kiddie pool
The Agenda
• Arduino• Setup• IDE introduction• Arduino programming• Hardware setup• Useful things• Additional requirements• Further information
Arduino
Arduino
Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software.
Setup
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
IDE Introduction
Arduino IDE
Editor
BuildFlas
h
Error
Configuration
Configuration
Load Basic example
Arduino Programming
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
Example
C\C++ with Arduino
General:
• Statements are closed with a ;
• Curly brackets define a scope { }
http://arduino.cc/en/Tutorial/HomePage
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
C\C++ with Arduino
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
C\C++ with Arduino
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.
C\C++ with Arduino
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();
C\C++ with Arduino
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/
C\C++ with Arduino
C\C++ with Arduino
C\C++ with Arduino
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
C\C++ with Arduino
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
C\C++ with Arduino
Hardware Setup
Brushless motor
Propeller
Servo
LiPo-Battery
Sonar - Ultrasonic-Range-Finder
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
Useful Things
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
How to control brushless motors and servos
How to use the sonar
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
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)
Debug practise
• Print text: o Serial.print("TESTTEXT");o Serial.println("TESTTEXT")
;
• Print variableo Serial.print(variablename)
;o Serial.println(variablenam
e);
General tips
Good programmers are not reinventing the wheel, copy and paste is king!
But be careful,
and learn from your copies!
Additional requirements
Requirements
• Shut off engines after 10 seconds of full collision, sonar distance below 10cm
• Shut off engines after 3min of runtime
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
Further Information
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
Further information
• Controlling a brushless motor and ESC with Arduino:
http://techvalleyprojects.blogspot.com/2012/06/arduino-control-escmotor-tutorial.html
The URL for the forum
moot.it/makeweekened