How to Build a robot

Page 1

Workshop : How to build an autonomous mobile robot ? This document is prepared By Mr. RERNGWUT CHOOMUANG


วัตถุประสงค์ เอกสารฉบับนีใช้ เพือเผยแพร่ ความรู้ ทเกี ี ยวข้ องกับการสร้ างหุ่นยนต์ อัตโนมัติ และ การเขียนโปรแกรมควบคุมหุ่นยนต์ ให้ กับนักเรี ยนและครู ผู้ เตรียมเอกสารมิได้ ต้องการหวังผลประโยนช์ ทางการค้ าใดๆทังสิน

คําขอบคุณ • ขอขอบพระคุณทุกท่ านทีได้ ร่วมกันพัฒนา open source : arduino language เพือช่ วยเพิมองค์ ความรู้ ทางด้ านการเขียนโปรแกรมให้ แก่ นักเรี ยน ครู และผู้ทสนใจ ี • ขอขอบพระคุณเว็ปไซด์ ต่างๆ ทีเอือเฟื อรูปภาพ • ขออภัยถ้ าทางผู้เตรียมมิได้ อ้างอิงเว็ปไซด์ ของรู ปภาพให้ ครบถ้ วน เนืองจากความบกพร่ อง ของผู้เตรียมเอกสาร


Why build a robot? • Mechanics Learning • Electronics Learning • Programming • etc.


Mechanics Learning

Moment = can_weight * arm_length + arm_weight * 1/2 * arm_length

http://www.societyofrobots.com


Electronic Learning

http://hyperphysics.phy-astr.gsu.edu/hbase/hframe.html


Programming

http://www.woodburytech.com/


What are your motivations?


Conceptual Design Mechanical Design Electronics Design Robot Programming


Typical of a robot design

Software

Mechanics

Electronics


Mechanical design tools

Little Merlin


Mechanical Design

Side view

Top view

Front view


Mechanical Design (2)

Assembly


Electrical design tools

Little Merlin


Schematic Design


PCB Design

Top layer

Bottom layer

Top Silk


Tips : Power Supply Lead Acid

Lithium (Li-ion)

NiCad (Nickel Cadmium)

Alkaline

Fuel Cell

NiMH (Nickel Metal Hydride)


Software Tools

Little Merlin


Workshop

How to build a OBEC’s Robot v1.0 ?


Workshop : Part list Robot platform OBEC’s kit controller board v1.0 OBEC’s kit sensors OBEC’s kit actuators OBEC’s kit amplifier Tools Miscellaneous


Robot platform

Robot chassis

wheels

motors

Passive wheel


OBEC’s kit controller board v1.0


Sensors

Push button switch

IR reflector

GND SIGNAL VCC

LDR

Thermistor


Display & Sound GND SIGNAL VCC

Liquid Crystal Display (LCD)

Blue LED

Green LED

Buzzer Red LED


Amplifier for two dc motors

Control signal #1

DC Motor #1 Vm 5-36v ground

Control signal #2 OBEC’s kit amplifier board v1.0

DC Motor #2


Engineering tools

soldering gun

screw driver

Multi meter

Ruler cutter


Miscellaneous

Nuts & Bolts

Battery holder USB-wire type B

Glue tape

Battery 1.5v AA type

soldering lead


Let’s start…


Step 1:


Step 2 :


Step 3:


Step 4:

IR reflector

IR reflector


Step 5: Battery holder

Battery


Step 6:

Liquid Crystal Display (LCD)

OBEC’s kit controller board v1.0


Coffee break

http://www.publicdomainpictures.net/view-image.php?image=1476&picture=cup-of-coffee


Software tool : Open Source


Open Source : Arduino

URL : http://www.arduino.cc/


Install driver


Open Source : Arduino

Double Click


Arduino Software


Arduino Program Tool bar

Menu bar

Text editor

Text editor


Arduino Program : Menu bar


Arduino Program : Tool bar

Verify

Upload New

Serial Monitor Stop Open

Save


Arduino pin mapping


Workshop activity: a rough topics • Robot motion • Robot light seeking • Robot line following • Robot Wall following • Mini rescue robot


Activity1-3: a simple robot motion

Move forward /backward

Move s-cure Move square


Activity 1: Robot move forward/backward

Rotation: CCW Speed :100%

Rotation: CW Speed :100%

Rotation: CW Speed :100%

Rotation: CCW Speed :100%


Activity 1-3: overview of robot motion

Motor #1

OBEC’s kit amplifier board v1.0 OBEC’s kit controller board v1.0 Motor #2


Activity 1 : Robot move forward/backward

A simple flowchart of robot action


Activity 1 : Robot move forward/backward #include <OBECMotors.h> OBECMotors motors; void setup() { //nothing } void loop() { motors.setM1rotate(CCW); motors.setM1speed(100); motors.setM2rotate(CW); motors.setM2speed(100); delay(3000); motors.setM1rotate(CW); motors.setM1speed(100); motors.setM2rotate(CCW); motors.setM2speed(100); delay(3000); }


Activity 2 : Robot move s-curve

Rotation: CCW Speed :70%

Rotation: CCW Speed :100%

Rotation: CW Speed :100%

Rotation: CW Speed :70%


Activity 2 : Robot move s-curve

A simple flowchart of robot action


Activity 2 : Robot move s-curve

#include <OBECMotors.h> OBECMotors motors; void setup() { //nothing } void loop() { robot_fw(100, 70); delay(2000); robot_fw(70, 100); delay(2000); }

void robot_fw(int speed1, int speed2) { motors.setM1rotate(CCW); motors.setM1speed(speed1); motors.setM2rotate(CW); motors.setM2speed(speed2); }


Activity 3 : Robot move a square Time: 0.5 sec. Time: 3 sec. Rotation: CW Speed :100%

Time: 0.5 sec. Rotation: CW Speed :100%

Time: 3 sec. Time: 3 sec.

Rotation: CCW Speed :100%

Time: 0.5 sec.

Time: 3 sec.

Rotation: CW Speed :100%


Activity 3 : Robot move a square

A simple flowchart of robot action


Activity 3 : Robot move a square (2)

A simple flowchart of robot action


Activity 3 : Robot move a square #include <OBECMotors.h> OBECMotors motors; void setup() { //nothing } void loop() { robot_fw(100, 100); delay(3000); robot_tl(); delay(500); robot_fw(100, 100); delay(3000); robot_tl(); delay(500); robot_fw(100, 100); delay(3000); }

void robot_fw(int speed1, int speed2) { motors.setM1rotate(CCW); motors.setM1speed(speed1); motors.setM2rotate(CW); motors.setM2speed(speed2); }

void robot_tl() { motors.setM1rotate(CW); motors.setM1speed(100); motors.setM2rotate(CW); motors.setM2speed(100); }


Exercise


Activity 4-5: a robot light seeking


Activity 4: overview of a light sensors reading

Light sensors #1 Serial communication computer

OBEC’s kit controller board v1.0

Light sensors #2


Activity 4 : light sensor reading


Activity 4 : a light sensor reading int value=0; void setup() { Serial.begin(9600); } void loop() { value = analogRead(0); Serial.print("light sensor #1 value="); Serial.print(value,DEC); Serial.print(", "); Serial.print("light sensor #2 value="); value = analogRead(1); Serial.println(value,DEC); delay(20); }


Activity 5: overview of a robot light seeking Motor #1

Light sensors #1

OBEC’s kit amplifier board v1.0

OBEC’s kit controller board v1.0

Light sensors #2 Motor #2


Activity 5: a robot light seeking


Activity 5: a robot light seeking #include <OBECMotors.h> OBECMotors motors; int val1=0, val2=0, val3=0; int offset=50; void setup() { // nothing } void loop() { val1=analogRead(0); val2=analogRead(1); val3 = abs(val1-val2); if( val3 < offset ) { robot_fw(100,100); }

else if(val1 > val2) { robot_tl(); } else if(val1 < val2) { robot_tr(); } }


Activity 5: sub-routine of a robot light seeking void robot_fw(int speed1, int speed2) { motors.setM1rotate(CCW); motors.setM1speed(speed1); motors.setM2rotate(CW); motors.setM2speed(speed2); }

void robot_bw(int speed1, int speed2) { motors.setM1rotate(CW); motors.setM1speed(speed1); motors.setM2rotate(CCW); motors.setM2speed(speed2); }

void robot_tl() { motors.setM1rotate(CW); motors.setM1speed(100); motors.setM2rotate(CW); motors.setM2speed(100); }

void robot_tr() { motors.setM1rotate(CCW); motors.setM1speed(100); motors.setM2rotate(CCW); motors.setM2speed(100); }


Exercise


Activity 6: overview of a reflector sensors reading

Motor turn right

Motor move forward

Motor turn left


Activity 6: overview of a reflector sensors reading

Liquid Crystal Display (LCD) 16x2

Reflector sensor #1

OBEC’s kit controller board v1.0

Reflector sensor #2


Activity 6 : a reflector sensors reading


Activity 6: a reflector sensors reading

#include <LiquidCrystal.h> LiquidCrystal lcd(23, 22, 16, 17, 18, 19); int val1 = 0, val2=0; void setup() { Serial.begin(9600); lcd.begin(16, 2); lcd.clear(); lcd.print("Hello,OBEC's kit"); lcd.setCursor(0,1); }

void loop() { val1=analogRead(0); val2=analogRead(1); lcd.setCursor(0,1); lcd.print("#1 value is"); lcd.print(val1); lcd.setCursor(0,2); lcd.print("#2 value is"); lcd.print(val2); delay(20); }


Exercise


Activity 7: a robot line following


Activity 7: overview of a robot line following

Motor #1 Reflector sensor #1

OBEC’s kit amplifier board v1.0

OBEC’s kit controller board v1.0

Reflector sensor #2 Motor #2


Activity 7: a line following robot


Activity 7: a line following robot (2)


Activity 7: a line following robot

#include <OBECMotors.h> OBECMotors motors; int val1=0, val2=0; int threshold1=100, threshold2=100; void setup() { //nothing } void loop() { val1=analogRead(0); val2=analogRead(1); if((val1>threshold1) && (val2>threshold2)) { robot_fw(100,100); }

else if((val1<threshold1) && (val2<threshold2)) { robot_fw(100,100); } else if((val1>threshold1) && (val2<threshold2)) { robot_tr(); delay(100); } else if((val1<threshold1) && (val2>threshold2)) { robot_tl(); delay(100); } }


Activity 7: sub-routine of a robot line following void robot_fw(int speed1, int speed2) { motors.setM1rotate(CCW); motors.setM1speed(speed1); motors.setM2rotate(CW); motors.setM2speed(speed2); }

void robot_bw(int speed1, int speed2) { motors.setM1rotate(CW); motors.setM1speed(speed1); motors.setM2rotate(CCW); motors.setM2speed(speed2); }

void robot_tl() { motors.setM1rotate(CW); motors.setM1speed(100); motors.setM2rotate(CW); motors.setM2speed(100); }

void robot_tr() { motors.setM1rotate(CCW); motors.setM1speed(100); motors.setM2rotate(CCW); motors.setM2speed(100); }


Exercise


Activity 8: robot move pass a junction (LCD)

#2 check point #3 check point #1 check point #4 check point


Activity 8: overview of a robot move pass a junction (LCD) Liquid Crystal Display

Motor #1

Reflector sensor #1

OBEC’s kit amplifier board v1.0 OBEC’s kit controller board v1.0 Reflector sensor #2

Motor #2


Activity 8: a robot move pass a junction (LCD)


Activity 8: a robot move pass a junction (LCD)(2)


Activity 8: a robot move pass a junction (LCD) #include <OBECMotors.h> #include <LiquidCrystal.h> LiquidCrystal lcd(23, 22, 16, 17, 18, 19); OBECMotors motors; int val1=0, val2=0; int threshold1=400, threshold2=400; int cline=0; void setup() { lcd.begin(16, 2); } void loop() { val1=analogRead(0); val2=analogRead(1); if((val1>threshold1) && (val2>threshold2)) { robot_fw(100,100); }

else if((val1<threshold1) && (val2<threshold2)) { cline++; lcd.setCursor(0,1); lcd.print("cline ="); lcd.print(cline); robot_fw(100,100); } else if((val1>threshold1) && (val2<threshold2)) { robot_tr(); delay(100); } else if((val1<threshold1) && (val2>threshold2)) { robot_tl(); delay(100); } }


Exercise


Activity 9: Obstacle Avoidance (Beep)

Beep

Beep

Beep


Activity 9: overview of an Obstacle Avoidance (beep) Buzzer

Motor #1

Bumper switch #1

OBEC’s kit amplifier board v1.0 OBEC’s kit controller board v1.0

Motor #2

Bumper switch #2


Activity 9: Obstacle Avoidance (Beep)


Activity 9: Obstacle Avoidance (Beep) (2)


Activity 9: Obstacle Avoidance (Beep) #include <OBECMotors.h> #include <Switch.h> OBECMotors motors; Switch sw2(2), sw4(4); int melodyPin=22; int val1=0, val2=0; void setup() { //nothing } void loop() { val1=sw2.isPressed(); val2=sw4.isPressed(); if((val1==true) && (val2==true)) { tone(melodyPin, 10000, 200); delay(200); noTone(melodyPin); delay(200); robot_bw(100,100); }

else if((val1==false) && (val2==false)) { robot_fw(100,100); } else if((val1==true) && (val2==false)) { tone(melodyPin, 10000, 200); delay(200); noTone(melodyPin); delay(200); robot_tr(); delay(100); } else if((val1==false) && (val2==true)) { tone(melodyPin, 10000, 200); delay(200); noTone(melodyPin); delay(200); robot_tl(); delay(100); } }


Exercise


Activity 10: mini rescue robot This zone >= 60 This zone <60

This zone <40

This zone<20


System overview of a mini rescue robot Red LED

Green LED Blue LED

Temperature sensor Motor #1

Bumper switch #1

OBEC’s kit amplifier board v1.0

OBEC’s kit controller board v1.0 Bumper switch #2

Motor #2

Buzzer


Activity 10: a mini rescue robot


Activity 10: a mini rescue robot (2)


Activity 10: a mini rescue robot (3)


Activity 10: a mini rescue robot (4)


Activity 10: a mini rescue robot (5)


Activity 10: a mini rescue robot #include <OBECMotors.h> #include <Thermistor.h> #include <Switch.h> #include <LED.h> OBECMotors motors; Thermistor temp(2); Switch sw2(2), sw4(4); LED red(16), green(17), blue(18); double tempC; int val1=0, val2=0; int melodyPin=22; void setup() { // noting } void loop() { tempC = temp.getCelciusValue(); analyze_temperature(tempC); val1=sw2.isPressed(); val2=sw4.isPressed();

if((val1==false) && (val2==true)) { robot_fw(100,100); } else if((val1==false) && (val2==false)) { robot_tr(); delay(100); } else if((val1==true) && (val2==true)) { robot_tl(); delay(100); } else if((val1==true) && (val2==false)) { robot_tr(); delay(100); } }


Activity 10: sub-routine a mini rescue robot

void analyze_temperature(double temp) { if(temp<20) { red.off(); green.off(); blue.on(); } else if(temp<40) { red.off(); green.on(); blue.off(); }

else if(temp<60) { red.on(); green.off(); blue.off(); } else { red.on(); green.off(); blue.off(); tone(melodyPin,1000,200); delay(200); noTone(melodyPin); delay(200); } }


Exercise


References http://www.arduino.cc http://www.societyofrobots.com http://www.industrialsupplier.in/nuts-bolts-washers.html


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.