Skip to content

Commit 6774ede

Browse files
committed
Adding examples for NXTCam & AbsoluteIMU
1 parent af85834 commit 6774ede

13 files changed

+546
-3
lines changed

ev3dev-lang-java/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//Gradle file library ev3dev-lang-java / examples
22
//Author: Juan Antonio Breña Moral
33

4-
version = '0.6.1'
4+
version = '0.7.0'
55

66
apply plugin: 'java'
77
apply plugin: 'eclipse'
@@ -13,8 +13,8 @@ repositories {
1313
}
1414

1515
dependencies {
16-
compile("com.github.ev3dev-lang-java:ev3dev-lang-java:v0.7.1-SNAPSHOT")
17-
compile("com.github.ev3dev-lang-java:lejos-navigation:v0.1.0")
16+
compile("com.github.ev3dev-lang-java:ev3dev-lang-java:0.7.0")
17+
compile("com.github.ev3dev-lang-java:lejos-navigation:0.2.0")
1818

1919
compile("ch.qos.logback:logback-classic:1.2.3")
2020
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ev3dev.sensors.mindsensors;
2+
3+
import lejos.hardware.port.SensorPort;
4+
import lejos.robotics.SampleProvider;
5+
import lejos.utility.Delay;
6+
7+
/**
8+
* Created by jabrena on 3/9/17.
9+
*/
10+
public class AbsoluteIMUAccelerationTest {
11+
12+
private static int HALF_SECOND = 500;
13+
14+
public static void main(String[] args) {
15+
16+
System.out.println("Absolute IMU Demo");
17+
18+
final AbsoluteIMU absoluteIMU = new AbsoluteIMU(SensorPort.S1);
19+
SampleProvider sp = absoluteIMU.getAccelerationMode();
20+
21+
int sampleSize = sp.sampleSize();
22+
System.out.println("Sample Size:" + sampleSize);
23+
float[] sample = new float[sampleSize];
24+
25+
// Takes some samples and prints them
26+
for (int i = 0; i < 10; i++) {
27+
sp.fetchSample(sample, 0);
28+
29+
System.out.println("N={} Sample={}" + i + " " + sample[0]);
30+
System.out.println("N={} Sample={}" + i + " " + sample[1]);
31+
System.out.println("N={} Sample={}" + i + " " + sample[2]);
32+
33+
Delay.msDelay(HALF_SECOND);
34+
35+
}
36+
37+
38+
}
39+
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ev3dev.sensors.mindsensors;
2+
3+
import lejos.hardware.port.SensorPort;
4+
import lejos.robotics.SampleProvider;
5+
import lejos.utility.Delay;
6+
7+
/**
8+
* Created by jabrena on 3/9/17.
9+
*/
10+
public class AbsoluteIMUCompassTest {
11+
12+
private static int HALF_SECOND = 500;
13+
14+
public static void main(String[] args) {
15+
16+
System.out.println("Absolute IMU Demo");
17+
18+
final AbsoluteIMU absoluteIMU = new AbsoluteIMU(SensorPort.S1);
19+
SampleProvider sp = absoluteIMU.getCompassMode();
20+
21+
int sampleSize = sp.sampleSize();
22+
System.out.println("Sample Size:" + sampleSize);
23+
float[] sample = new float[sampleSize];
24+
25+
// Takes some samples and prints them
26+
for (int i = 0; i < 10; i++) {
27+
sp.fetchSample(sample, 0);
28+
29+
System.out.println("N={} Sample={}" + i + " " + sample[0]);
30+
31+
Delay.msDelay(HALF_SECOND);
32+
33+
}
34+
35+
36+
}
37+
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ev3dev.sensors.mindsensors;
2+
3+
import lejos.hardware.port.SensorPort;
4+
import lejos.robotics.SampleProvider;
5+
import lejos.utility.Delay;
6+
7+
/**
8+
* Created by jabrena on 3/9/17.
9+
*/
10+
public class AbsoluteIMUGyroTest {
11+
12+
private static int HALF_SECOND = 500;
13+
14+
public static void main(String[] args) {
15+
16+
System.out.println("Absolute IMU Demo");
17+
18+
final AbsoluteIMU absoluteIMU = new AbsoluteIMU(SensorPort.S1);
19+
SampleProvider sp = absoluteIMU.getGyroMode();
20+
21+
int sampleSize = sp.sampleSize();
22+
System.out.println("Sample Size:" + sampleSize);
23+
float[] sample = new float[sampleSize];
24+
25+
// Takes some samples and prints them
26+
for (int i = 0; i < 10; i++) {
27+
sp.fetchSample(sample, 0);
28+
29+
System.out.println("N={} Sample={}" + i + " " + sample[0]);
30+
System.out.println("N={} Sample={}" + i + " " + sample[1]);
31+
System.out.println("N={} Sample={}" + i + " " + sample[2]);
32+
33+
Delay.msDelay(HALF_SECOND);
34+
35+
}
36+
37+
38+
}
39+
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ev3dev.sensors.mindsensors;
2+
3+
import lejos.hardware.port.SensorPort;
4+
import lejos.robotics.SampleProvider;
5+
import lejos.utility.Delay;
6+
7+
/**
8+
* Created by jabrena on 3/9/17.
9+
*/
10+
public class AbsoluteIMUMagneticTest {
11+
12+
private static int HALF_SECOND = 500;
13+
14+
public static void main(String[] args) {
15+
16+
System.out.println("Absolute IMU Demo");
17+
18+
final AbsoluteIMU absoluteIMU = new AbsoluteIMU(SensorPort.S1);
19+
SampleProvider sp = absoluteIMU.getMagneticMode();
20+
21+
int sampleSize = sp.sampleSize();
22+
System.out.println("Sample Size:" + sampleSize);
23+
float[] sample = new float[sampleSize];
24+
25+
// Takes some samples and prints them
26+
for (int i = 0; i < 10; i++) {
27+
sp.fetchSample(sample, 0);
28+
29+
System.out.println("N={} Sample={}" + i + " " + sample[0]);
30+
System.out.println("N={} Sample={}" + i + " " + sample[1]);
31+
System.out.println("N={} Sample={}" + i + " " + sample[2]);
32+
33+
Delay.msDelay(HALF_SECOND);
34+
35+
}
36+
37+
38+
}
39+
40+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package ev3dev.sensors.mindsensors;
2+
3+
import lejos.hardware.port.SensorPort;
4+
import lejos.robotics.SampleProvider;
5+
import lejos.utility.Delay;
6+
7+
/**
8+
* <b>Mindsensors AbsoluteIMU</b><br>
9+
* Sensor interface for the Mindsensors AbsoluteIMU family of sensors. The
10+
* AbsoluteIMU sensors combine gyro, accelerometer and compass sensors in
11+
* various combinations in a single housing. This interface works with all
12+
* AbsoluteIMU models, but not all modes will work with any particular model.
13+
*
14+
*
15+
* <p>
16+
* <table border=1>
17+
* <tr>
18+
* <th colspan=4>Supported modes</th>
19+
* </tr>
20+
* <tr>
21+
* <th>Mode name</th>
22+
* <th>Description</th>
23+
* <th>unit(s)</th>
24+
* <th>Getter</th>
25+
* </tr>
26+
* <tr>
27+
* <td>Magnetic</td>
28+
* <td>Measures the strength of the magnetic field over three axes</td>
29+
* <td></td>
30+
* <td> {getMagneticMode() }</td>
31+
* </tr>
32+
* <tr>
33+
* <td>Compass</td>
34+
* <td>Measures the orientation of the sensor</td>
35+
* <td>Degrees, corresponding to the compass rose</td>
36+
* <td> {getCompassMode() }</td>
37+
* </tr>
38+
* <tr>
39+
* <td>Angle</td>
40+
* <td>Measures the orientation of the sensor</td>
41+
* <td>Degrees, corresponding to the right hand coordinate system</td>
42+
* <td> {getAngleMode() }</td>
43+
* </tr>
44+
* <tr>
45+
* <td>Acceleration</td>
46+
* <td>The Acceleration mode measures the linear acceleration of the sensor over
47+
* three axes</td>
48+
* <td>Metres/second^2</td>
49+
* <td> {getAccelerationMode() }</td>
50+
* </tr>
51+
* <tr>
52+
* <td>Rate</td>
53+
* <td>The Rate mode measures the angular speed of the sensor over three axes</td>
54+
* <td>Degrees/second</td>
55+
* <td> {getRateMode() }</td>
56+
* </tr>
57+
* </table>
58+
*
59+
*
60+
* <p>
61+
*
62+
* <b>Sensor configuration</b><br>
63+
* The gyro sensor of the AbsoluteIMU uses a filter to remove noise from
64+
* the samples. The filter can be configured using the {setGyroFilter }
65+
* method. <br>
66+
* The compass sensor of the AbsoluteIMU can be calibrated to compensate for magnetical disturbances on the robot (soft iron
67+
* calibration) using the {#startCalibration} and {stopCalibration}
68+
* methods.<p>
69+
* To calibrate Compass, mount it on your robot where it will be used and
70+
* issue startCalibration method and then rotate AbsoluteIMU slowly along all
71+
* three axes. (The Compass in AbsoluteIMU is a 3 axis compass, and hence
72+
* needs to be turned along all three axes, and if it's mounted on your robot,
73+
* the whole robot needs to rotate). Rotate one axis at a time, turn once in
74+
* clock-wise direction completing at-least 360 degrees, and then turn it in
75+
* anti-clock-wise direction, then go to next axis. Upon finishing turning
76+
* along all axes, issue stopCalibration method.
77+
*
78+
*
79+
* <p>
80+
*
81+
* See <a href=
82+
* "http://mindsensors.com/index.php?module=documents&JAS_DocumentManager_op=downloadFile&JAS_File_id=1369"
83+
* >Mindsensors IMU user guide"> Sensor Product page </a>
84+
* See <a href="http://sourceforge.net/p/lejos/wiki/Sensor%20Framework/"> The
85+
* leJOS sensor framework</a>
86+
* See {@link lejos.robotics.SampleProvider leJOS conventions for
87+
* SampleProviders}
88+
*
89+
* <p>
90+
*
91+
*
92+
* @author Andy, Juan Antonio Breña Moral
93+
*
94+
*/
95+
public class AbsoluteIMUTiltTest {
96+
97+
private static int HALF_SECOND = 500;
98+
99+
public static void main(String[] args) {
100+
101+
System.out.println("Absolute IMU Demo");
102+
103+
final AbsoluteIMU absoluteIMU = new AbsoluteIMU(SensorPort.S1);
104+
SampleProvider sp = absoluteIMU.getTiltMode();
105+
106+
int sampleSize = sp.sampleSize();
107+
System.out.println("Sample Size:" + sampleSize);
108+
float[] sample = new float[sampleSize];
109+
110+
// Takes some samples and prints them
111+
for (int i = 0; i < 10; i++) {
112+
sp.fetchSample(sample, 0);
113+
114+
System.out.println("N={} Sample={}" + i + " " + sample[0]);
115+
System.out.println("N={} Sample={}" + i + " " + sample[1]);
116+
System.out.println("N={} Sample={}" + i + " " + sample[2]);
117+
118+
Delay.msDelay(HALF_SECOND);
119+
120+
}
121+
122+
123+
}
124+
125+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ev3dev.sensors.mindsensors;
2+
3+
4+
import ev3dev.actuators.Sound;
5+
import ev3dev.sensors.mindsensors.NXTCamV5;
6+
import lejos.hardware.port.SensorPort;
7+
import lejos.utility.Delay;
8+
9+
/**
10+
* Created by jabrena on 30/7/17.
11+
*/
12+
public class CreatePhotoDemo {
13+
14+
public static void main(String[] args){
15+
16+
System.out.println("NXTCamV5 create Photo Demo");
17+
18+
final NXTCamV5 camera = new NXTCamV5(SensorPort.S1);
19+
20+
int counter = 0;
21+
boolean flag = true;
22+
while (flag) {
23+
24+
Delay.msDelay(5000);
25+
System.out.println("Creating photo");
26+
camera.createPhoto();
27+
Sound.getInstance().beep();
28+
Delay.msDelay(500);
29+
30+
counter++;
31+
if(counter > 5){
32+
break;
33+
}
34+
}
35+
36+
System.exit(0);
37+
}
38+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ev3dev.sensors.mindsensors;
2+
3+
4+
import ev3dev.actuators.Sound;
5+
import ev3dev.sensors.Button;
6+
import ev3dev.sensors.mindsensors.NXTCamV5;
7+
import lejos.hardware.port.SensorPort;
8+
import lejos.utility.Delay;
9+
10+
/**
11+
* Created by jabrena on 30/7/17.
12+
*/
13+
public class CreatePhotoEV3Demo {
14+
15+
public static void main(String[] args){
16+
17+
System.out.println("NXTCamV5 create Photo Demo");
18+
19+
final NXTCamV5 camera = new NXTCamV5(SensorPort.S1);
20+
21+
while (Button.ESCAPE.isUp()) {
22+
23+
Button.waitForAnyPress();
24+
Delay.msDelay(5000);
25+
System.out.println("Creating photo");
26+
camera.createPhoto();
27+
Sound.getInstance().beep();
28+
Delay.msDelay(500);
29+
30+
}
31+
32+
System.exit(0);
33+
}
34+
}

0 commit comments

Comments
 (0)