Monday, February 20, 2012

Autonomous Maze Traversal

To find the flame, we had to program the Squarebot to move towards each room so that it can call it detect flame function. We used a combination of simple drive calls in conjunction with the ultrasonic sensor.


void searchRoom1()
{
  goForward(340);
  goRightSlowly(63);
  goForward(268);
  goRightSlowly(63);
  goForward(170);
  roomNum=1;
}

void searchRoom2()
{
  goLeftSlowly(67);
  goLeftSlowly(67);
  uSonicMove(7);
  goLeftSlowly(63);
  goForward(450);
  goLeftSlowly(67);
  uSonicMove(7);
  roomNum=2;
}

void searchRoom3()
{
  goRightSlowly(67);
  goRightSlowly(67);
  uSonicMove(7);
  goRightSlowly(63);
  goForward(170);
  goLeftSlowly(63);
  goForward(180);
  goLeftSlowly(63);
  uSonicMove(7);
  roomNum=3;
}

void searchRoom4()
{
  goRightSlowly(67);
  goRightSlowly(67);
  uSonicMove(7);
  goLeftSlowly(63);
  uSonicMove(7);
  goRightSlowly(63);
  uSonicMove(14);
  goRightSlowly(63);
  roomNum=4;
}

We successfully navigated on both our attempts. Our problem was that the squirt gun did not fire due to technical difficulties of the water pump. Overall, we had a blast and are looking forward to the next firefighting competition.

  

Firefighting Robot Challenge: Flame Detection and Extinguishing

To detect a flame, we use a flame sensor with 22,000 ohms resistor in conjunction with the Squarebot to read flame values. Our strategy was to sense  for flame values as soon as we stepped into any of the obstacle's rooms. We detect the flame and approach the flame and extinguish the flame with our squirt gun firing mechanism.
We set our main function to call the aim detection function twice to maximize the accuracy of the squirt gun.

bool aim4flame()
{
  if(SensorValue[flame]>=60)
  {
      //Initializers
      SensorValue[rEncoder]=0;
      SensorValue[lEncoder]=0;
      int highestFlame=SensorValue[flame];
      bool highestFlameOnRight=false;
      bool highestFlameOnLeft=false;
      int encoderVal=0;

      //Procedure
      if(SensorValue[flame]>=995)
      {
         return true;
      }
      
      else if(SensorValue[flame]<995)
      {
      while(SensorValue[rEncoder]<=90) //turning right until 90
      {
        if(sensorValue[flame]>995)
        {
          return true;
        }
        goRight(1);
        if(SensorValue[flame]>highestFlame) //set a new highestFlame if a greater flame value is detected
        {
          encoderVal=SensorValue[rEncoder];
          highestFlame=SensorValue[flame];
          highestFlameOnRight=true;
        }
      }
      goLeft(43);
      SensorValue[rEncoder]=0;
      while(SensorValue[rEncoder]<=90)
      {
        if(sensorValue[flame]>995)
        {
          return true;
        }
        goLeft(1);
        if(SensorValue[flame]>highestFlame)
        {
          encoderVal=SensorValue[rEncoder];
          highestFlame=SensorValue[flame];
          highestFlameOnLeft=true;
        }
      }
      goRight(53);
      if(highestFlameOnRight==true && highestFlameOnLeft==false)
      {
        int newEncoderVal=(((encoderVal/2)/2)/2);
        goRight(newEncoderVal);
        uSonicMove(12);
        if(SensorValue[flame]>995)
        {
          return true;
        }
        else
        {
          aim4flame();
        }
      }
      else if(highestFlameOnLeft==true)
      {
        int newEncoderVal2=((encoderVal/3));
        goLeft(newEncoderVal2);
        uSonicMove(12);
        return true;
        if(SensorValue[flame]>995)
        {
        return true;
        }
        else
        {
          aim4flame();
        }
      }
    }
  }
  return true;
}

Sunday, February 19, 2012

Traversing Through a Maze with the Squarebot

My partner and I set the Squarebot to traverse through a maze autonomously. We began on the bot by taking away the radio receiver and then writing a program to traverse though the maze. This program is written in RobotC:


#pragma config(Sensor, in7,    rEncoder,         sensorRotation)
#pragma config(Sensor, in8,    lEncoder,         sensorRotation)
#pragma config(Motor,  port2,           rMotor,        tmotorNormal, openLoop)
#pragma config(Motor,  port3,           lMotor,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
int left = 98;
int right = 70;
int wt = 250;
void goForward(int length)
{
  //wait1Msec(2000);
  bMotorReflected[port2]=1;
  SensorValue[lEncoder] = 0;
  while(SensorValue[lEncoder]<length)
  {
    motor[port3]=127;
    motor[port2]=95;
  }
}

void goleft(int length)
{
  //wait1Msec(2000);
  bMotorReflected[port2]=1;
  SensorValue[lEncoder] = 0;
  while(SensorValue[lEncoder]<length)
  {
    motor[port3]=-127;
    motor[port2]=80;
  }
}

void goright(int length)
{
  //wait1Msec(2000);
  bMotorReflected[port2]=1;
  SensorValue[lEncoder] = 0;
  while(SensorValue[lEncoder]<length)
  {
    motor[port3]=127;
    motor[port2]=-80;
  }
}

void w(int wt)
{
  while(SensorValue[lEncoder]<wt)
  {
    motor[port3]=0;
    motor[port2]=0;
    wait1Msec(wt);
  }

}

task main()
{
  goForward(570);
  goleft(left);
  goForward(280);
  goleft(left);
  goForward(550);
  goRight(right);
  goForward(280);
  goRight(right);
  goForward(740);
  goRight(right);
  goRight(3000);
}

Monday, January 23, 2012

Hacking a Toy

Mad Cow
To control our motorized toy, we have to first pull out any wires linking to the switch, motor, and speaker. Unfortunately, this model toy only has one motor which causes the toy to jump.
We carefully pull the fabric off of the toy in order to access the electronics located inside the toy's chassis.
I solder on extension wires to any wires that were too short for use. The purpose of these wire will be for later use when interfacing with our microcontroller.

MadCow transformation into CyborgHappyCow
MadCow has been mad all his life. I decided to make MadCow happier since he has such a great smile. However, to do this MadCow needed a new eye to see the world in a new light. So, I reamed a hole through his right eye and inserted a LDR to sense light.
Once the light becomes dimmer, the new CyborgHappyCow plays a Happy Birthday tune and then jumps for 2 secs. To play the tune, I programed the PicAxe to control pin 4 which plays through Piezo sounder with a 10 microfarad capacitor to intensify the sound.

To control MadCow's motor, I programmed the PicAxe microcontroller to power on Pin 1 which will power the motor. I used a Tip42C transistor to boost the voltage to MadCow's motor.
 So, as soon as the tune finishes playing his tune he jumps for hurray for 2 secs.

Overall, CyborgHappyCow is much happier and much more satisfied with his new and improved abilities

Introduction to Microcontrollers

Microcontroller
We will be using the PicAxe 08m as a microcontroller to control electronic components. Microcontrollers are quite useful because they are compact, programmable, control several components, and versatility. We begin by setting up a simple circuit to our microcontroller. Next, we program the microcontroller to blink for a determined duration.
 time = 0
   time > 0

We also built and programmed the same circuit except this time we use a Light Dependent Resistor (LDR) and two LEDs to show the how the microcontroller works with a sensor.

  With light.
Without light.
 
Taking a photo of this circuit proved quite difficult because the flash on my camera kept triggering the LDR which is the reason for why there was a little bit of light left in the green LED.

Build a Logic Probe

Logic Probe
Another useful tool for electronics debugging is the logic probe. A logic probe will tell you the logic of a particular point in a circuit, and whether the point has low or high voltage. We start the prototype circuit on the breadboard before soldering the circuit onto a printed circuit board.
 When the probe is powered and not testing for logic or voltage.
 When the probe touches the positive side, the LED glows even brighter.
 When the probe touches ground, the LED goes dark.

Now that we have enough practice, we move onto the fabrication lab for some surface mounting work. This requires a tedious soldering job because once a mistake is made it will be difficult to fix the mistake (I only have one PCB!). After the soldering is complete, we take an exacto knife to make the incisions necessary for this particular circuit because the PCB is made in such a way that all the pins are intertwined as one circuitry. So, our logic must thoroughly predetermined before we begin cutting.
Once we finish our board should function as it did in the breadboard and we put a little bit of hot glue to prevent any of the components from moving about the pins and short-circuiting.
 
DB9 Serial Connector
To prepare for programming and interfacing between a microcontroller and the PC, we solder the necessary wires onto a DB9 serial connector.
The wiring should look as such and shrink wrap should be used to prevent unintended wires from shorting.

Transistor Switching

Transistor
A transistor works much like a relay by switching electronic signals, except that it is much more sensitive and versatile. Today, we test the transistor to see how it differs from a relay. We start by building a simple momentary switch circuit to test the transistor and later switch the momentary switch for just two stand alone jump wires.
The yellow and blue wires that protruding upwards allows us to test the transistor with a simple touch of a finger. When electricity passes through the finger (low-resistance) the transistor receives the electricity and sends it to the LED, powering it as a result.
If you just add a little bit of moisture to your fingers, the LED will glow even brighter!