-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Octavio first commit not done with 2
- Loading branch information
Showing
2 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
int ROBOT_COME_AND_GO = 1000; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jcmayoral
via email
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.
Sorry, something went wrong. |
||
|
||
//CONTROLLER VARIABLES | ||
int d=0; | ||
int CORRECTION=0; | ||
int SMALL_ROBOT_STEPS=10; | ||
int tmp=0; | ||
This comment has been minimized.
Sorry, something went wrong.
sthoduka
|
||
|
||
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); | ||
} | ||
|
||
} |
are these constants? If yes, make them
static final int