Skip to content

Commit 97e63b8

Browse files
improve READMEs
1 parent 0d3defc commit 97e63b8

File tree

6 files changed

+121
-18
lines changed

6 files changed

+121
-18
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ This is the Java frontend implementation to [MAVSDK](https://github.com/mavlink/
44

55
It is organized as follows:
66

7-
* The [sdk](./sdk) directory contains the different components provided by this project.
87
* The [examples](./examples) directory contains Java and Android examples using the sdk.
8+
* The [sdk](./sdk) directory contains the actual SDK.
99

10-
## Contributing
10+
Detailed instructions on how to run the examples and how to build the SDK are available in
11+
those directories.
1112

12-
Please read the "Contributing" section of the specific project you are interested in.
13+
## QuickStart
14+
15+
The fastest way to start is to follow the instructions in the README of the [java-client](./examples/java-client) example.
1316

1417
## Coding style
1518

16-
Java/Android coding style is ensured using CheckStyle with the Google configurations.
19+
Java/Android coding style is ensured using CheckStyle with the Google style.
1720

1821
### Command line
1922

examples/java-client/README.md

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1+
# Java client
2+
3+
This project is meant to show examples using MAVSDK-Java, and is a good place to get started.
4+
15
## Prerequisites
26

3-
The examples include MAVSDK-Java using gradle, but `protoc-gen-dcsdk` must be in your PATH. It requires Python 3.6+ and can be built from `sdk/proto/pb_plugins` by running:
7+
MAVSDK-Java will connect to a running instance of `mavsdk_server`, that can be downloaded from the [MAVSDK release page](https://github.com/mavlink/MAVSDK/releases).
8+
9+
Running `mavsdk_server` from the command line will show output similar to the following:
410

5-
```sh
6-
pip install -r requirements.txt
7-
pip install -e .
811
```
12+
$ ./mavsdk_server
13+
[02:58:29|Info ] MAVSDK version: 0.18.3-51-g0c2c48f1 (mavsdk_impl.cpp:25)
14+
[02:58:29|Debug] New: System ID: 0 Comp ID: 0 (mavsdk_impl.cpp:361)
15+
[02:58:29|Info ] Server set to listen on 0.0.0.0:50051 (grpc_server.cpp:44)
16+
[02:58:29|Info ] Server started (grpc_server.cpp:28)
17+
[02:58:29|Info ] Waiting to discover system... (connection_initiator.h:58)
18+
```
19+
20+
The other requirement is to have a MAVLink drone (or simulator) running. You can get started with the simulation environment [here](https://dev.px4.io/master/en/simulation/). If using docker, an alternative is to run a headless gazebo instance, as described [here](https://github.com/JonasVautherin/px4-gazebo-headless):
921

10-
Make sure to add `protoc-gen-dcsdk` to your PATH, and try to run the examples!
22+
```sh
23+
$ docker run --rm -it jonasvautherin/px4-gazebo-headless:v1.9.2
24+
```
1125

1226
## Running the examples
1327

@@ -19,6 +33,36 @@ The examples can be run with the following commands:
1933
./gradlew runMission
2034
```
2135

22-
The examples will connect to a running `mavsdk_server` instance. The `mavsdk_server` binary can be downloaded from the [MAVSDK release page](https://github.com/mavlink/mavsdk/releases).
23-
2436
Note that running `./gradlew run` will default to `takeoffAndLand`.
37+
38+
## Playing with jshell, the Java REPL
39+
40+
It can be useful to start with the REPL to get a feeling of how MAVSDK-Java works. Try to start jshell from gradle (note: that may not work on all platforms):
41+
42+
```sh
43+
./gradlew jshell
44+
```
45+
46+
If everything goes well, you should now be in an interactive jshell, showing the prompt:
47+
48+
```
49+
jshell>
50+
```
51+
52+
Let's start by importing the `Action` plugin:
53+
54+
```
55+
jshell> import io.mavsdk.action.Action
56+
```
57+
58+
We can now instantiate an `action` object:
59+
60+
```
61+
jshell> Action action = new Action()
62+
```
63+
64+
And, given that `mavsdk_server` is running and connected to a (possibly simulated) drone, we can directly takeoff:
65+
66+
```
67+
jshell> action.arm().andThen(action.takeoff()).subscribe()
68+
```

examples/java-client/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ task runMission(dependsOn: 'classes', type: JavaExec) {
2929
classpath = sourceSets.main.runtimeClasspath
3030
}
3131

32+
task exportDeps(type: Copy) {
33+
from sourceSets.main.runtimeClasspath into 'build/jshell_classpath_export/'
34+
}
35+
36+
task jshell(dependsOn: 'exportDeps', type: Exec) {
37+
print("\n\n=======\nWARNING: this is not the best way to run `jshell`, as it may not be cross-platform and it won't have auto-completion enabled.\nYou may want to run the following instead:\n\n \$ ./gradlew exportDeps\n \$ jshell --class-path \$(ls -d build/jshell_classpath_export/* | tr '\\n' ':')\n=======\n\n")
38+
standardInput = System.in
39+
commandLine 'bash', '-c', "jshell --class-path \$(ls -d build/jshell_classpath_export/* | tr '\\n' ':')"
40+
}
41+
3242
task checkstyle(type: Checkstyle) {
3343
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
3444
source 'src'
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
rootProject.name = 'TakeoffAndLand'
1+
rootProject.name = 'MAVSDK-Java-example'
22

3-
includeBuild '../../sdk'
3+
// Uncomment the following line to use the SDK built from sources.
4+
// This will require `protoc-gen-dcsdk` to be in your PATH. See
5+
// the README in ../../sdk for more instructions about building
6+
// from sources.
7+
//includeBuild '../../sdk'

examples/java-client/src/main/java/io/mavsdk/example/TakeoffAndLand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ public static void main(String[] args) {
1616
CountDownLatch latch = new CountDownLatch(1);
1717

1818
action.arm()
19+
.doOnComplete(() -> logger.debug("Arming..."))
1920
.andThen(action.takeoff())
21+
.doOnComplete(() -> logger.debug("Taking off..."))
2022
.delay(5, TimeUnit.SECONDS)
2123
.andThen(action.land())
24+
.doOnComplete(() -> logger.debug("Landing..."))
2225
.doOnComplete(() -> latch.countDown())
2326
.subscribe();
2427

sdk/README.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1+
# MAVSDK-Java - SDK
2+
3+
This project is the actual Java SDK that gets deployed on [Maven Central](https://search.maven.org/search?q=a:mavsdk). It works by connecting to a running instance of `mavsdk_server`, that can be downloaded from the [MAVSDK release artifacts](https://github.com/mavlink/MAVSDK/releases). By default, it connects on a `mavsdk_server` instance running locally (i.e. on 'localhost'), but it can connect on any machine over the network.
4+
5+
## Getting started
6+
7+
Because it is deployed on Maven Central, adding MAVSDK-Java to your project is a matter of adding the dependency to your gradle file:
8+
9+
```groovy
10+
dependencies {
11+
implementation 'io.mavsdk:mavsdk:0.1.0'
12+
}
13+
```
14+
15+
In your project, it can then be used to e.g. takeoff with the following (assuming an instance of `mavsdk_server` is running):
16+
17+
```java
18+
import io.mavsdk.action.Action
19+
20+
Action action = new Action();
21+
action.arm().andThen(action.takeoff()).subscribe();
22+
```
23+
24+
Note that the MAVSDK-Java API is using [RxJava](https://github.com/ReactiveX/RxJava), for which extensive documentation can be found online. Don't forget to have a look at our [examples](../examples).
25+
126
## Contributing
227

3-
The SDK implements the MAVSDK protobuf interfaces by using RxJava and TDD-style. This means that every single public method of a component must be unit-tested.
28+
MAVSDK-Java is mainly autogenerated from the MAVSDK [proto files](./proto), using our [protoc-gen-dcsdk plugin](./proto/pb_plugins) and [templates](./templates). Before starting contributing, learn to build from sources (below).
29+
30+
## Building from sources
31+
32+
### Prerequisites
33+
34+
MAVSDK-Java is built using gradle, but `protoc-gen-dcsdk` must be in your PATH in order to auto-generate the code. It requires Python 3.6+ and can be built from `sdk/proto/pb_plugins` by running:
35+
36+
```sh
37+
pip install -r requirements.txt
38+
pip install -e .
39+
```
40+
41+
Make sure to add `protoc-gen-dcsdk` to your PATH!
442

5-
## Project organization
43+
### Building the SDK
644

7-
This is the root of the main "sdk" project, composed of multiple modules. Each module corresponds to a component defined by a protobuf interface (see [MAVSDK-Proto](https://github.com/mavlink/MAVSDK-Proto)).
45+
Once the prerequisites are met, the SDK can be built with:
846

9-
Each module is only building a specific part of the overall protobuf interface by using a symbolic link to the corresponding folder in MAVSDK-Proto (see for instance [the core module](https://github.com/mavlink/MAVSDK-Proto)).
47+
```sh
48+
./gradlew build
49+
```
1050

11-
Most of the gradle setup is shared between the components and can be found in [build.gradle](./build.gradle).

0 commit comments

Comments
 (0)