Skip to content

Commit c2331cc

Browse files
committed
Example upgrade
1 parent 4376395 commit c2331cc

File tree

70 files changed

+1010
-459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1010
-459
lines changed

ev3dev-lang-java/src/main/java/ev3dev/actuators/LCDDrawIconsTest.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

ev3dev-lang-java/src/main/java/ev3dev/actuators/LCDDrawImagesTest.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

ev3dev-lang-java/src/main/java/ev3dev/actuators/LCDDrawLinesTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

ev3dev-lang-java/src/main/java/ev3dev/actuators/LCDDrawRectanglesTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

ev3dev-lang-java/src/main/java/ev3dev/actuators/LCDTest.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

ev3dev-lang-java/src/main/java/ev3dev/actuators/LCDWriteTextTest.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

ev3dev-lang-java/src/main/java/ev3dev/actuators/lego/motors/LargeMotorDemo.java renamed to ev3dev-lang-java/src/main/java/ev3dev/actuators/LargeMotorDemo.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
package ev3dev.actuators.lego.motors;
1+
package examples.actuators;
22

3+
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
34
import lejos.hardware.port.MotorPort;
45
import lejos.utility.Delay;
6+
import lombok.extern.slf4j.Slf4j;
57

8+
@Slf4j
69
public class LargeMotorDemo {
710

811
public static void main(String[] args) throws InterruptedException {
912

10-
System.out.println("Starting motors on A");
13+
LOGGER.info("Starting motors on A");
1114
final EV3LargeRegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.A);
1215
mA.setSpeed(500);
1316
mA.brake();
1417
mA.forward();
15-
System.out.println(String.format("Large Motor is moving: %s at speed %d", mA.isMoving(), mA.getSpeed()));
18+
LOGGER.info(String.format("Large Motor is moving: %s at speed %d", mA.isMoving(), mA.getSpeed()));
1619
Delay.msDelay(2000);
1720
mA.stop();
18-
System.out.println("Stopped motors");
21+
LOGGER.info("Stopped motors");
1922
}
2023

2124
}

ev3dev-lang-java/src/main/java/ev3dev/actuators/lego/motors/LargeMotorDemo2.java renamed to ev3dev-lang-java/src/main/java/ev3dev/actuators/LargeMotorDemo2.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
package ev3dev.actuators.lego.motors;
1+
package examples.actuators;
22

3+
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
34
import lejos.hardware.port.MotorPort;
45
import lejos.utility.Delay;
6+
import lombok.extern.slf4j.Slf4j;
57

8+
@Slf4j
69
public class LargeMotorDemo2 {
710

811
public static void main(String[] args) throws InterruptedException {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package examples.actuators;
2+
3+
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
4+
import lejos.hardware.port.MotorPort;
5+
import lejos.utility.Delay;
6+
import lombok.extern.slf4j.Slf4j;
7+
8+
import java.util.stream.IntStream;
9+
10+
@Slf4j
11+
public class LargeMotorDemo3 {
12+
13+
//Robot Definition
14+
private static EV3LargeRegulatedMotor motor1 = new EV3LargeRegulatedMotor(MotorPort.A);
15+
16+
//Configuration
17+
private final static int DELAY = 300;
18+
private final static int iterations = 90;
19+
20+
public static void main(String[] args) {
21+
22+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
23+
System.out.println("Emergency Stop");
24+
motor1.stop();
25+
}));
26+
27+
motor1.resetTachoCount();
28+
motor1.coast();
29+
30+
imperativeLoops();
31+
functionalLoops();
32+
33+
motor1.stop();
34+
}
35+
36+
private static void imperativeLoops() {
37+
38+
int motorPower = 0;
39+
40+
for(int x =0; x <= iterations; x++) {
41+
42+
motorPower = 10 * x;
43+
motor1.setSpeed(motorPower);
44+
motor1.forward();
45+
LOGGER.info("Power: {}", motor1.getSpeed());
46+
47+
Delay.msDelay(DELAY);
48+
}
49+
50+
for(int x =iterations; x >= 0; x--) {
51+
52+
motorPower = 10 * x;
53+
motor1.setSpeed(motorPower);
54+
motor1.forward();
55+
LOGGER.info("Power: {}", motor1.getSpeed());
56+
57+
Delay.msDelay(DELAY);
58+
}
59+
60+
}
61+
62+
private static void functionalLoops() {
63+
64+
IntStream.range(0, iterations)
65+
.forEach( (x) -> {
66+
67+
motor1.setSpeed(10 * x);
68+
motor1.forward();
69+
LOGGER.info("Power: {}", motor1.getSpeed());
70+
71+
Delay.msDelay(DELAY);
72+
});
73+
74+
IntStream.range(0, iterations)
75+
.map(i -> 0 + (iterations - i))
76+
.forEach( (x) -> {
77+
78+
motor1.setSpeed(10 * x);
79+
motor1.forward();
80+
LOGGER.info("Power: {}", motor1.getSpeed());
81+
82+
Delay.msDelay(DELAY);
83+
});
84+
85+
}
86+
87+
}

ev3dev-lang-java/src/main/java/ev3dev/actuators/lego/motors/LargeMotorStopModesExample.java renamed to ev3dev-lang-java/src/main/java/ev3dev/actuators/LargeMotorStopModesExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package ev3dev.actuators.lego.motors;
1+
package examples.actuators;
22

3+
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
34
import lejos.hardware.port.MotorPort;
45
import lejos.utility.Delay;
56

0 commit comments

Comments
 (0)