Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial MoCap service #105

Merged
merged 8 commits into from
Oct 10, 2019
Merged

Initial MoCap service #105

merged 8 commits into from
Oct 10, 2019

Conversation

irsdkv
Copy link
Contributor

@irsdkv irsdkv commented Sep 5, 2019

This is a draft to MoCap plugin API implementation.
I allowed myself to move slightly away from the usual API. May be you will find it useful.
Please let me know is that interface ok.

Links:
External Positioning
VISION_POSITION_ESTIMATE
MAVSDK PR

@irsdkv
Copy link
Contributor Author

irsdkv commented Sep 5, 2019

I'm founded that MAVSDK-Python protoc generator don't agree with my API :)

@JonasVautherin
Copy link
Collaborator

JonasVautherin commented Sep 9, 2019

I'm founded that MAVSDK-Python protoc generator don't agree with my API :)

Oh, because you send a stream. Yep, that's something new 😅. But fortunately the last of 4 types of RPC supported by gRPC 🙂.

@irsdkv
Copy link
Contributor Author

irsdkv commented Sep 10, 2019

I'm founded that MAVSDK-Python protoc generator don't agree with my API :)

Oh, because you send a stream. Yep, that's something new . But fortunately the last of 4 types of RPC supported by gRPC .

Yes, API change resolved this problem. I was not tested yet, but generation works ok :)

irsdkv added a commit to irsdkv/MAVSDK that referenced this pull request Sep 11, 2019
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
Copy link
Collaborator

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see this interface be limited to a tested and supported easy to use subset instead of just exposing/duplicating everything that MAVLink has.

Not that this is part of the reason why MAVSDK exists in the first place. It's because the MAVLink API is huge and it's unclear what is supported, what should be used and how and by having a small simple stupid API it becomes much more usable.

protos/mocap/mocap.proto Outdated Show resolved Hide resolved
irsdkv added a commit to irsdkv/MAVSDK-Proto that referenced this pull request Sep 19, 2019
    Deprecated frames reset due to mavlink#105 (review)
    Method of uncnown covariance arrays define changed due to mavlink#105 (comment)
irsdkv added a commit to irsdkv/MAVSDK-Proto that referenced this pull request Sep 19, 2019
    Deprecated frames reset due to mavlink#105 (review)
    Method of unknown covariance arrays define changed
        due to mavlink#105 (comment)
irsdkv added a commit to irsdkv/MAVSDK that referenced this pull request Sep 19, 2019
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
@irsdkv
Copy link
Contributor Author

irsdkv commented Sep 24, 2019

Hm.
I found that Python generator doesn't work fine outside naming like SetWhatever(SetWhateverRequest) returns([stream] SetWhateverResponse).
It is not ok for testing and using.
At this time I tested single request-response scheme and it work ok in around of 30Hz on 433MHz radio.
Now I think that fastest and clearest way to implement this module will be using this "old" way (single request-response).

@irsdkv irsdkv force-pushed the pr-mocap branch 4 times, most recently from 6129752 to 10611f0 Compare September 24, 2019 16:17
@irsdkv
Copy link
Contributor Author

irsdkv commented Sep 25, 2019

Small test result:
This implementation (with this commit in Backend) has reached more than 250Hz frequency of sending VisualPositionEstimate using MAVSDK-Python and ESP8266-12e link.

@julianoes
Copy link
Collaborator

Oh nice!

@JonasVautherin
Copy link
Collaborator

I found that Python generator doesn't work fine outside naming like SetWhatever(SetWhateverRequest) returns([stream] SetWhateverResponse).

Yes, because we would need to extend the generator to support client streams.

@julianoes: do you think we should go for this implementation right now, and possibly move to a client-side stream later if that gets contributed?

@irsdkv: how would you represent a client stream in python? A server stream becomes a generator, but I'm not sure what a client stream should be 😊

@irsdkv
Copy link
Contributor Author

irsdkv commented Sep 25, 2019

@julianoes: do you think we should go for this implementation right now, and possibly move to a client-side stream later if that gets contributed?

One more day for me please :)
Now I'm trying to implement Telemetry Odometry stream. I would try to reach more compatibility for Odometry types in Mocap and Telemetry (may be in future they will go outside plugins in common types header).

@irsdkv: how would you represent a client stream in python? A server stream becomes a generator, but I'm not sure what a client stream should be

I tried to hardcode it, but it is too complicated for me now. So I have no idea how client stream should be implemented :)

@JonasVautherin
Copy link
Collaborator

So I have no idea how client stream should be implemented :)

I did not mean how the protoc plugin should be implemented, but the actual python code. Say SetVisionPositionEstimate is a client stream, that could be something like:

position_estimate_subject = drone.mocap.set_vision_position_estimate()

while True:
    position_estimate_subject.post("the new value I want to send to the server")

position_estimate_subject.close()

For instance. Well, adapted for asyncio, somehow. What do you think?

@irsdkv
Copy link
Contributor Author

irsdkv commented Sep 26, 2019

For instance. Well, adapted for asyncio, somehow. What do you think?

Hm. May be I will try it later.

@irsdkv
Copy link
Contributor Author

irsdkv commented Sep 28, 2019

position_estimate_subject = drone.mocap.set_vision_position_estimate()

while True:
    position_estimate_subject.post("the new value I want to send to the server")

position_estimate_subject.close()

I definitely try it later (may be next week). But may be make sense go for this implementation at this moment?
So we will have some worked implementation as the reference.

@irsdkv
Copy link
Contributor Author

irsdkv commented Oct 2, 2019

So, tests showed that the current implementation works correctly.

In this case need to adjust FMU parameters but all related to plugin works ok.

"Fake" VisualPositionEstimate streaming (x10 time-scale):
image

Real position OTA VisualPositionEstimate streaming (x10 time-scale):
image

@JonasVautherin
Copy link
Collaborator

I definitely try it later (may be next week). But may be make sense go for this implementation at this moment?

Sure, let's do that.

protos/mocap/mocap.proto Outdated Show resolved Hide resolved
@irsdkv irsdkv force-pushed the pr-mocap branch 3 times, most recently from 2d482fd to 306d000 Compare October 4, 2019 12:40
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
protos/mocap/mocap.proto Outdated Show resolved Hide resolved
    1. Intendation fix
    2. Removing Mav Frames currently unused in PX4
    3. Renaming AttPosMocap -> AttitudePositionMocap
    4. Reusing common types like Covariance
    5. Comments added
    6. Change Client-server streaming to single
       request-response
    7. Units added
    8. Odometry refactor due to Telemetry::Odometry.
irsdkv added a commit to irsdkv/MAVSDK that referenced this pull request Oct 5, 2019
irsdkv added a commit to irsdkv/MAVSDK that referenced this pull request Oct 5, 2019
message Odometry {
// Mavlink frame id
enum MavFrame {
STUB = 0; // Stub for Protobuf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a STUB for protobuf?

Copy link
Contributor Author

@irsdkv irsdkv Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In MAVSDK (without STUB):

$ ./generate_from_protos.sh 
-------------------------------
 Generating pb and grpc.pb files
    * protoc --version: libprotoc 3.9.1
-------------------------------

mocap/mocap.proto:64:20: The first enum value must be zero in proto3.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't that mean that BODY_FRD should be = 0 instead of = 12? See here: https://developers.google.com/protocol-buffers/docs/proto3#enum.

And then the next ones like BODY_FLU could be 1, 2, etc. Or does it conflict with something else?

Copy link
Contributor Author

@irsdkv irsdkv Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that setting BODY_FRD = 0 may be confusing for gRPC-client users.
For example in MAVSDK-Python:
I manually changed generated code to delete STUB and set real values of enum members.
This will not conflict for any user-defined code which operated with MAVLink-defined constants (for example MOCAP_NED eq 14).
And also, on the other hand, bindings for gRPC plugins to other languages will be produced with users which familiar with MAVSDK and MAVLink and they will can also remove stubs from final API.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is BODY_FRD = 0 confusing? I don't get that 😕.

Copy link
Collaborator

@JonasVautherin JonasVautherin Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also static_cast will not work for casting ever more in plugin_service_impl.h :)

Yes, static_cast is convenient, but it requires a unit test to make sure that it works. If it doesn't, then we need to write more verbose code, which I believe can still be auto-generated. So I believe that I'm fine with losing the ability to static_cast: it would force us to have clearer (but more verbose) code in C++, and it wouldn't add a weird case in the templates.

My fear is this: if we make it difficult to write a template, then it will make it difficult to contribute new languages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more info from docs:

For enums, the default value is the first defined enum value, which must be 0.

So 0 is default. I don't know in which cases uses default values. May be this also need to take into consideration.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the default value in case you don't specify it. In many cases we have UNKNOWN = 0. But also, we always specify a value in the code we generate. So I don't think that has any effect for us.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote for this: we remove STUB, and we start the others at 0 (i.e. we don't care about the MAVLink enum ids). If then we see that this makes it very confusing for python users, we can change the python templates to make it more intuitive.

This way we don't propagate a weird STUB to all the other languages.

What do you think? 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this make sense. I will do corresponding changes.

Copy link
Collaborator

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I think this might be sane to get in and then go from there.

protos/mocap/mocap.proto Outdated Show resolved Hide resolved
@julianoes julianoes merged commit f7bbe32 into mavlink:master Oct 10, 2019
@irsdkv irsdkv deleted the pr-mocap branch October 10, 2019 09:53
@irsdkv irsdkv restored the pr-mocap branch October 14, 2019 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants