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

Add actuator control to offboard plugin #782

Merged
merged 19 commits into from
Jul 18, 2019

Conversation

irsdkv
Copy link
Collaborator

@irsdkv irsdkv commented Jul 2, 2019

Implementation of set_actuator_control method due to #771 (review).

I think that this solution most corresponds to mavlink message specification compared first PR.

Also in protobuf3 "0" is the default for numeric types so this would hide the complexity.

The corresponding MAVSDK-Proto PR is here.

@irsdkv irsdkv changed the title Add direct control with not specified group names Add offboard/set_actuator_control to offboard plugin with not specified group names Jul 2, 2019
@irsdkv irsdkv changed the title Add offboard/set_actuator_control to offboard plugin with not specified group names Add offboard/set_actuator_control to offboard plugin without specifying group names Jul 2, 2019
@irsdkv irsdkv force-pushed the add-direct-control-with-group branch 3 times, most recently from dae4c49 to 60bcc8a Compare July 2, 2019 17:27
@irsdkv irsdkv force-pushed the add-direct-control-with-group branch from 60bcc8a to 295fbe4 Compare July 2, 2019 18:07
@irsdkv
Copy link
Collaborator Author

irsdkv commented Jul 8, 2019

Hi @julianoes

I tried to implement your suggestion.
Also I tried to avoid unnecessary load on the FMU by passing the length of the array in MAVSDK API method and avoid to sent unnecessary message for Group 1.

If I misunderstand something I will be grateful if you will explain it.
This feature is important for us and also we want to implement really good solution for community :)

Thank you!

@julianoes
Copy link
Collaborator

@irsdkv what do you think about this suggestion? #771 (comment)

So the API would be:

std::array<float, 16> actuators = { 0.1, 0.2, 0.3, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

and if the last 8 entries are zero, we only send the message to control group 0, and we don't need to send the message to control group 1.

Would that work?

@irsdkv
Copy link
Collaborator Author

irsdkv commented Jul 8, 2019

and if the last 8 entries are zero, we only send the message to control group 0, and we don't need to send the message to control group 1.

Unfortunately, due to px4 uORB subscription subsystem, if we need to fill all controls to zero - we should send all-zero message. If we don't do this then actuator_controls_1 subscribers will not receive zeroed controls and the actual control values will still remain the previously received (non-zero) values.

@julianoes
Copy link
Collaborator

Ok, what about NAN?

@irsdkv
Copy link
Collaborator Author

irsdkv commented Jul 8, 2019

Ok, what about NAN?

Hm. I think that this can be a possible solution

@irsdkv irsdkv force-pushed the add-direct-control-with-group branch 2 times, most recently from 6db0e64 to 3fd30c2 Compare July 8, 2019 18:25
@irsdkv irsdkv force-pushed the add-direct-control-with-group branch from 3fd30c2 to ea7a971 Compare July 8, 2019 18:27
to 7 in Group 0 will be set to zero.
If index of first NAN value will be great than 8 then two messages (to
Group 0 and Group 1) will be sent. In this case all controls from first NAN value
to 7 in Group 1 will be set to zero. */
Copy link
Collaborator Author

@irsdkv irsdkv Jul 8, 2019

Choose a reason for hiding this comment

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

Perhaps this description can be more understandable :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

😄 what about:

Up to 16 actuator controls can be set. To ignore an output, set it to NaN.
The first 8 actuator controls internally map to control group 0, the latter 8 actuator controls map to control group 1.
Depending on what controls are set (instead of NaN) 1 or 2 MAVLink messages are actually sent.

Given that description is a bit awkward, would it be clearer, like that:

struct ActuatorControl {
    struct Group {
        float controls[8];
    };
    Group groups[2];
}

(Or is that almost what you had suggested in the beginning? Sorry for the long discussion)

Copy link
Collaborator Author

@irsdkv irsdkv Jul 9, 2019

Choose a reason for hiding this comment

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

All ok, I understand that you just want to construct a good solution :)

struct ActuatorControl {
    struct Group {
        float controls[8];
    };
    Group groups[2];
}

This is the possible solution, but In this case, in my assumption we need to change ActuatorControl structure in Proto too due to API "consistency". It can be like that:

message ControlGroup {
  repeated float controls = 1;
}
message ActuatorControl {
  repeated ControlGroup control_group = 1;
}

But this will be too comlpicated?


If you just don't want to have field like group_number in data types then I have this proposal:

struct ActuatorControl {
    struct Group {
        float controls[8];
    };
    union {
        Group groups[2];
        float controls[16];
    };
}

In this case current protobuf message can be used.
Also description of usage can be like that:

Up to 16 actuator controls can be set. To ignore an **output group**, set it to NaN. 
In case of **all** controls in the group is NaN than this group will not be sent (otherwise all NaN controls will sent as zero).
The first 8 actuator controls internally map to control group 0, the latter 8 actuator controls map to control group 1.
Depending on what controls are set (instead of NaN) 1 or 2 MAVLink messages are actually sent. 

What do you think about it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

message ControlGroup {
 repeated float controls = 1;
}
message ActuatorControl {
 repeated ControlGroup control_group = 1;
}

But this will be too comlpicated?

I'd say that's fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I will implement it.
In this case the union is not required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@irsdkv irsdkv force-pushed the add-direct-control-with-group branch from 1e49244 to 05c6028 Compare July 9, 2019 15:22
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.

Thanks, mostly ok, I think.

src/plugins/offboard/offboard.cpp Outdated Show resolved Hide resolved
src/plugins/offboard/offboard_impl.cpp Show resolved Hide resolved
julianoes
julianoes previously approved these changes Jul 10, 2019
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.

Great thanks for the continuous changes!

@irsdkv
Copy link
Collaborator Author

irsdkv commented Jul 10, 2019

It's a pleasure. Thank you too 😄

@julianoes
Copy link
Collaborator

CI complains about std::isnan:

/home/user/DronecodeSDK/src/plugins/offboard/offboard.cpp:92:18: error: '__builtin_isnan' is not a member of 'std'
             if ((std::isnan(lhs.groups[i].controls[j]) && std::isnan(rhs.groups[i].controls[j])) ||
                  ^

Try adding #include <cmath> in offboard.cpp.

@julianoes
Copy link
Collaborator

Looks like the grpc service doesn't quite compile (anymore):
https://travis-ci.org/mavlink/MAVSDK/jobs/556753980#L7412

@irsdkv
Copy link
Collaborator Author

irsdkv commented Jul 10, 2019

Looks like the grpc service doesn't quite compile (anymore):
https://travis-ci.org/mavlink/MAVSDK/jobs/556753980#L7412

My bad. Seems like just need to update proto submodule rev

@julianoes
Copy link
Collaborator

I think now you only need:

./tools/fix_style.sh .

@irsdkv
Copy link
Collaborator Author

irsdkv commented Jul 11, 2019

Done

@JonasVautherin
Copy link
Collaborator

@irsdkv Thanks for all the work! We recently fixed the clang-format issues, that should be fine now. Sorry for the inconvenience there 😅.

Can you try fix_style again, from latest develop? Just want to make sure it works for you as well. If not I'll have to investigate.

@irsdkv
Copy link
Collaborator Author

irsdkv commented Jul 16, 2019

I think all works ok :)

@JonasVautherin
Copy link
Collaborator

Hmm somehow it seems like some styling was still wrong. I pushed a fix, let's hope it works this time :-).

@irsdkv
Copy link
Collaborator Author

irsdkv commented Jul 16, 2019

Hmm somehow it seems like some styling was still wrong. I pushed a fix, let's hope it works this time :-).

Oh, sorry. It was my changes. I did it because I thought it was more readable and similarly to other functions like this. I apologize for not telling you this.

P.S. Whew. Seems that this pull request has a hard fate :)

@JonasVautherin
Copy link
Collaborator

Oh, you're missing some docs (see Jenkins):

Parsing file /tmp/jenkins/workspace/mavlink_MAVSDK_PR-782/tools/docs/install/include/mavsdk/plugins/camera/came/tmp/jenkins/workspace/mavlink_MAVSDK_PR-782/tools/docs/install/include/mavsdk/plugins/offboard/offboard.h:151: warning: Compound mavsdk::Offboard::ActuatorControl::Group is not documented.

Please check doxygen warnings.

Good news is that this is the last CI test 😆

@JonasVautherin
Copy link
Collaborator

Argh, somehow having issues with Jenkins. Trying to fix that.

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.

Thanks again.

@julianoes julianoes merged commit 87d3149 into mavlink:develop Jul 18, 2019
@JonasVautherin JonasVautherin changed the title Add offboard/set_actuator_control to offboard plugin without specifying group names Add actuator control to offboard plugin Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants