Robotics Club Tabletop Challenge #2

On Wednesday, Nov. 11, Robotics Club had an after-school meeting to work on part 2 of the HBRC Tabletop Challenge.  The rules for that were to cross from one side of the table to the other, and come back to the original side without falling off the table.  Three groups programmed code, and all groups got their code working well within the hour.  This was good for their first autonomous programming.

Here are the three programs they wrote to all achieve the same goal:

//PROGRAM #1
void motorForward() {
startMotor (MotorR, 125);
startMotor (MotorL, 125);
}

void motorBackward () {
startMotor (MotorR, -100);
startMotor (MotorL, -78);
}

void StopMotor () {
stopMotor (MotorR);
stopMotor (MotorL);
}

void detectEdge1() {
while(SensorValue(LimitL1) == 1 && SensorValue(LimitR1) == 1) {
wait(0.01);
}
motorBackward();
}

void detectEdge2 () {
while(SensorValue(LimitL2) == 1 && SensorValue (LimitR2) == 1) {
wait(0.01);
}
motorForward();
}

task main () {
motorForward ();
detectEdge1 ();
detectEdge2 ();
motorForward ();
wait (2);
StopMotor ();
}

//PROGRAM #2
void goforward(){
startMotor(motorR, 100);
startMotor(motorL, 100);
}

void edgeDetect()
{
int x = 1;
while (x == 1){
if (SensorValue(a)==0){
stopMotor(motorL);
stopMotor(motorR);
x = 0;
}

if (SensorValue(b)==0){

stopMotor(motorL);
stopMotor(motorR);
x = 0;
}
}
}

void gobackward(){
startMotor(motorR, -100);
startMotor(motorL, -78);
}

void edgeDetect2(){
int x = 1;
while (x == 1){
if (SensorValue(c)==0){
stopMotor(motorL);
stopMotor(motorR);
x = 0;
}
if (SensorValue(d)==0){
stopMotor(motorL);
stopMotor(motorR);
x = 0;
}
}
}

void forward2(){
startMotor(motorR,75);
startMotor(motorL,75);
wait(2);
stopMotor(motorL);
stopMotor(motorR);
}

task main(){
goforward();
edgeDetect();
gobackward();
edgeDetect2();
forward2();
}
//PROGRAM #3
void goForward()
{
startMotor (motorL, 100);
startMotor (motorR, 100);
}

void goBackward ()
{
startMotor (motorL, -100);
startMotor (motorR, -100);
}

task main()
{
while(SensorValue(frontR)==1 && SensorValue(frontL)==1)
{
goForward();
}

while(SensorValue(backR)==1 && SensorValue(backL)==1)
{
goBackward();
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s