10000 Adding doc for EV3 US Sensor · ev3dev-lang-java/docs@de068e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit de068e9

Browse files
committed
Adding doc for EV3 US Sensor
1 parent 62f19a1 commit de068e9

File tree

7 files changed

+109
-3
lines changed

7 files changed

+109
-3
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ev3dev.sensors.ev3;
2+
3+
import lejos.hardware.port.SensorPort;
4+
import lejos.robotics.SampleProvider;
5+
import lejos.utility.Delay;
6+
7+
public class USSensorDemo {
8+
9+
private static EV3UltrasonicSensor us1 = new EV3UltrasonicSensor(SensorPort.S1);
10+
11+
public static void main(String[] args) {
12+
13+
final SampleProvider sp = us1.getDistanceMode();
14+
int distanceValue = 0;
15+
16+
final int iteration_threshold = 100;
17+
for(int i = 0; i <= iteration_threshold; i++) {
18+
19+
float [] sample = new float[sp.sampleSize()];
20+
sp.fetchSample(sample, 0);
21+
distanceValue = (int)sample[0];
22+
23+
System.out.println("Iteration: " + i + ", Distance: " + distanceValue);
24+
25+
Delay.msDelay(500);
26+
}
27+
28+
}
29+
30+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package ev3dev.sensors.ev3;
2+
3+
import ev3dev.sensors.Battery;
4+
import lejos.hardware.port.SensorPort;
5+
import lejos.robotics.SampleProvider;
6+
import lejos.utility.Delay;
7+
8+
public class USSensorDemo2 {
9+
10+
//Robot Configuration
11+
private static EV3UltrasonicSensor us1 = new EV3UltrasonicSensor(SensorPort.S1);
12+
13+
//Configuration
14+
private static int HALF_SECOND = 500;
15+
16+
public static void main(String[] args) {
17+
18+
SampleProvider sp;
19+
20+
int distanceValue = 0;
21+
22+
for(int i = 0; i <= 10; i++) {
23+
24+
sp = us1.getListenMode();
25+
int sampleSize = sp.sampleSize();
26+
float[] sample = new float[sampleSize];
27+
sp.fetchSample(sample, 0);
28+
29+
Delay.msDelay(2000);
30+
31+
sp = us1.getDistanceMode();
32+
sampleSize = sp.sampleSize();
33+
sample = new float[sampleSize];
34+
sp.fetchSample(sample, 0);
35+
36+
distanceValue = (int)sample[0];
37+
38+
System.out.println("Iteration: {}, Distance: {}" + i + " "+ distanceValue);
39+
40+
}
41+
42+
System.out.println(Battery.getInstance().getVoltage());
43+
}
44+
45+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# EV3 Ultrasonic Sensor
2+
3+
## Introduction
4+
5+
The digital EV3 Ultrasonic Sensor generates sound waves and reads their echoes to detect and measure distance from objects. It can also send single sound waves to work as sonar or listen for a sound wave that triggers the start of a program. Students could design a traffic-monitoring system and measure distances between vehicles, for instance. There is an opportunity to discover how the technology is used in everyday items like automatic doors, cars and manufacturing systems.
6+
7+
* Measures distances between one and 250 cm
8+
* Front illumination is constant while emitting and blinks while listening
9+
10+
image:./ev3_us_sensor.png[image]
11+
12+
## How to use the sensor
13+
14+
### Example to read distances
15+
16+
[source,java]
17+
----
18+
include::./USSensorDemo.java[]
19+
----
20+
21+
### Example to use the Listen Mode
22+
23+
[source,java]
24+
----
25+
include::./USSensorDemo2.java[]
26+
----
27+
28+
**References**
29+
30+
https://shop.lego.com/en-GB/EV3-Ultrasonic-Sensor-45504
31+
Loading

src/main/asciidoc/sensors/ev3_gyro_sensor.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= EV3 Gyro sensor
1+
# EV3 Gyro sensor
22

33
The digital EV3 Gyro Sensor measures the robot’s rotational motion and changes in its orientation.
44

src/main/asciidoc/sensors/index.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ In same way, in a Robot, it is possible to use sensors in your robots to get dat
1515
1616
### Exteroceptors sensors
1717

18-
* link:ev3_us_sensor.html[Ultrasonic sensor]
18+
* link:ev3-us-sensor/ev3_us_sensor.html[Ultrasonic sensor]
1919
* link:ev3_ir_sensor.html[Infrared sensor]
2020
* link:ev3_touch_sensor.html[Touch sensor]
2121
* link:ev3_light_sensor.html[Light sensor]
@@ -43,7 +43,7 @@ image:./31313.png[image]
4343

4444
The Kit includes the following sensors:
4545

46-
* link:ev3_us_sensor.html[Ultrasonic sensor] x1
46+
* link:ev3-us-sensor/ev3_us_sensor.html[Ultrasonic sensor] x1
4747
* link:ev3_touch_sensor.html[Touch sensor] x2
4848
* link:ev3_light_sensor.html[Light sensor] x1
4949
* link:ev3_gyro_sensor.html[Gyro sensor] x1

0 commit comments

Comments
 (0)
0