mavlink: move HOME_POSITION to separate stream header

This commit is contained in:
Daniel Agar
2021-03-11 11:46:14 -05:00
parent f7ee6b3c5e
commit 3964cfb3a7
2 changed files with 100 additions and 85 deletions
+3 -85
View File
@@ -117,6 +117,7 @@ using matrix::wrap_2pi;
#include "streams/FLIGHT_INFORMATION.hpp"
#include "streams/GPS_GLOBAL_ORIGIN.hpp"
#include "streams/GPS_STATUS.hpp"
#include "streams/HOME_POSITION.hpp"
#include "streams/HIGH_LATENCY2.hpp"
#include "streams/HIL_ACTUATOR_CONTROLS.hpp"
#include "streams/HIL_STATE_QUATERNION.hpp"
@@ -3054,91 +3055,6 @@ protected:
}
};
class MavlinkStreamHomePosition : public MavlinkStream
{
public:
const char *get_name() const override
{
return MavlinkStreamHomePosition::get_name_static();
}
static constexpr const char *get_name_static()
{
return "HOME_POSITION";
}
static constexpr uint16_t get_id_static()
{
return MAVLINK_MSG_ID_HOME_POSITION;
}
uint16_t get_id() override
{
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamHomePosition(mavlink);
}
unsigned get_size() override
{
return _home_sub.advertised() ? (MAVLINK_MSG_ID_HOME_POSITION_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES) : 0;
}
private:
uORB::Subscription _home_sub{ORB_ID(home_position)};
/* do not allow top copying this class */
MavlinkStreamHomePosition(MavlinkStreamHomePosition &) = delete;
MavlinkStreamHomePosition &operator = (const MavlinkStreamHomePosition &) = delete;
protected:
explicit MavlinkStreamHomePosition(Mavlink *mavlink) : MavlinkStream(mavlink)
{}
bool send() override
{
/* we're sending the GPS home periodically to ensure the
* the GCS does pick it up at one point */
home_position_s home;
if (_home_sub.advertised() && _home_sub.copy(&home)) {
if (home.valid_hpos) {
mavlink_home_position_t msg{};
msg.latitude = home.lat * 1e7;
msg.longitude = home.lon * 1e7;
msg.altitude = home.alt * 1e3f;
msg.x = home.x;
msg.y = home.y;
msg.z = home.z;
matrix::Quatf q(matrix::Eulerf(0.0f, 0.0f, home.yaw));
msg.q[0] = q(0);
msg.q[1] = q(1);
msg.q[2] = q(2);
msg.q[3] = q(3);
msg.approach_x = 0.0f;
msg.approach_y = 0.0f;
msg.approach_z = 0.0f;
msg.time_usec = home.timestamp;
mavlink_msg_home_position_send_struct(_mavlink->get_channel(), &msg);
return true;
}
}
return false;
}
};
class MavlinkStreamCameraCapture : public MavlinkStream
{
public:
@@ -3258,7 +3174,9 @@ static const StreamListItem streams_list[] = {
create_stream_list_item<MavlinkStreamAutopilotStateForGimbalDevice>(),
create_stream_list_item<MavlinkStreamGimbalDeviceSetAttitude>(),
#endif
#if defined(HOME_POSITION_HPP)
create_stream_list_item<MavlinkStreamHomePosition>(),
#endif // HOME_POSITION_HPP
#if defined(SERVO_OUTPUT_RAW_HPP)
create_stream_list_item<MavlinkStreamServoOutputRaw<0> >(),
create_stream_list_item<MavlinkStreamServoOutputRaw<1> >(),