Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4....

15
Microprocessors Tutorial 2: Arduino Robotics

Transcript of Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4....

Page 1: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Microprocessors Tutorial 2:Arduino Robotics

Page 2: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Agenda

1. Robot Anatomy2. Sensor Review3. PWM4. MAKE: Fade5. Motors 6. H Bridge7. Robot Control library8. MAKE: Robot react9. Challenge: Solve Maze10. Links

Page 3: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Robot Anatomy

Page 4: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Robot Anatomy

Page 5: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Sensor Review• Analog Arduino mapping: 0-5V 0-1023• 3 connections: V+, pin, GND• Serial Monitor:

• Use Serial.begin(9600) to start communication• Use custom function serialOutputValue(“msg”, value)

to see sensor value in serial monitor• This robot has IR range sensor: Outputs 0.0 - 2.6V (0-600 in Arduino) Peaks at 15cm, farther objects create lower voltageBUT code inverts relationship!

Example:• Example 1 Analog_in

Page 6: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Pulse Width Modulation• Duty cycle = percentage of time signal is positive in

square wave• Min-Max voltage: 0 – 5v

Min-Max Arduino mapping: 0 – 255• PWM pins have a ~ on Arduino

10% average

50% average

90% average

Page 7: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Make: Fade• Use analogWrite(pin, value) to fade light on/off

using for loop to vary value• Remember PWM range is 0-255• Recall LED connection:

long leg = positivesmall resistor in series necessary

• Use PWM to 1. fade the led from 0 to full in 5 seconds,2. hold for 2 secs,3. fade back down in 7 seconds.

• Then each loop would do it faster and faster or brighter and brighter!

Challenge: Fade Increments

Page 8: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Motors• They draw more current than USB/Arduino can supply

(40mA per pin, 200mA in total) so need another power supply: batteries• Current through in 1 direction turns them in 1 direction• More voltage = More speed, how to control voltage?

• Use electronically controlled switch (transistor) between motor and batteries

• Use PWM pin to control switch• Motors in this robot run on 4.5-7.0V and have a peak current of 1A.

Page 9: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

H- Bridge• Used to make 1 motor turn in either direction by

directing current• use 4 switches controlled by 2 signals

Page 10: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

H- Bridge• The IC we will use (SN754410N) has 2 H-Bridges to

control 2 motors

• PWM is used here at the enable pin to control speed

A

Page 11: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Robot Control Library• Written by Sebastien Parent-Charette last year• Get sensor values with

• updateSensorRangeState()• And values state_sensor_range_value• Display with serialOutputValue(“msg”, value)

• Change directions with • modifyMotorState(motor, direction, speed) • Followed by updateMotorState()

Example: • Example 3: Spin_in_a_Loop

Page 12: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

MAKE: Robot Move

MAKE: Robot React

• Change code in Example 3 so you are in control• For example, go forward 5s, stop, turn right 90˚,

forward, backwards, left 270 ˚ and come back.• Use modifyMotorState(motor, direction, speed)

updateMotorState()

• When you feel comfortable, add sensor information• Use Example 4: Wall stop, as a base

• Get sensor data with updateSensorRangeState()• Use state_sensor_range_value to decide on a move

Page 13: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

CHALLENGE: solve the maze!Create your own algorithm to beat the maze using

Example 0: TemplateOr start from our other example codes Example 4, 5, 6

Page 14: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

Useful Links

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

MAKE projects http://makezine.com/arduino/http://makezine.com/category/electronics/arduino/?post_type=projects

Jeremy Blum Tutorials (#5: motors and transistors)http://www.jeremyblum.com/category/arduino-tutorials/

Page 15: Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.

[email protected]

Questions? Comments? Suggestions?