Close
0%
0%

Chrissybot3000

My first robotics project. A bit ambitious.

Similar projects worth following
A (so far) failed object-avoidance robot. She only sweeps the head right now.

Most of my logs are already on google+.

Look up #Chrissybot3000 on g+ while I try to transfer over.

This is my first foray into robotics.   I could never start small and so decided to go with this motorshield even though all other sample projects are using others. 

I will be using this as a stepping stone to bigger robotics projects like balancers (I always wanted Rosie the robot like on the Jetsons) that can carry loads.

For now Chrissybot3000 will communicate via the native serial terminal function that comes with th Arduino IDE.  I haven't been able to get my LCD shield to work correctly yet, but that will be added, once I get the wheels to roll while the head sweeps.

  • 1 × seeed studio motoshield v2 l298 based shield
  • 1 × arduino uno uh... everyone knows this one
  • 3 × Tower pro mg90 servo
  • 1 × hc-sr04 4 pin sensor
  • 2 × wheel / motor pack DFOOTS 130 motor dual axle 6th wheels

View all 9 components

  • More successful code example

    txdo.msk08/03/2014 at 05:29 1 comment

    I added the ping sensor into this demo, and also got tired of typing motordriver.goForward and ON an ON an ON.

    So I turned the commands in modules, now I just need to finish the other direction modules and then add the second HC-SR04 (Which will require another head), and decide how to use the go backward command:  maybe if both sensor show as being in a corner (backward, left, forward)?

    --------------------------------------------------------------------------------------------

    // Demo function:The application method to drive the DC motor.

    // Author:Frankie.Chu

    // Date:20 November, 2012

    #include "MotorDriver.h" //SeeedStudio Motor Library

    #include "NewPing.h" //library for the SR04 ultrasonic sensor

    #include "Servo.h" //Standard Servo Library

    Servo HeadServo;

    #define TRIGGER_PIN 2 //using analog pins as digital for SR04 sensor

    #define ECHO_PIN 3 //because I just happened to plug them in here

    #define MAX_DISTANCE 200 //the sensor can't measure much further then this distance

    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

    #define runEvery(t) for (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))

    int uS; //value of SR04 ultrasonic sensor

    int Distance; //distance in cm of ultrasonic sensor

    int Too_Close = 50;

    //int pos = 90; //Center the Servo

    int robotDirection = 0; //0 = forward, 1 = backward, 2 = left, 3 = right

    //int servoDirection = 0; //Sweep Left or Right

    int lastRobotDirection; //last direction of the robot

    int distanceCenter;

    //int distanceLeft;

    //int distanceRight;

    //int servoDelay = 2; //Sweep speed

    void setup()

    {

    /*Configure the motor A to control the wheel at the left side.*/

    /*Configure the motor B to control the wheel at the right side.*/

    motordriver.init();

    motordriver.setSpeed(75,MOTORB);

    motordriver.setSpeed(90,MOTORA);

    Serial.begin(9600);

    }

    void loop()

    {

    // sweepServo();

    getDistance();

    if (Distance < Too_Close)

    {

    Forward();

    //delay(2000);

    }

    else if (Distance > Too_Close)

    {

    Left();

    }

    else

    {

    Stop();

    }

    }

    void Forward()

    {

    // sweepServo();

    motordriver.goForward();

    Serial.print("Going Forward");

    }

    void Backward()

    {

    // sweepServo();

    motordriver.goBackward();

    }

    void Left()

    {

    // sweepServo();

    motordriver.goLeft();

    Serial.print("Going Left");

    }

    void Right()

    {

    // sweepServo();

    motordriver.goRight();

    }

    void Stop()

    {

    // sweepServo();

    motordriver.stop();

    }

    /* Servo And Sensor Commands - BEGIN */

    void getDistance()

    {

    runEvery(40) //loop for ultrasonic measurement

    {

    uS = sonar.ping();

    Distance = uS / US_ROUNDTRIP_CM;

    if (uS == NO_ECHO) // if the sensor did not get a ping

    {

    Distance = MAX_DISTANCE; //so the distance must be bigger then the max vaulue of the sensor

    }

    Serial.print("Ping Distance: "); //to check distance on the serial monitor

    Serial.print(Distance);

    Serial.println("cm");

    }

    }

    /*void sweepServo()

    {

    runEvery(servoDelay) //this loop determines the servo position

    {

    if(pos < 165 && servoDirection == 0) // 165 = servo to the left

    {

    pos = pos + 5; // +1 was to slow

    }

    if(pos > 15 && servoDirection == 1) // 15 = servo to the right

    {

    pos = pos - 5;

    }

    }

    if (pos == 165 )

    {

    servoDirection = 1; //changes the direction

    }

    if (pos == 15 )

    {

    servoDirection = 0; //changes the direction

    }

    HeadServo.write(pos); //move that servo!

    }*/

    /* Servo And Sensor Commands - END */

  • She Works! Kinda...

    txdo.msk08/03/2014 at 05:16 0 comments

    I started fresh and after going back over Jeremy Blum's book again for some ideas, and following Daniel toll's advice, I started with parts that do work.

    And I also switched some power wires.  D'Oh!

    I narrowed the problem down to the servo sweep interfering with the drive motors, so for now, I am eliminating that from the sketch.

    I will be adding a second HC-SR04 to give this a stereo-like avoidance combo.

  • Code for Chrissybot3000

    txdo.msk08/02/2014 at 01:36 0 comments

    I pulled the code from a project by Bajdi as it was the closest to what I thought was workable with my setup.

    Still some wheel problems.  It might be as simple as not hooking the motorshield upp correctly (doubtful as Seeed's demo works) or adapting this from a bare chip has screwed up some timings.  All I know is, the sensor sweeps and reports and the drive variables and commands show up in the serial monitor debugger.

    /*

    http://www.bajdi.com (your number one source for buggy Arduino sketches)

    Simple obstacle avoiding robot made from parts mostly sourced from Ebay

    Micro controller = ATmega328P-PU with Arduino bootloader (3.5$ @ Eb.. noooo Tayda Electronics)

    Using a L293D (bought from my favourite Ebay seller Polida) to drive 2 yellow "Ebay motors with yellow wheels"

    Detecting obstacles with an SR04 ultrasonic sensor (uber cheap on Ebay)

    SR04 sensor mounted on SG90 servo (you can get these servo very cheap on ... oh yes you guessed it: EBay)

    Adapted by Ross Potts 7-29-2014 for Seeed Motor Shield V2 BUT I'M STILL HAVING WHEEL ISSUES

    */

    #include "NewPing.h" //library for the SR04 ultrasonic sensor

    #include "Servo.h" //servo library, SR04 is mounted on this servo

    #include "MotorDriver.h"

    Servo HeadServo;

    //Servo LarmServo;

    //Servo RarmServo;

    #define TRIGGER_PIN 2 //using analog pins as digital for SR04 sensor

    #define ECHO_PIN 3 //because I just happened to plug them in here

    #define MAX_DISTANCE 200 //the sensor can't measure much further then this distance

    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

    #define runEvery(t) for (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))

    //const int EN1 = 8; //enable motor 1 = pin 1 of L293D

    //const int direction1 = 11; //direcion motor 1 = pin 2 of L293D

    //const int EN2 = 12; //enable motor 2 = pin 9 of L293D

    //const int direction2 = 13; //direction motor 2 = pin 15 of L293D

    // leds are very handy for testing

    //const int redLed = 10; // this led will lit up when the robot drives forward

    //const int greenLed = 11; // this led will lit up when the robot drives backward

    //const int yellowLed = 12; // this led will lit up when the robot turns left

    //const int whiteLed = 13; // this led will lit up when the robot turns right

    int uS; //value of SR04 ultrasonic sensor

    int distance; //distance in cm of ultrasonic sensor

    int pos = 90; //start position of servo = 90

    int servoDirection = 0; // sweeping left or right

    int robotDirection = 0; //0 = forward, 1 = backward, 2 = left, 3 = right

    int lastRobotDirection; //last direction of the robot

    int distanceCenter;

    int distanceLeft;

    int distanceRight;

    int servoDelay = 20; //with this parameter you can change the sweep speed of the servo

    long previousMillis = 0;

    const int interval = 650; //interval to switch between the robotDirection, this value will determine

    //how long the robot will turn left/right when it detects an obstacle

    void setup() {

    motordriver.init();

    motordriver.setSpeed(200,MOTORB);

    motordriver.setSpeed(200,MOTORA);

    Serial.begin(9600); //to use the serial monitor

    HeadServo.attach(4); //Head servo on pin 8

    HeadServo.write(pos); //center Head servo

    // LarmServo.attach(5); //Left Arm servo on pin 5

    // LarmServo.write(pos); //center Left Arm servo

    // RarmServo.attach(6); //Right Arm servo on pin 6

    // RarmServo.write(pos); //center Right Arm servo

    delay(1500); // delay so we have some time to put the robot on the floor

    }

    void loop()

    {

    sweepServo(); //function to sweep the servo

    getDistance(); //function to get the distance from the ultrasonic sensor

    if (pos >= 15 && pos <= 45)

    {

    distanceRight = distance; //servo is to the right so measured distance = distanceRight

    }

    if (pos >= 135 && pos <= 165)

    {

    distanceLeft = distance; //servo is to the left so measured distance = distanceLeft

    }

    if (pos > 70 && pos < 110)

    {

    distanceCenter = distance; //servo is centred so measured distance = distanceCenter

    }

    if (distanceCenter >= 25) // coast is clear, full power forward

    {

    robotDirection = 0; //move forward

    }

    else //obstacle detected, turn...

    Read more »

  • Logs

    txdo.msk08/01/2014 at 23:31 0 comments

    logs can be found for now at #chrissybot3000 at google+ while I transition

View all 4 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates