Skip to content

Commit

Permalink
Octavio first commit not done with 2
Browse files Browse the repository at this point in the history
  • Loading branch information
oarriaga committed Sep 15, 2015
1 parent e8a66b5 commit 97e8db1
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Exercise3/Series3Ex1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import ch.aplu.robotsim.Gear;
import ch.aplu.robotsim.LightSensor;
import ch.aplu.robotsim.NxtContext;
import ch.aplu.robotsim.NxtRobot;
import ch.aplu.robotsim.SensorPort;
import ch.aplu.robotsim.TouchSensor;



public class Series3Ex1 {

Series3Ex1(){

NxtRobot robot = new NxtRobot();
Gear gear = new Gear();
robot.addPart(gear);
TouchSensor ts = new TouchSensor(SensorPort.S3); //creates TouchSensor
robot.addPart(ts); //fixes the TouchSensor to the Robot
gear.setSpeed(30);

gear.forward();

while(true){

while (true)
{

if (ts.isPressed()) //if the TouchSensor is pressed do
{
gear.backward(1000);
gear.left(1250);
gear.forward(2000);
gear.left(1250);
gear.forward();
break;
}
}

while (true){



if (ts.isPressed()) //if the TouchSensor is pressed do
{
gear.backward(1000);
gear.right(1250);
gear.forward(2000);
gear.right(1250);
gear.forward();
break;
}
}
}

}

public static void main(String[] args) {

new Series3Ex1();

}


//Environment-----------------------------------------------------------------

static {
//430,60 initial
NxtContext.setStartPosition(100, 60);
NxtContext.setStartDirection(180);
NxtContext.useObstacle("sprites/rectangle.gif", 250, 250);
}

}
148 changes: 148 additions & 0 deletions Exercise3/Series3Ex2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import ch.aplu.robotsim.Gear;
import ch.aplu.robotsim.LightSensor;
import ch.aplu.robotsim.NxtContext;
import ch.aplu.robotsim.NxtRobot;
import ch.aplu.robotsim.SensorPort;
import ch.aplu.robotsim.TouchSensor;



public class Series3Ex2 {



Series3Ex2(){

NxtRobot robot = new NxtRobot();
Gear gear = new Gear();
robot.addPart(gear);
TouchSensor ts = new TouchSensor(SensorPort.S3);
robot.addPart(ts);
gear.setSpeed(30);


//just to find first wall assuming
//the robot starts in front of the path

//find right-wall-----------------------------------------------
gear.right(1270);
int ROBOT_STEPS = 2500;

This comment has been minimized.

Copy link
@sthoduka

sthoduka Sep 21, 2015

are these constants? If yes, make them static final int

int ROBOT_COME_AND_GO = 1000;

This comment has been minimized.

Copy link
@sthoduka

sthoduka Sep 21, 2015

what does this variable name mean?

This comment has been minimized.

Copy link
@jcmayoral

jcmayoral via email Sep 21, 2015

Owner
int DEGREES = 1280;

while(true){
//if you rotate and you find a wall
//you have already found a wall!
if(ts.isPressed()){
gear.backward(ROBOT_COME_AND_GO);
gear.left(DEGREES);
gear.forward(ROBOT_STEPS);
break;
}
//if not! you will have to look for one
else{
gear.forward();
//you found it!
if(ts.isPressed()){
System.out.println("I found the first wall");
gear.backward(ROBOT_COME_AND_GO);
gear.left(DEGREES);
gear.forward(ROBOT_STEPS);
break;
}
}

}
//------------------------------------------------------------------
System.out.println("FIRST LOOP");

This comment has been minimized.

Copy link
@sthoduka

sthoduka Sep 21, 2015

the indentation in this file seems to be wrong


//CONTROLLER VARIABLES
int d=0;
int CORRECTION=0;
int SMALL_ROBOT_STEPS=10;
int tmp=0;

This comment has been minimized.

Copy link
@sthoduka

sthoduka Sep 21, 2015

use spaces between operators int tmp = 0
use more verbose variable names. What is tmp?


while(true){

//CONTROLLER-------------------------------------
d++;
if(d==2){
System.out.println("I corrected my orentation");
//CORRECTION=100;
d=0;
}
else{
CORRECTION=0;
}
//-----------------------------------------------

gear.right(DEGREES+CORRECTION);
gear.forward(ROBOT_COME_AND_GO);
if(ts.isPressed()){
gear.backward(ROBOT_COME_AND_GO);
gear.left(DEGREES + CORRECTION);
System.out.println("I found a wall!");
//HERE IS A PROBLEM
//what happens if it crashes against a wall!
//while(true){
// gear.forward
//}
while(true){
gear.forward(SMALL_ROBOT_STEPS);
tmp = tmp+SMALL_ROBOT_STEPS;

if(tmp==ROBOT_STEPS){
System.out.println("NO OBSTACLES");
tmp=0;
break;
}
else{
if(ts.isPressed()){
System.out.println("DANGER!");
gear.right(DEGREES + CORRECTION);
gear.forward(ROBOT_COME_AND_GO);
if(ts.isPressed()){
System.out.println("THE OTHER WAY!");
gear.left(2*(DEGREES + CORRECTION));
}
else{
System.out.println("It must be this way captain!");
gear.forward(ROBOT_STEPS);
break;
}
}
}

}

}//this closes de if



}



}





public static void main(String[] args) {

new Series3Ex2();

}


//Environment-----------------------------------------------------------------

static {

NxtContext.setStartPosition(340, 460);
NxtContext.setStartDirection(270);
NxtContext.useObstacle("sprites/parcours.gif", 250, 250);
}

}

0 comments on commit 97e8db1

Please sign in to comment.