You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project is meant to show examples using MAVSDK-Java, and is a good place to get started.
4
+
1
5
## Prerequisites
2
6
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:
[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):
9
21
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
+
```
11
25
12
26
## Running the examples
13
27
@@ -19,6 +33,36 @@ The examples can be run with the following commands:
19
33
./gradlew runMission
20
34
```
21
35
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
-
24
36
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:
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")
Copy file name to clipboardExpand all lines: sdk/README.md
+44-5Lines changed: 44 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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):
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
+
1
26
## Contributing
2
27
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!
4
42
5
-
##Project organization
43
+
### Building the SDK
6
44
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:
8
46
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
+
```
10
50
11
-
Most of the gradle setup is shared between the components and can be found in [build.gradle](./build.gradle).
0 commit comments