-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
69 additions
and
8 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 |
---|---|---|
@@ -1,14 +1,75 @@ | ||
package ev3dev.java.walle; | ||
|
||
import ev3dev.java.walle.robot.Robot; | ||
import ev3dev.hardware.Battery; | ||
import ev3dev.hardware.port.MotorPort; | ||
import ev3dev.hardware.port.SensorPort; | ||
import ev3dev.hardware.motor.EV3LargeRegulatedMotor; | ||
import ev3dev.hardware.sensor.ev3.EV3IRSensor; | ||
import lejos.robotics.SampleProvider; | ||
import lejos.utility.Delay; | ||
|
||
public class WallE { | ||
|
||
//Robot Definition | ||
private final static EV3LargeRegulatedMotor grab = new EV3LargeRegulatedMotor(MotorPort.D); | ||
private final static EV3LargeRegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.C); | ||
private final static EV3LargeRegulatedMotor mB = new EV3LargeRegulatedMotor(MotorPort.B); | ||
private final static EV3IRSensor ir1 = new EV3IRSensor(SensorPort.S2); | ||
|
||
|
||
public static void main(String[] args) { | ||
Robot r = new Robot(); | ||
|
||
r.testColor(); | ||
} | ||
//Configuration | ||
private final static int motorSpeed = 500; | ||
private final static int rampSpeed = 2000; | ||
|
||
public static void main(String[] args) { | ||
|
||
final SampleProvider sp = ir1.getDistanceMode(); | ||
int distance = 255; | ||
|
||
} | ||
final int distance_threshold = 350; | ||
|
||
|
||
//Robot control loop | ||
final int iteration_threshold = 200; | ||
for(int i = 0; i <= iteration_threshold; i++) { | ||
forward(); | ||
|
||
float [] sample = new float[sp.sampleSize()]; | ||
sp.fetchSample(sample, 0); | ||
distance = (int)sample[0]; | ||
if(distance <= distance_threshold){ | ||
backwardWithTurn(); | ||
} | ||
|
||
System.out.print("\033[0GDistance: " + distance + " "); | ||
} | ||
|
||
mA.stop(); | ||
mB.stop(); | ||
System.exit(0); | ||
} | ||
|
||
private static void forward(){ | ||
mA.setSpeed(motorSpeed); | ||
mB.setSpeed(motorSpeed); | ||
mA.setRampUp(rampSpeed); | ||
mB.setRampUp(rampSpeed); | ||
mA.setRampDown(rampSpeed); | ||
mB.setRampDown(rampSpeed); | ||
|
||
mA.forward(); | ||
mB.forward(); | ||
} | ||
|
||
private static void backwardWithTurn(){ | ||
mA.backward(); | ||
mB.backward(); | ||
Delay.msDelay(1000); | ||
mA.stop(); | ||
mB.stop(); | ||
mA.backward(); | ||
mB.forward(); | ||
Delay.msDelay(1000); | ||
mA.stop(); | ||
mB.stop(); | ||
} | ||
} |
e0ae470
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est stupide!