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

Added SetAttitudeTarget message to the off board implementation #621

Closed
wants to merge 0 commits into from
Closed

Added SetAttitudeTarget message to the off board implementation #621

wants to merge 0 commits into from

Conversation

salauddinaliahmed
Copy link
Contributor

Added a new message in the offboard plugin implementation.
Added an integration test example showcasing roll, pitch, yaw and thrust values. (offboard_attitude.cpp)

Please review and let me know incase it needs further improvements.
Thank you!

Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the contribution! I reviewed mainly the style, I'll wait for a comment from @julianoes regarding the actual feature.

BTW, all the .DS_Store files should be removed from this PR.

cmake/compiler_flags.cmake Outdated Show resolved Hide resolved
plugins/offboard/include/plugins/offboard/offboard.h Outdated Show resolved Hide resolved
plugins/offboard/include/plugins/offboard/offboard.h Outdated Show resolved Hide resolved
plugins/offboard/include/plugins/offboard/offboard.h Outdated Show resolved Hide resolved
plugins/offboard/offboard.cpp Outdated Show resolved Hide resolved
plugins/offboard/offboard_impl.cpp Outdated Show resolved Hide resolved
plugins/offboard/offboard_impl.cpp Outdated Show resolved Hide resolved
plugins/offboard/offboard_impl.cpp Outdated Show resolved Hide resolved
plugins/offboard/offboard_impl.cpp Outdated Show resolved Hide resolved
plugins/offboard/offboard_impl.h 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.

Awesome, thank you! This looks correct and very clean. I would change the naming a bit because we might also add attitude control later, so we should call this attitude rate, and we don't need to use the confusing "target" naming from MAVLink.

* @brief Type for Attitude rate commands in body coordinates (roll, pitch, yaw angular
* rate and Thrust).
*/
struct SetAttitude {
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 call this AttitudeRate.

float roll_deg_s;
float pitch_deg_s;
float yaw_deg_s;
float thrust_value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We we'll need comments for every field here because it's the public header file. This is used for the auto-generated reference docs.

@@ -153,6 +164,13 @@ class Offboard : public PluginBase {
*/
void set_velocity_body(VelocityBodyYawspeed velocity_body_yawspeed);

/**
* @brief Set the attitude target in terms of pitch, roll and yaw angular rate along with thrust in percentage.
Copy link
Collaborator

Choose a reason for hiding this comment

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

attitude -> attitude rate

*
* @param set_attitude_body pitch, roll and yaw angular rate along with Thrust in percentage `struct`.
*/
void set_attitude_target(SetAttitude set_attitude);
Copy link
Collaborator

Choose a reason for hiding this comment

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

set_attitude_target -> set_attitude_rate I'd say.

body_roll_rate,
body_pitch_rate,
body_yaw_rate,
thrust);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks all correct.

@@ -46,10 +48,11 @@ class OffboardImpl : public PluginImplBase {
void stop_sending_setpoints();

mutable std::mutex _mutex{};
enum class Mode { NOT_ACTIVE, VELOCITY_NED, VELOCITY_BODY } _mode = Mode::NOT_ACTIVE;
enum class Mode { NOT_ACTIVE, VELOCITY_NED, VELOCITY_BODY, ATTITUDE_TARGET} _mode = Mode::NOT_ACTIVE;
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 call it ATTITUDE_RATE because there will also be an ATTITUDE.

julianoes
julianoes previously approved these changes Dec 10, 2018
offboard->set_attitude_rate({0.0f, 0.0f, 0.0f, 0.6f});
std::this_thread::sleep_for(std::chrono::seconds(2));
// Roll for 45 degrees.
std::cout << "Rolling for -45 degrees" << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed, open-loop control like this won't work properly. We need to close the loop.

Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

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

Thanks for all the changes! Looking good! There is still one .DS_Store to remove, and then I'll be fine with it 😊

JonasVautherin
JonasVautherin previously approved these changes Dec 11, 2018
Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, LGTM! Now you only need to convince @julianoes ;-)

@salauddinaliahmed
Copy link
Contributor Author

I have added a closing loop logic to my integration test example (offboard_attitude.cpp) as discussed.

double thrust_control = 0.1 * (double)(10.5f - telemetry->position().relative_altitude_m);
if (thrust_control < 0.1)
{
thrust_control = 0.35;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this is correct? This means thrust_control will jump from 0.1 to 0.35 when < 0.1?

Copy link
Contributor Author

@salauddinaliahmed salauddinaliahmed Dec 11, 2018

Choose a reason for hiding this comment

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

That is to prevent against negative thrust. Because, the quad would then free fall.
I am trying to stay at an altitude of <=10 meters.
If I go beyond 10mts due to any action, then the thrust becomes negative and the props stop. Causing a free fall. (0.3 was like a sweet spot which helps in lowering the altitude)

{
auto yaw_bal = close_loop(0.0f,0.0f,0.0f,telemetry);
offboard->set_attitude_rate({yaw_bal.roll, yaw_bal.pitch, yaw_bal.yaw, yaw_bal.thrust});
std::this_thread::sleep_for(std::chrono::milliseconds(10));
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nicer to use the callback for new attitude updates instead of sleeping here but we can do that in a future pull request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will work on that later (mostly by next week)

@julianoes
Copy link
Collaborator

julianoes commented Dec 13, 2018

@salauddinaliahmed ok I've tested this and it seems to work, or at least do something 😄.

Now I suggest you do the following and then we can merge this:

  1. Merge with latest develop:
    git fetch origin
    git merge origin/develop
    
  2. Fix style issues:
    make fix_style
    
  3. Fix the discontinuance in throttle, I think this would make sense:
        if (thrust_control < 0.1) {
            thrust_control = 0.1;
        }
    

@julianoes
Copy link
Collaborator

I messed up here with force-pushing, but the changes are now in #627.

julianoes added a commit that referenced this pull request Dec 14, 2018
Added SetAttitudeTarget message to the off board implementation (same as #621)
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