-
-
Notifications
You must be signed in to change notification settings - Fork 503
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 support for COMMAND_INT and abstraction for the same including COMMAND_LONG
#351
Conversation
Adds new types `MAVLinkCommands::CmdInt` and `MAVLinkCommands::CmdLong` types that abstract to those of MAVLink protocol: http://mavlink.org/messages/common/#COMMAND_INT http://mavlink.org/messages/common/#COMMAND_LONG Also includes the changes in core and plugins, wherever these commands are used. `COMMAND_INT` is used only in Gimbal plugin as of now for `MAV_CMD_DO_SET_ROI_LOCATION`.
COMMAND_LONG
core/mavlink_commands.h
Outdated
float param4 = NAN; | ||
int32_t lat_deg = 0; | ||
int32_t lon_deg = 0; | ||
float alt_m = NAN; |
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.
This would be called param7
I'd say.
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 just realized, we better name last 3 members as x, y and z., x could be in meters also in case of Local position. So, _deg
would mislead. Right ?
x | int32_t | PARAM5 / local: x position in meters * 1e4, global: latitude in degrees * 10^7 |
---|---|---|
y | int32_t | PARAM6 / local: y position in meters * 1e4, global: longitude in degrees * 10^7 |
z | float | PARAM7 / z position: global: altitude in meters (relative or absolute, depending on frame. |
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.
Ok, makes sense then
core/mavlink_system.cpp
Outdated
cmd.params.param1 = float(mode); | ||
cmd.params.param2 = float(custom_mode); | ||
cmd.params.param3 = float(custom_sub_mode); | ||
cmd.target_component_id = get_autopilot_id(); |
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 think that's actually nicer!
core/mavlink_commands.h
Outdated
@@ -30,20 +31,65 @@ class MAVLinkCommands | |||
|
|||
typedef std::function<void(Result, float)> command_result_callback_t; | |||
|
|||
struct Params { | |||
float v[7]; | |||
struct CmdInt { |
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 CommandInt
because we use command
everywhere, and not cmd
, right?
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.
Right. I'll change.
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.
cmd
in argument should be fine, I think. Right ?
MAVLinkCommands::Result
MAVLinkSystem::send_command(MAVLinkCommands::CommandInt &cmd)
{...}
core/mavlink_commands.h
Outdated
@@ -6,6 +6,7 @@ | |||
#include <string> | |||
#include <functional> | |||
#include <mutex> | |||
#include <memory> |
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.
What's this include for? Shouldn't it be in mavlink_commands.cpp
?
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.
Yeah, forgot to remove. I wanted to use unique_ptr
but realized its an overkill. :)
command_result_callback_t callback, | ||
uint8_t component_id = 0); | ||
// FIXME: I tried to use templates for these; | ||
// but I get undefined reference. Need to dig it later. |
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 think like this is fine. I'd even tend to:
send_command_int(...);
send_command_long(...);
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.
OK. I am encouraging compile-time polymorphism :-)
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.
Ok sure.
plugins/action/action_impl.cpp
Outdated
MAVLinkCommands::CmdLong cmd {}; | ||
|
||
cmd.command = MAV_CMD_NAV_LAND; | ||
cmd.target_component_id = _parent->get_autopilot_id(); |
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.
Note that the behavior here could potentially change because we switch from having all params as NAN
to 0.f
. I would vote to set all reserved as NAN
.
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 vote to set all reserved as NAN.
OK.
So what should they be initialized by default ?
MAVLinkCommands:CmdInt -> MAVLinkCommands::CommandInt MAVLinkCommands:CmdLong -> MAVLinkCommands::CommandLong
In MAVLink spec for `COMMAND_INT` last 3 params are named as x, y and z. Units of these would vary from meteres (Local pos) to degrees (Global pos). Hence renamed as x, y and z.
Most of the "Reserved" values in MAVLink spec are NAN. However, in some cases "Reserved" value could be "0". This utility method supplied can be used to set any value to mark as "Reserved". For.eg: For commands `MAV_CMD_LOGGING_START`, `MAV_CMD_LOGGING_STOP` etc, "Reserved" value is 0.
7538d52
to
e09ac5a
Compare
Correct param name "reserved_value" in set_as_reserved().
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 good to me now.
…MAND_INT Add support for COMMAND_INT and abstraction for the same including `COMMAND_LONG`
Adds new types
MAVLinkCommands::CmdInt
andMAVLinkCommands::CmdLong
types that abstract to those of MAVLink protocol:Also includes the changes in core and plugins, wherever these commands are used.
COMMAND_INT
is used only in Gimbal plugin as of now forMAV_CMD_DO_SET_ROI_LOCATION
.