-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFirstRobot.java
More file actions
59 lines (44 loc) · 1.7 KB
/
MyFirstRobot.java
File metadata and controls
59 lines (44 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package examples;
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import ev3dev.sensors.Battery;
import lejos.hardware.port.MotorPort;
import lejos.utility.Delay;
public class MyFirstRobot {
public static void main(final String[] args){
System.out.println("Creating Motor A & B");
final EV3LargeRegulatedMotor motorLeft = new EV3LargeRegulatedMotor(MotorPort.A);
final EV3LargeRegulatedMotor motorRight = new EV3LargeRegulatedMotor(MotorPort.B);
//To Stop the motor in case of pkill java for example
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
System.out.println("Emergency Stop");
motorLeft.stop();
motorRight.stop();
}
}));
System.out.println("Defining the Stop mode");
motorLeft.brake();
motorRight.brake();
System.out.println("Defining motor speed");
final int motorSpeed = 200;
motorLeft.setSpeed(motorSpeed);
motorRight.setSpeed(motorSpeed);
System.out.println("Go Forward with the motors");
motorLeft.forward();
motorRight.forward();
Delay.msDelay(2000);
System.out.println("Stop motors");
motorLeft.stop();
motorRight.stop();
System.out.println("Go Backward with the motors");
motorLeft.backward();
motorRight.backward();
Delay.msDelay(2000);
System.out.println("Stop motors");
motorLeft.stop();
motorRight.stop();
System.out.println("Checking Battery");
System.out.println("Votage: " + Battery.getInstance().getVoltage());
System.exit(0);
}
}