Thursday, December 11, 2014

It Works!!!

The robot officially moves with the remote control. I ended up seeking help from a computer science friend and learned a lot from the. After I finally got the hang of things, I ended up making a few extra moves for the robot to do. Pushing the OK button makes it dance, pushing the INFO button makes the robot go in a circle, HELP makes the robot do a figure 8, and pressing MENU makes the robot shake back and forth.

The motors ended up being wired backwards and I didn't have a screwdriver handy to change the order, so I ended up putting some things backwards in the program in order for the robot to do what was intended. Also, the wheels are a little wonky so one had to run longer than the other in order to make a perfect figure 8 or perfect circle, which is why the values in some of the sections are a little weird.

The first time around in the earlier post regarding this program, the values gathered for the buttons were in hexadecimal instead of decimal, and that didn't work because it read letters instead of integers. These values were converted in order for the program to compile and execute as needed.


//This is the best code of the 21st century.
#include <IRremote.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

#define IR_CODE_FORWARD 16798291
#define IR_CODE_BACKWARD 16831187
#define IR_CODE_TURN_RIGHT 16839411
#define IR_CODE_TURN_LEFT 16806515
#define IR_CODE_DANCE 3937909453
#define IR_CODE_INFO 16817309
#define IR_CODE_HELP 16825019
#define IR_CODE_MENU 16796235
#define IR_CODE_CONTINUE -1

boolean isActing=false;
long timer;
const long TIME_OUT=100;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *rightMotor = AFMS.getMotor(3);
Adafruit_DCMotor *leftMotor = AFMS.getMotor(4);

void setup(){
  Serial.begin(9600);
  AFMS.begin();
  rightMotor->setSpeed(180);
  leftMotor->setSpeed(180);
  irrecv.enableIRIn();
}
void fig8(){
  for(int i = 0 ; i < 2 ; ++i){
    rightMotor->setSpeed(50);
    leftMotor->run(BACKWARD);
    rightMotor->run(BACKWARD);
    delay(2000);
    rightMotor->setSpeed(180);
    delay(1000);
    leftMotor->setSpeed(60);
    delay(3500);
    rightMotor->run(RELEASE);
    leftMotor->run(RELEASE);
    leftMotor->setSpeed(180);
  }
}
void shake(){
  for(int i = 0 ; i < 10 ; ++i){
    if(i%2==0){
      rightMotor->run(BACKWARD);
      leftMotor->run(BACKWARD);
      delay(250);
    }else{
      rightMotor->run(FORWARD);
      leftMotor->run(FORWARD);
      delay(250);
    }
  }
  rightMotor->run(RELEASE);
  leftMotor->run(RELEASE);
}
void circle(){
  rightMotor->setSpeed(50);
  leftMotor->run(BACKWARD);
  rightMotor->run(BACKWARD);
  delay(3000);
  leftMotor->run(RELEASE);
  rightMotor->run(RELEASE);
  rightMotor->setSpeed(180);
}
void dance(){
  for(int i = 0 ; i < 10 ; ++i){
    if(i%2 == 0){
      leftMotor->run(FORWARD);
      rightMotor->run(BACKWARD);
      delay(250);
    }else{
      leftMotor->run(BACKWARD);
      rightMotor->run(FORWARD);
      delay(250);
    }
  }
  leftMotor->run(RELEASE);
  rightMotor->run(RELEASE);
}
void isWorking(){
  timer=millis();
  isActing=true;
}
void loop(){
  if(irrecv.decode(&results)){
    switch(results.value){
      case IR_CODE_BACKWARD:
        leftMotor->run(FORWARD);
        rightMotor->run(FORWARD);
        isWorking();
        break;
      case IR_CODE_FORWARD:
        leftMotor->run(BACKWARD);
        rightMotor->run(BACKWARD);
        isWorking();
        break;
      case IR_CODE_TURN_RIGHT:
        leftMotor->run(BACKWARD);
        rightMotor->run(FORWARD);
        isWorking();
        break;
      case IR_CODE_TURN_LEFT:
        leftMotor->run(FORWARD);
        rightMotor->run(BACKWARD);
        isWorking();
        break;
      case IR_CODE_INFO:
        circle();
        break;
      case IR_CODE_HELP:
        fig8();
        break;
      case IR_CODE_MENU:
        shake();
        break;
      case IR_CODE_DANCE:
        dance();
        break;
      case IR_CODE_CONTINUE:
        timer=millis();
        break;
    }
    irrecv.resume();
  }
  if(isActing && (millis()-timer>=TIME_OUT)){
    leftMotor->run(RELEASE);
    rightMotor->run(RELEASE);
    isActing=false;
  }
 
}

BROOMBA IS SWEEPING!!



We were able to get our Bromba to sweep in autonomous mode just to make sure it works.
We are working on getting it to be controlled by a remote. Kathy is still on her adventure. Go Kathy!!! (Joseline- the cheerleader)

We Are Not Computer Science Majors Either

Last night Kate and Connor tried to get the IR receiver from the DVD player to work. Unfortunately, we wired the circuit wrong and we overheated the IR receiver, breaking it.

So this morning Kate went on an adventure to Radio Shack and got a new one!

This one works, and we were able to get the codes from the buttons on the Comcast remote that we were going to use to control the robot. Using the following program, we pulled up the Serial Monitor and got the codes corresponding to each button.


Below is the serial monitor with the codes for each button on the remote. We are going to use the directional buttons on the remote which we labeled forward, back, right, and left. Below are the codes we found for each button when we ran the program on the arduino. 


Wednesday, December 3, 2014

Marc Risked His Life on Black Friday to Find us the Perfect Brush

Thanks, Marc! We're glad you made it back alive (see end for more of Marc's breathtaking adventure).

 Beautiful!
 Look at those luscious bristles!

Marc was caught amidst a wave of savage shoppers in the hardware store commonly referred to as Lowes, on Black Friday evening.  As our protagonist neared complete exhaustion, out of the corner of his eye, he caught a glimpse of the most spectacular sweeping machine he had ever seen.  Oh what a glorious day for all of mankind.

Tuesday, December 2, 2014

The Quest for the Infrared Receiver

Today, Connor and Kate had a little fun with a DVD player, screw drivers, and a soldering iron. Our happy little Broomba chassis kept us company while we did it.

DVD player and happy Broomba chassis

The first thing to do was take off the black covering. That was simple, we just had to remove a few screws.

Picture 1: Connor the hand model unscrewing the DVD case

Here's what we found underneath the outer covering of a DVD player:

Picture 2: inside of a DVD player
And here's a closeup of where the disk would go:

Picture 3: where the DVD goes
The white plastic that you can see in picture 3 was intertwined with the black plastic and it was hard to shimmy out of there gently. Since we weren't putting the DVD player back together, we just broke it all apart. After unscrewing multiple screws, we were able to find a few motors and some gears. 

Below a small yellow board is shown. You can see in Picture 2 where this was located in the DVD player. Everything was very heavily soldered onto this board so we weren't able to salvage anything from it, but it was pretty fun Googling the serial numbers of the parts to find out what served what purpose on this board. 

Picture 4

We found the IR receiver that we need! It was right next to the LED display.
Figure 5: The IR receiver! 

Picture 6: The IR receiver in all of its glory
 And for an added bonus, we managed to find and salvage a potentiometer!
Picture 7: Potentiometer!