In our final project we attempted to search four rooms and extinguish a lit candle. To extinguish the candle we used a smacking type device which was controlled by two motors.
#pragma config(Sensor, in1, firesensor, sensorPotentiometer)
#pragma config(Sensor, in5, Ultrasonic, sensorSONAR, int1)
#pragma config(Sensor, in3, leftEncoder, sensorRotation)
#pragma config(Sensor, in2, rightEncoder, sensorRotation)
#pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop,reversed)
#pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop)
#pragma config(Motor, port7, rightarm, tmotorNormal, openLoop)
#pragma config(Motor, port8, leftarm, tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
//turn left
//Look for the fire
//If you find the fire gofoward
//If you don't find the fire turn left more (repeat)
//to get out of the room use ultrasonic to find the empty wall
void goforward(int distance)
{
SensorValue(leftEncoder)=0;
SensorValue(rightEncoder)=0;
while(SensorValue[leftEncoder]<distance && SensorValue(rightEncoder)<distance)
{
if (SensorValue(Ultrasonic)>2)
{
motor[port3]=60;
motor[port2]=60;
}
}
motor[port3]=0;
motor[port2]=0;
}
void raisearm(int time10)
{
motor[port7]=-34;
motor[port8]=34;
wait10Msec(15);
}
void findflame2(int time10)
{
SensorValue[leftEncoder] = 0;
bool flamenotfound2 = true;
while(flamenotfound2) //Play with number 180
{
if (SensorValue(firesensor)<100 && SensorValue[leftEncoder]<520)//search
{
motor[port2]=-60;
motor[port3]=60;
wait10Msec(5);
motor[port2]=0;
motor[port3]=0;
wait10Msec(1);
}
if (SensorValue(firesensor)>100 && SensorValue(firesensor)<200)// first go find it
{
motor[port2]=60;
motor[port3]=60;
wait10Msec(10);
motor[port2]=0;
motor[port3]=0;
wait10Msec(1);
}
if (SensorValue(firesensor)>200 && SensorValue(firesensor)<450)
{
motor[port2]=-60;
motor[port3]=60;
wait10Msec(5);
motor[port2]=0;
motor[port3]=0;
wait10Msec(1);
}
if (SensorValue(firesensor)>450 && SensorValue(Ultrasonic)>6)
{
motor[port2]=60;
motor[port3]=60;
wait10Msec(5);
motor[port2]=0;
motor[port3]=0;
wait10Msec(1);
}
if (SensorValue(firesensor)>850 && SensorValue(Ultrasonic)<6)
{
SensorValue(leftEncoder)=0;
SensorValue(rightEncoder)=0;
while(SensorValue(leftEncoder)<200 && SensorValue(rightEncoder)<200)
{
motor[port2]=0; //Stop
motor[port3]=0;
wait10Msec(5);
motor[port7]=127; //commence wacking
motor[port8]=-127;
wait10Msec(50);
motor[port7]=-127; //return wacker
motor[port8]=127;
wait10Msec(50);
motor[port2]=-60; // Spin by time !Not Good!
motor[port3]=60;
wait10Msec(7);
motor[port2]=0; //Stop
motor[port3]=0;
wait10Msec(5);
motor[port7]=127; //commence wacking
motor[port8]=-127;
wait10Msec(50);
motor[port7]=-127; //return wacker
motor[port8]=127;
wait10Msec(50);
motor[port2]=60; // Good!
motor[port3]=-60;
wait10Msec(7);
}
}
// Signal that the flame is found
if (SensorValue(firesensor)<=60 && SensorValue(leftEncoder)>=520)
{
flamenotfound2 = false;
}
}
}
void goleft(int distance)
{
SensorValue(leftEncoder)=0;
SensorValue(rightEncoder)=0;
while(SensorValue[leftEncoder]<distance && SensorValue(rightEncoder)<distance)
{
motor[port3]=-60;
motor[port2]=60;
}
motor[port3]=0;
motor[port2]=0;
}
void goright(int distance)
{
SensorValue(leftEncoder)=0;
SensorValue(rightEncoder)=0;
while(SensorValue[leftEncoder]<distance && SensorValue(rightEncoder)<distance)
{
motor[port3]=60;
motor[port2]=-60;
}
motor[port3]=0;
motor[port2]=0;
}
void findflame1(int time10)
{
SensorValue[leftEncoder] = 0;
bool flamenotfound1 = true;
while(flamenotfound1) //Play with number 180
{
if (SensorValue(firesensor)<100 && SensorValue[leftEncoder]<507)//search
{
motor[port2]=-60;
motor[port3]=60;
wait10Msec(5);
motor[port2]=0;
motor[port3]=0;
wait10Msec(1);
}
if (SensorValue(firesensor)>100 && SensorValue(firesensor)<200)// first go find it
{
motor[port2]=60;
motor[port3]=60;
wait10Msec(10);
motor[port2]=0;
motor[port3]=0;
wait10Msec(1);
}
if (SensorValue(firesensor)>200 && SensorValue(firesensor)<450)
{
motor[port2]=-60;
motor[port3]=60;
wait10Msec(5);
motor[port2]=0;
motor[port3]=0;
wait10Msec(1);
}
if (SensorValue(firesensor)>450 && SensorValue(Ultrasonic)>6)
{
motor[port2]=60;
motor[port3]=60;
wait10Msec(5);
motor[port2]=0;
motor[port3]=0;
wait10Msec(1);
}
if (SensorValue(firesensor)>850 && SensorValue(Ultrasonic)<5)
{
SensorValue(leftEncoder)=0;
SensorValue(rightEncoder)=0;
while(SensorValue(leftEncoder)<200 && SensorValue(rightEncoder)<200)
{
motor[port2]=0; //Stop
motor[port3]=0;
wait10Msec(5);
motor[port7]=127; //commence wacking
motor[port8]=-127;
wait10Msec(50);
motor[port7]=-127; //return wacker
motor[port8]=127;
wait10Msec(50);
motor[port2]=-60; // Spin by time !Not Good!
motor[port3]=60;
wait10Msec(10);
motor[port2]=0; //Stop
motor[port3]=0;
wait10Msec(5);
motor[port7]=127; //commence wacking
motor[port8]=-127;
wait10Msec(50);
motor[port7]=-127; //return wacker
motor[port8]=127;
wait10Msec(50);
motor[port2]=60; // Good!
motor[port3]=-60;
wait10Msec(10);
}
}
// Signal that the flame is found
if (SensorValue(firesensor)<=60 && SensorValue(leftEncoder)>=507)
{
flamenotfound1 = false;
}
}
}
task main()
{
while(true)
{
wait10Msec(200);//searches first room
raisearm(10);
wait10Msec(100);
goforward(373);
wait10Msec(10);
goright(97);
wait10Msec(10);
goforward(320);
wait10Msec(10);
goright(96);
wait10Msec(10);
goforward(135);
wait10Msec(10);
findflame1(150);//looks for flame ans if found puts it out
wait10Msec(10);
goforward(135);//gets out of the room
wait10Msec(10);
goleft(93);
wait10Msec(10);//goes to the next room
goforward(301);
wait10Msec(10);
goright(100);
wait10Msec(10);
goforward(415);
wait10Msec(10);
goright(95);
wait10Msec(10);
goforward(220);//enters room in front
wait10Msec(10);
findflame2(150);
wait10Msec(10);
goforward(215);
wait10Msec(10);
goleft(91);
wait10Msec(10);
goforward(170);
wait10Msec(10);
goright(90);
wait10Msec(10);
goforward(240);
wait10Msec(10);
findflame1(150);
wait1Msec(10);
goforward(120);
wait10Msec(10);
goright(90);
wait10Msec(10);
goforward(200);
wait10Msec(10);
goright(90);
wait10Msec(10);
goforward(200);
wait10Msec(10);
goleft(90);
wait10Msec(10);
goforward(120);
wait10Msec(10);
findflame1(150);
wait10Msec(10);
}
}
Tuesday, February 14, 2012
Wednesday, February 8, 2012
Find the Flame/Robot moving into room one
Here is a video demonstrating how our robot moves from the starting point into room one as it detects and extinguishes the flame.
Monday, February 6, 2012
Ultrasonic Rangefinder and other Sensors
In this experiment we were able to demonstrate how our robot implements the flame, and ultrasonic sensors work. We did this by programming the ROBOTC software and affixing the sensors to our bot. The video shows how the flame sensor detects the heat of the flame while the ultrasonic sensor detects the range of the box.
Thursday, February 2, 2012
Building a Sensor for your Robot
For the Building a Sensor experiment, we used a phototransistor to detect the heat, via infrared, a candle emitted. Once the circuit was made using a bread board, wires, and resistor we lit up a candle and placed it in front of the sensor moving it back and forth.
Wednesday, February 1, 2012
Vex Programming
In the Vex Programming experiment, my partner and I had two objectives: 1) program the vex bot to operate properly in the labyrinth using time, and 2) program the vex bot using encoders. We used the ROBOTC program for both parts. In the first objective, we used time as the main source to control the bot, such as 3000ms = 3 seconds. In the second part we had to control the bot using the encoder which counts rotation instead of time.
timing program
encoder program
timing program
encoder program
Subscribe to:
Posts (Atom)