-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
plugins/offboard/offboard_impl.cpp
Outdated
body_roll_rate, | ||
body_pitch_rate, | ||
body_yaw_rate, | ||
thrust); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all correct.
plugins/offboard/offboard_impl.h
Outdated
@@ -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; |
There was a problem hiding this comment.
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
.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 😊
There was a problem hiding this 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 ;-)
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
@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:
|
I messed up here with force-pushing, but the changes are now in #627. |
Added SetAttitudeTarget message to the off board implementation (same as #621)
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!