Tuesday, February 12, 2013

Robotics CSU Long Beach Competiton

The competition at Cal State Long Beach was fun to attend. It was the first of a kind for my person. I had fun riding my byclicle all the way to the event. One key point was my partner deciding to carry all our competition materials. We did some more testing in the university. This left us with an unresponsive robot that unfortunately did not perform as well as it should have.

 
The code for the robot was as follows:
 
#pragma config(Sensor, in1,    flameSensor,    sensorReflection)
#pragma config(Sensor, in2,    leftEncoder,    sensorRotation)
#pragma config(Sensor, in3,    rightEncoder,   sensorRotation)
#pragma config(Sensor, in4,    sonarSensor,    sensorSONAR, int1)
#pragma config(Sensor, in5,    fan,            sensorDigitalIn)
#pragma config(Sensor, in9,    Switch,         sensorTouch)
#pragma config(Sensor, in10,   fan,            sensorDigitalIn)
#pragma config(Motor,  port2,           leftMotor,     tmotorServoContinuousRotation, openLoop)
#pragma config(Motor,  port3,           rightMotor,    tmotorServoContinuousRotation, openLoop,reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
//This function activates the fan from digital input
void turnonfan(){
 while(SensorValue(fan) == 0)  //Loop while robot's bumper/touch sensor isn't pressed in
{
  wait1Msec(1);//Do nothing
 }
}

//This function activates the robot with a bumber switch
void waitforStart(){
 while(SensorValue(Switch) == 0)  //Loop while robot's bumper/touch sensor isn't pressed in
{
  wait1Msec(1);//Do nothing
 }
}

//Function to make the robot turn in place right90 degrees using the encoder (85)
void turnRight(int turnwheels, int turnspeed)
{
 SensorValue[rightEncoder] = 0;    //Reset encoder
  motor[port2] = turnspeed;  //robot turns slowly
  motor[port3] = -turnspeed;
 while(SensorValue[rightEncoder] < turnwheels)//Wheels go until value is reached
 {
 }
}
void turnAround()
{
 SensorValue[rightEncoder] = 0;    //Reset encoder
  motor[port2] = 63;  //robot turns slowly
  motor[port3] =  -63;
 while(SensorValue[rightEncoder] < 170)//Wheels go until value is reached
 {
 }
}
//Function to make the robot turn in place 90 degrees using the encoder (85)
void turnLeft(int turnwheels)
{
 SensorValue[rightEncoder] = 0;    //Reset encoder
 motor[port2] =  -63;  //robot turns slowly
 motor[port3] =   63;
 while(SensorValue[rightEncoder] < turnwheels)//Wheels go until value is reached
 {
 }
}
//Function to make the robot stop
void pause(int waitTime)
{
 SensorValue[rightEncoder] = 0;    //Reset encoder
  motor[port3] = 0;
  motor[port2] = 0;
 wait1Msec(waitTime);
}
void goToFlame()
{
 while(SensorValue[flameSensor]<120)
 {
  turnLeft(5);
  pause(1);
 }
  pause(1);
}
//Function to make the robot go forward 20cm using the encoder
void goforward(int gowheels)
{
 SensorValue[rightEncoder] = 0;       //Initialize encoder; set count to "0"
 while(SensorValue[rightEncoder] < gowheels)//Wheels go until value is reached
 {
  motor[port3] = 95;
  motor[port2] = 95;
 }
 pause(1);
}
void flameCheck()
{
 SensorValue[rightEncoder]=0; //encoder value for ONE full rotations
 while((SensorValue[flameSensor]<110)&&SensorValue[rightEncoder]<91)//first read value in range
 {
  wait10Msec(1);
  turnRight(1,100);          //takes 1st step to the right
 }
  pause(1000);
}
//void goToLine() //searches for a line(value of Zero) and haults movement
//{
// while(SensorValue[lineSensor]!=0)
// {
//    gofoward(2);
//  }
//  Stop();
//}
void goToWall(int distance)  //goes to wall to specified distance away from it
{
 while(SensorValue[sonarSensor]>distance||SensorValue[sonarSensor]<0)
 {
    goforward(1);
  }
  pause(1);
}
void backIntoWall()
{
 SensorValue[leftEncoder] = 0;       //Initialize encoder; set count to "0"
 while(SensorValue[leftEncoder] < 180)//Wheels go until value is reached
 {
  motor[port3] = -127;
  motor[port2] = -127;
 }
 pause(1);
}
void searchRoom1()
{
pause(1000); //pause at home base
goToWall(8);
turnRight(70,100); //90 degress
goToWall(11); //enter first room
flameCheck();  // 1 full rotation
backIntoWall(); //straightens robot
}
void searchRoom2()
{
goToWall(5); //EXIT ROOM 1
turnLeft(70); //90 degress
goforward(172); //need to place robot infront of entrance(69)45cm
turnRight(70,100); //90 degress
backIntoWall();
goToWall(5); //enter room
flameCheck();
backIntoWall();
}
void searchRoom3()
{
goToWall(5); //EXIT ROOM 2
turnRight(70,100); //90 degress
goforward(244); //adjacent of 3rd room hallway(69)45cm
turnLeft(70); //90 degress
goToWall(5);
turnRight(70,100); //90 degress
goToWall(5); //ENTER ROOM 3
flameCheck();
backIntoWall();
}
void SearchRoom4()
{
goToWall(5); //EXIT ROOM 3
turnLeft(70); //90 degress
goforward(244); //necessary distance to be infront of room 4(NEED TO CALCULATE CORRECT DISTANCE)
turnLeft(70); //90 degress
goToWall(5); //ENTER ROOM 4
flameCheck();
}
 
task main()
{
 waitforStart();
 //searchRoom1();
 //searchRoom2();
 //searchRoom3();
turnRight(20,75);
}

No comments:

Post a Comment