Wednesday, February 13, 2013

Competition Day, LUCKY!

A picture of the first stages of the square bot.



A picture of the middle stages of the square bot.

A picture of the square bot near the final stages, looking for the flame.

A picture of the final build of the square bot. Our team name for the competition is, "Kitty Kat".

Here is the link to the video of "Kitty Kat" in action:
http://www.youtube.com/watch?v=paTmTizYf1I&feature=player_embedded

Our team was able to put of the flame, however, it was due to luck and not the code. Kitty Kat did carry out code correctly. More testing would have avoided the robot from crashing into the candle.

Here is the code for "Kitty Kat":

#pragma config(Sensor, in1,    flameSensor,    sensorAnalog)
#pragma config(Sensor, in2,    leftEncoder,    sensorRotation)
#pragma config(Sensor, in3,    rightEncoder,   sensorRotation)
#pragma config(Sensor, in4,    sonarSensor,    sensorSONAR, int1)
#pragma config(Sensor, in5,    lineSensor,     sensorReflection)
#pragma config(Sensor, in6,    startButton,     sensorReflection)
#pragma config(Sensor, in10,   fan,          sensorDigitalOut)
#pragma config(Motor,  port2,           rightMotor,    tmotorServoContinuousRotation, openLoop, reversed)
#pragma config(Motor,  port3,           leftMotor,     tmotorServoContinuousRotation, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
void stoprobot()
{
    motor[leftMotor]=0;
    motor[rightMotor]=0;
    SensorValue[rightEncoder]=0;
    SensorValue[leftEncoder]=0;
}
void goforward(int counts)
{
    SensorValue [leftEncoder] = 0;
    SensorValue [rightEncoder] = 0;
    int normalspeed;
    int    slowspeed;
    normalspeed = 60;
    slowspeed =45 ;
    //while (SensorValue [rightEncoder]<counts && SensorValue [leftEncoder]<counts)
    while(SensorValue[leftEncoder] < counts)
    {
        if(SensorValue[leftEncoder]>SensorValue[rightEncoder])
        {
            motor[rightMotor]=normalspeed;
            motor[leftMotor]=slowspeed;
        }
        if(SensorValue[rightEncoder]>SensorValue[leftEncoder])
        {
            motor[rightMotor]=slowspeed;
            motor[leftMotor]=normalspeed;
        }
        if(SensorValue[rightEncoder] == SensorValue[leftEncoder])
        {
            motor[rightMotor]=normalspeed;
            motor[leftMotor]=normalspeed;
        }
    }
}
void gotowall(int distance)
{
    while (SensorValue [sonarSensor] >= distance || SensorValue [sonarSensor] < 2)
    {
        goforward(1);
    }
}
void fanOn ()
{
    SensorValue[fan]=1;
    wait10Msec(100);
    SensorValue[fan]=0;
}
void killFlame (int flameValue)
{
    fanOn();
    wait10Msec(100);
    while (SensorValue[flameSensor]> flameValue)
    {
        goforward(5);
        fanOn();
        stoprobot();
        wait10Msec(500);
    }
}
void searchRight(int fire, int searchTime)
{
    int counter=0;
    SensorValue [flameSensor] = 0;
    SensorValue [leftEncoder] = 0;
    while(SensorValue[flameSensor]<fire && counter<searchTime)
    {
        counter=counter+1;
        wait1Msec(1);
        motor[rightMotor] = -50;
        motor[leftMotor] = 50;
    }
    killFlame(600);
}
void fw2 ()
{
    while (SensorValue[flameSensor]> 100 && SensorValue[flameSensor] <900)
    {
        goforward(5);
        stoprobot();
    }
    int fire;
    int searchTime;

    searchRight(fire+300,searchTime);
}
void goleft(int langle)
{
    SensorValue [leftEncoder] = 0;
    SensorValue [rightEncoder] = 0;
    while (SensorValue [rightEncoder]<langle)
    {
        motor[rightMotor] = 60;
        motor[leftMotor] = -60;
    }
}
void goright(int rangle)
{
    SensorValue [leftEncoder] = 0;
    SensorValue [rightEncoder] = 0;
    while (SensorValue [leftEncoder]<rangle)
    {
        motor[rightMotor] = -60;
        motor[leftMotor] = 60;
    }
}
void rfindTape(int rblack)
{
    while (SensorValue [lineSensor] <= rblack)
    {
        goforward(10);
    }
}
void findTape(int black)
{
    while (SensorValue [lineSensor] >= black)
    {
        goforward(10);
    }
}
void back(int bb)
{
    SensorValue[rightEncoder]=0;
    SensorValue[leftEncoder]=0;
    motor[rightMotor]= 0;
    motor[leftMotor]=0;
    motor[rightMotor]=-60;
    motor[leftMotor]=-60;
    wait1Msec(1000);
    motor[rightMotor]=0;
    motor[leftMotor]=0;
}
void sr1()
{
    goright(90);
    back(50);
    gotowall(10);
    goright(90);
    back(50);
    gotowall(15);
    searchRight(600,2900);
    stoprobot();
    wait10Msec(100);
    goright(90);
    stoprobot();
    back(200);
    stoprobot();
    goright(95);
    back(200);
    gotowall(10);
    goleft(90);
    back(150);
    gotowall(10);
    stoprobot();
    goleft(90);
    stoprobot();
    back(60);
    stoprobot();
}
void sr2()
{
    goforward(200);
    //    gotowall(35);
    stoprobot();
    goright(90);
    stoprobot();
    back(60);
    stoprobot();
    gotowall(35);
    stoprobot();
    searchRight(400,3400);
    stoprobot();
    wait10Msec(100);
    goright(75);
    stoprobot();
    back(100);
    stoprobot();
    goright(90);
    stoprobot();
    back(250);
    gotowall(10);
    stoprobot();
}
void sr3()
{
    goright(90);
    //stoprobot();
    //back(210);
    //stoprobot();
    goforward(100);
    stoprobot();
    goright(90);
    stoprobot();
    gotowall(40);
    goleft(90);
    stoprobot();
    back(50);
    gotowall(10);
    searchRight(600,3400);
    stoprobot();
    goright(90);
    back(60);
    goright(90);
    back(60);
    gotowall(10);
    stoprobot();
}
void sr4()
{
    goright(90);
    goforward(90);
    goright(90);
    gotowall(40);
    goleft(90);
    gotowall(10);
    goright(90);
    back(60);
    gotowall(20);
    searchRight(600,3000);
    gotowall(10);
    searchRight(600,3000);
    stoprobot();
}
void SearchRoom1()
{
    wait1Msec(2000);
    back(80);
    stoprobot();
    gotowall(10);
    sr1();
}
void t2 ()
{
    //    gotowall(10);
    //    stoprobot();
    goforward(80);
    //    searchRight(400,2900);
    stoprobot();
}
task main()
{
    wait1Msec(1500);
    SearchRoom1();
    stoprobot();
    sr2();
    stoprobot();
    sr3();
    stoprobot();
    sr4();
    stoprobot();
}

The task main code basically tells "Kitty Kat" what navigation path the take. "Kitty Kat" will go straight to room 1, call functions that search for the flame and turn the fan on if a value of greater than 500 is present. If there is no flame, it would then proceed to sr2,(room2) and do the same. It would keep doing this in till it has found a flame or explored all 4 rooms.

Testing and reconfigure values was a must. Depending on battery life, and surface texture "Kitty Kat" would behave differently. In order to minimize errors, few function were made and many were called a lot. This made debugging easier. One governing rule that was absolutely necessary was "Kitty Kat" ability to go straight for long distances and turn 90 degrees perfectly. Having this insured that the robot would not crash on throw itself off course.

Overall this project was extremely fun and taught me a lot about programming, planning, and testing a unit. I think the next time I enter a robot competition I will be very confident in being able to win. I would not relay on luck but on hard work.

Day 14, Final build of Square Bot

Picture of final build of the square bot.

Square bot has fan, external power supply, sonar sensor, flame sensor, line sensor, and encodes on the wheels. Code has been written to allow the square bot to move forward by both encoder counts, and sonar values, turn right and left, power on the fan, and find the flame.

More testing was done on the maze. Problems with going straight and turning were wrinkled out.

Tuesday, February 12, 2013

Day 13, Powering The Fan

Picture of the power supply needed to turn on the fan.

The fan that we are using to extinguish the fan is rated at 12V but the power supply of the square bot only outputted 7.2V. So a MPS A 14 transistor was used with two 9V batteries in series to give the fan the needed power. The fan is controlled by the signal output of the Vex.

Day 12, Traveling The Maze

Picture of the maze with the square bot searching for the flame.

On this class day, our time was spent on having the square bot traverse through the maze and find the flame and stop once it found the fire. Our search strategy was to go top right, top left, bottom left and finally bottom right. Each time in would enter a room it would initiate the search for the flame and if not found would go to the next room. Going straight and turning 90 degrees was mandatory for a successful run.

Thursday, January 31, 2013

Day Eleven, Adding Sensors and Programming


Picture of the square bot with added sensors. Sonic, flame, and light sensor added. Writing code is fun and hard. Adjusting right values to initiate commands can be frustrating but rewarding once it works.

Wednesday, January 30, 2013

Day Project, Bird


Picture of the gutted bird. I think I broke the connection that control the movement of the wings. Or lost the piece. I will take better note and care when disassemble a toy.



Picture of bird put back together. The goal of my project was to have to movement be controlled by the press of the tongue but was unable to do so. The movement is now controlled by the micro controller in set time intervals. The motor runs clockwise, stops, and then counter clockwise.


Video of the Bird in action. Movement is controlled by micro controller. It moves in time intervals that can be change with the PC. The wings are suppose to move with the movement of the head but they do not. More debugging and more attention to detail when taking the bird apart would of safeguarded against breaking the wing movement. But the motor at least does controll the head movement. The project was fun and rewarding.

Code for Bird project:

void setup ()
{
  pinMode (6,OUTPUT);  // input for relayswitch

  pinMode (7,OUTPUT); // input for relayswitch
}

void loop ()
{
  digitalWrite (6, HIGH); // inputs high to motor
  digitalWrite (7,HIGH);  // inputs high to motor
  delay (5000);           // duration of movement
  digitalWrite (7,LOW);   // inputs low to motor
  delay (1000);           // stops movement for 1 second
  digitalWrite (6,LOW);   // reverse movement for motor
  delay (2000);           // duration of movement
}

Day Ten, Building Sensors for Robot


Picture of the square bot pointing towards the candle light. The picture shows the encoders on the back wheels. The flame sensor is in front. The goal for the day was to write code that would tell the square bot to turn clockwise in till the flame sensor finds the flame then tells the square bot to move forward a given amount controlled by the encoder. It was very rewarding to have the square bot function as attended.