arduino robot

Upload: mafas-munawfar

Post on 02-Jun-2018

240 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/10/2019 Arduino Robot

    1/17

    INTRODUCTION TO AI

    N45 Avoidance Robot

    Design Document

    Nicola Gordon 11012129

    1/25/2014

  • 8/10/2019 Arduino Robot

    2/17

  • 8/10/2019 Arduino Robot

    3/17

    2 | P a g e

    GoalThe goal for my project was to make a robot as cheap as possible to build and run, yet still

    capable of having its own personality. The robot will not be a remote-controlled botit will

    think for its self, trying to avoid obstacles and determine its own direction.

    ResearchInitial research was conducted into obstacle avoidance robots and robotics in general. A

    copy of the research presentation slides that I presented is located in Appendix A.

  • 8/10/2019 Arduino Robot

    4/17

    3 | P a g e

    Project Solution Block Diagram

    Project Flow Chart

  • 8/10/2019 Arduino Robot

    5/17

    4 | P a g e

    Pseudo CodeSet constants Right Forward at 0oSet constants Right Backward at 180oSet constants Left Forward same as Right BackwardSet constants Left Backward same as Right Forward

    Set constants Right Motor at 90o

    Set constants Left Motor at 90oSet constants for ping)))Set threshold for obstacles (in cm)Set distances on either sideSet constants for motorsSet time it takes to receive PING))) signal

    setup()attach motors to pins 10 and 11

    loop()Set constant for Forward Distance equals ping sensorIf distance forward is more than the thresholdMove ForwardelseIf distance forward is blockedTurn off motorsDelay for a few seconds to thinkTurn to the left and scanTurn to the right and scanCompare the distance

    compareDistance()if left Distance more than right DistanceTurn leftelse if (right Distance less than leftDistance)Turn rightelseif they are equally obstructedturn 180 degreeslong ping()Send out PING))) signal pulseGet duration it takes to receive echo

    Convert duration into distance

  • 8/10/2019 Arduino Robot

    6/17

    5 | P a g e

    Concept Art

    Circuit Wiring Diagram

  • 8/10/2019 Arduino Robot

    7/17

    6 | P a g e

    Breadboard Diagram

  • 8/10/2019 Arduino Robot

    8/17

    7 | P a g e

    Testing the ServosPlease visit blog for videos of testing of servos.

    Ping))) Ultra-Sonic SensorWhat is it?The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats or dolphins

    do. It offers excellent range accuracy and stable readings in an easy-to-use package.

    I ordered a 4 pin ultra-sonic sensor from china for only 1.00 including postage and only had

    to wait 21 days for it to arrive. Once I received I looked at the data sheet to work out what

    pins done what.

    Using the HC-SR04 with an ArduinoThere is an Arduino library for the HC-SR04 that offers two ways to use the sensor, See

    Appendix B for the 3 Ping))) ultra-sonic data sheet.

    The library includes 3 functions that I will use:

    1. Ultrasonic(int TP, int EP)

    This is an initial function for ultrasonic ranging module, choose the pins for module TRIG and

    ECHO pin. For example:

    Ultrasonic (13,12);

    Defines the digital pin 13 of Arduino as the TRIG pin of HC-SR04 and pin 12 for the ECHO

    pin.

  • 8/10/2019 Arduino Robot

    9/17

    8 | P a g e

    2. long Timing()

    This function triggers the ultrasonic module and returns the duration that the ECHO pin was

    held high. For example:

    long time; Ultrasonic hcsr; time = hcsr.Timing();

    The distance of the object corelates to the time the ECHO pin is held high. The distance

    formula is:

    Distance = ((Duration of high level)*(Sonic :340m/s))/2

    3. long Ranging(int sys) (sys : CM / INC)

    As I dont want to change the time into distance, this function helps you get the distance

    immediately. This function has a parameter (using CM or ICN) that shows the distance in

    centimetres or inches. This function will call Timing() and you dont need to use the Timing()

    before it. For example:

    long distance; Ultrasonic hcsr; distance = hcsr.Ranging(CM);

    returns the distance in centimetres.

    Testing the Sensor

  • 8/10/2019 Arduino Robot

    10/17

    9 | P a g e

    Constructing a body

    Adding the Arduino Uno

    Lucky Find Old RC Car no Remote

  • 8/10/2019 Arduino Robot

    11/17

    10 | P a g e

    Motor ShieldThe motor shield can drive up to 4 DC motors bi-directionally. That means they can be

    driven forwards and backwards. The speed can also be varied at 0.5% increments using the

    high-quality built in PWM. This means the speed is very smooth and won't vary!

    Note that the H-bridge chip is not meant for driving loads over 0.6A or that peak over 1.2A sothis is for smallmotors. Check the datasheet for information about the motor to verify its OK.

    To connect a motor, simply solder two wires to the terminals and then connect them to either

    theM1, M2, M3,or M4. Then follow these steps in your sketch

    Make sure you #include

    Create the AF_DCMotor object with AF_DCMotor(mo tor#, frequency), to setup the motor

    H-bridge and latches. The constructor takes two arguments.

    The first is which port the motor is connected to, 1, 2, 3or 4.

    f requencyis how fast the speed controlling signal is.For motors 1 and 2 you can choose MOTOR12_64KHZ,MOTOR12_8KHZ,

    MOTOR12_2KHZ, orMOTOR12_1KHZ. A high speed like 64KHzwont be audible but a low

    speed like 1KHz will use less power. Motors 3 & 4 are only possible to run at 1KHz and will

    ignore any setting given

    Then you can set the speed of the motor using setSpeed(speed)where the speedranges

    from 0 (stopped) to 255 (full speed). You can set the speed whenever you want.

    To run the motor, call run(direct ion)wheredirect ionis FORWARD, BACKWARDor

    RELEASE. Of course, the Arduino doesn't actually know if the motor is 'forward' or

    'backward', so if you want to change which way it thinks is forward; simply swap the twowires from the motor to the shield.

  • 8/10/2019 Arduino Robot

    12/17

    11 | P a g e

    Modifying the RCThe first thing I done was unconnected all wires, there was three wires in total, two for the

    motors and one for the antenna for the controller. As I did not have any controllers I just took

    it all apart and added in my own motors with the Arduino. Instead of throwing the old brains

    out and purchasing a battery compartment, I used the RCs battery component to power the

    Arduino and motors.

    Testing all components togetherPlease visit blog to see all the testing videos.

    Source CodeThe final source code can be found in appendix C.

    P.I.M.P My Ride

    Once all the components were in place and working correct I purchased some spray paintsand letter stencils and started to customised my robot.

    Goal achievedOverall the goal I set myself at the start of the project has been 98% achieved, the only

    missing component was an on/off switch.

  • 8/10/2019 Arduino Robot

    13/17

    12 | P a g e

    Bibliography

    Book:

    Karvinen, K, Karvien, T. 2011, Make: Arduino Bots and Gadgets, Maker Media, Inc, USA

    Websites:

    Arduino Playgroundhttp://playground.arduino.cc/[Last accessed 03 January 2014]

    Hacking RC Carhttp://www.instructables.com/id/Autonomous-Control-of-RC-Car-Using-

    Arduino/[Last accessed 03 January 2014]

    Lady Adahttp://www.ladyada.net/make/mshield/[Last accessed 13 January 2014]

    Lets make robotshttp://letsmakerobots.com/node/26905 [Last accessed 10 January 2014]

    Make ICT

    Workshophttp://cratel.wichita.edu/blogs/eecsseniordesignspring2013fall2013/files/2013/02/

    Hacking-a-RC-Car-(1).pdf[Last accessed 10 January 2014]

    Maker Shedhttp://www.makershed.com/Articles.asp?ID=263[Last accessed 06 January

    2014]

    Parallaxhttp://www.parallax.com/sites/default/files/downloads/28015-PING-Sensor-Product-

    Guide-v2.0.pdf [Last accessed 13 January 2014]

    Robot Tutorials using the Arduinohttp://arthursrobotorial.blogspot.co.uk/[Last accessed 13

    November 2013]

    http://playground.arduino.cc/http://playground.arduino.cc/http://playground.arduino.cc/http://www.instructables.com/id/Autonomous-Control-of-RC-Car-Using-Arduino/http://www.instructables.com/id/Autonomous-Control-of-RC-Car-Using-Arduino/http://www.instructables.com/id/Autonomous-Control-of-RC-Car-Using-Arduino/http://www.instructables.com/id/Autonomous-Control-of-RC-Car-Using-Arduino/http://www.ladyada.net/make/mshield/http://www.ladyada.net/make/mshield/http://www.ladyada.net/make/mshield/http://letsmakerobots.com/node/26905http://letsmakerobots.com/node/26905http://letsmakerobots.com/node/26905http://cratel.wichita.edu/blogs/eecsseniordesignspring2013fall2013/files/2013/02/Hacking-a-RC-Car-%281%29.pdfhttp://cratel.wichita.edu/blogs/eecsseniordesignspring2013fall2013/files/2013/02/Hacking-a-RC-Car-%281%29.pdfhttp://cratel.wichita.edu/blogs/eecsseniordesignspring2013fall2013/files/2013/02/Hacking-a-RC-Car-%281%29.pdfhttp://cratel.wichita.edu/blogs/eecsseniordesignspring2013fall2013/files/2013/02/Hacking-a-RC-Car-%281%29.pdfhttp://www.makershed.com/Articles.asp?ID=263http://www.makershed.com/Articles.asp?ID=263http://www.makershed.com/Articles.asp?ID=263http://www.parallax.com/sites/default/files/downloads/28015-PING-Sensor-Product-Guide-v2.0.pdfhttp://www.parallax.com/sites/default/files/downloads/28015-PING-Sensor-Product-Guide-v2.0.pdfhttp://www.parallax.com/sites/default/files/downloads/28015-PING-Sensor-Product-Guide-v2.0.pdfhttp://www.parallax.com/sites/default/files/downloads/28015-PING-Sensor-Product-Guide-v2.0.pdfhttp://arthursrobotorial.blogspot.co.uk/http://arthursrobotorial.blogspot.co.uk/http://arthursrobotorial.blogspot.co.uk/http://arthursrobotorial.blogspot.co.uk/http://www.parallax.com/sites/default/files/downloads/28015-PING-Sensor-Product-Guide-v2.0.pdfhttp://www.parallax.com/sites/default/files/downloads/28015-PING-Sensor-Product-Guide-v2.0.pdfhttp://www.makershed.com/Articles.asp?ID=263http://cratel.wichita.edu/blogs/eecsseniordesignspring2013fall2013/files/2013/02/Hacking-a-RC-Car-%281%29.pdfhttp://cratel.wichita.edu/blogs/eecsseniordesignspring2013fall2013/files/2013/02/Hacking-a-RC-Car-%281%29.pdfhttp://letsmakerobots.com/node/26905http://www.ladyada.net/make/mshield/http://www.instructables.com/id/Autonomous-Control-of-RC-Car-Using-Arduino/http://www.instructables.com/id/Autonomous-Control-of-RC-Car-Using-Arduino/http://playground.arduino.cc/
  • 8/10/2019 Arduino Robot

    14/17

    13 | P a g e

    Appendix

    Appendix A: Research Slides

  • 8/10/2019 Arduino Robot

    15/17

    14 | P a g e

    Appendix B: Ping Ultra Sonic Sensor data sheet

  • 8/10/2019 Arduino Robot

    16/17

    15 | P a g e

    Appendix C: Final Source code#include

    #define trigPin3 // Ping))) Sensor

    #define echoPin 2 // Ping))) Sensor

    AF_DCMotormotor1(1, MOTOR12_8KHZ); // create motor #1, 8KHz pwm

    AF_DCMotor motor3(3, MOTOR34_8KHZ); // create motor #2, 8KHz pwm

    void setup()

    {

    Serial.begin (9600);

    pinMode(trigPin, OUTPUT);

    pinMode(echoPin, INPUT);

    motor1.setSpeed(255); // set the speed to 200/255

    motor3.setSpeed(255); // set the speed to 200/255}

    intCheckDistance()

    {

    long duration, distance;

    digitalWrite(trigPin, LOW);

    delayMicroseconds(2);

    digitalWrite(trigPin, HIGH);

    delayMicroseconds(10);digitalWrite(trigPin, LOW);

    duration = pulseIn(echoPin, HIGH);

    distance = (duration/2) / 29.1;

    return distance;

    }

    void MotorForward(intdelaytime)

    {

    motor1.run(FORWARD);

    motor3.run(FORWARD);

    delay(delaytime);

    }

    void MotorBackward(intdelaytime)

    {

    motor1.run(BACKWARD);

    motor3.run(BACKWARD);

    delay(delaytime);

    }

    void MotorRelease()

    {

    motor1.run(RELEASE);motor3.run(RELEASE);

  • 8/10/2019 Arduino Robot

    17/17

    16 | P a g e

    delay(1000);

    }

    voidMotorLeft()

    {

    motor1.run(FORWARD);motor3.run(BACKWARD);

    delay(600);

    }

    voidMotorRight()

    {

    motor1.run(BACKWARD);

    motor3.run(FORWARD);

    delay(500);

    }

    void loop()

    {

    inttestDistance = CheckDistance();

    Serial.print(testDistance);

    Serial.println( test);

    if (testDistance>= 50|| testDistance