mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-04 19:21:37 +08:00
mavlink: move TRAJECTORY_REPRESENTATION_WAYPOINTS to separate streams header
This commit is contained in:
committed by
Lorenz Meier
parent
5762c3b356
commit
629d03b684
@@ -97,7 +97,6 @@
|
|||||||
#include <uORB/topics/vehicle_rates_setpoint.h>
|
#include <uORB/topics/vehicle_rates_setpoint.h>
|
||||||
#include <uORB/topics/vehicle_status.h>
|
#include <uORB/topics/vehicle_status.h>
|
||||||
#include <uORB/topics/vehicle_status_flags.h>
|
#include <uORB/topics/vehicle_status_flags.h>
|
||||||
#include <uORB/topics/vehicle_trajectory_waypoint.h>
|
|
||||||
#include <uORB/topics/vtol_vehicle_status.h>
|
#include <uORB/topics/vtol_vehicle_status.h>
|
||||||
|
|
||||||
using matrix::Vector3f;
|
using matrix::Vector3f;
|
||||||
@@ -128,6 +127,7 @@ using matrix::wrap_2pi;
|
|||||||
#include "streams/RAW_RPM.hpp"
|
#include "streams/RAW_RPM.hpp"
|
||||||
#include "streams/STATUSTEXT.hpp"
|
#include "streams/STATUSTEXT.hpp"
|
||||||
#include "streams/STORAGE_INFORMATION.hpp"
|
#include "streams/STORAGE_INFORMATION.hpp"
|
||||||
|
#include "streams/TRAJECTORY_REPRESENTATION_WAYPOINTS.hpp"
|
||||||
#include "streams/WIND_COV.hpp"
|
#include "streams/WIND_COV.hpp"
|
||||||
|
|
||||||
#if !defined(CONSTRAINED_FLASH)
|
#if !defined(CONSTRAINED_FLASH)
|
||||||
@@ -3667,114 +3667,6 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MavlinkStreamTrajectoryRepresentationWaypoints: public MavlinkStream
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
const char *get_name() const override
|
|
||||||
{
|
|
||||||
return MavlinkStreamTrajectoryRepresentationWaypoints::get_name_static();
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr const char *get_name_static()
|
|
||||||
{
|
|
||||||
return "TRAJECTORY_REPRESENTATION_WAYPOINTS";
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr uint16_t get_id_static()
|
|
||||||
{
|
|
||||||
return MAVLINK_MSG_ID_TRAJECTORY_REPRESENTATION_WAYPOINTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t get_id() override
|
|
||||||
{
|
|
||||||
return get_id_static();
|
|
||||||
}
|
|
||||||
|
|
||||||
static MavlinkStream *new_instance(Mavlink *mavlink)
|
|
||||||
{
|
|
||||||
return new MavlinkStreamTrajectoryRepresentationWaypoints(mavlink);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned get_size() override
|
|
||||||
{
|
|
||||||
if (_traj_wp_avoidance_sub.advertised()) {
|
|
||||||
return MAVLINK_MSG_ID_TRAJECTORY_REPRESENTATION_WAYPOINTS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
uORB::Subscription _traj_wp_avoidance_sub{ORB_ID(vehicle_trajectory_waypoint_desired)};
|
|
||||||
|
|
||||||
/* do not allow top copying this class */
|
|
||||||
MavlinkStreamTrajectoryRepresentationWaypoints(MavlinkStreamTrajectoryRepresentationWaypoints &);
|
|
||||||
MavlinkStreamTrajectoryRepresentationWaypoints &operator = (const MavlinkStreamTrajectoryRepresentationWaypoints &);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
explicit MavlinkStreamTrajectoryRepresentationWaypoints(Mavlink *mavlink) : MavlinkStream(mavlink)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool send() override
|
|
||||||
{
|
|
||||||
vehicle_trajectory_waypoint_s traj_wp_avoidance_desired;
|
|
||||||
|
|
||||||
if (_traj_wp_avoidance_sub.update(&traj_wp_avoidance_desired)) {
|
|
||||||
mavlink_trajectory_representation_waypoints_t msg{};
|
|
||||||
|
|
||||||
msg.time_usec = traj_wp_avoidance_desired.timestamp;
|
|
||||||
int number_valid_points = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < vehicle_trajectory_waypoint_s::NUMBER_POINTS; ++i) {
|
|
||||||
msg.pos_x[i] = traj_wp_avoidance_desired.waypoints[i].position[0];
|
|
||||||
msg.pos_y[i] = traj_wp_avoidance_desired.waypoints[i].position[1];
|
|
||||||
msg.pos_z[i] = traj_wp_avoidance_desired.waypoints[i].position[2];
|
|
||||||
|
|
||||||
msg.vel_x[i] = traj_wp_avoidance_desired.waypoints[i].velocity[0];
|
|
||||||
msg.vel_y[i] = traj_wp_avoidance_desired.waypoints[i].velocity[1];
|
|
||||||
msg.vel_z[i] = traj_wp_avoidance_desired.waypoints[i].velocity[2];
|
|
||||||
|
|
||||||
msg.acc_x[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[0];
|
|
||||||
msg.acc_y[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[1];
|
|
||||||
msg.acc_z[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[2];
|
|
||||||
|
|
||||||
msg.pos_yaw[i] = traj_wp_avoidance_desired.waypoints[i].yaw;
|
|
||||||
msg.vel_yaw[i] = traj_wp_avoidance_desired.waypoints[i].yaw_speed;
|
|
||||||
|
|
||||||
switch (traj_wp_avoidance_desired.waypoints[i].type) {
|
|
||||||
case position_setpoint_s::SETPOINT_TYPE_TAKEOFF:
|
|
||||||
msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_TAKEOFF;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case position_setpoint_s::SETPOINT_TYPE_LOITER:
|
|
||||||
msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_LOITER_UNLIM;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case position_setpoint_s::SETPOINT_TYPE_LAND:
|
|
||||||
msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_LAND;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
msg.command[i] = UINT16_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (traj_wp_avoidance_desired.waypoints[i].point_valid) {
|
|
||||||
number_valid_points++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.valid_points = number_valid_points;
|
|
||||||
|
|
||||||
mavlink_msg_trajectory_representation_waypoints_send_struct(_mavlink->get_channel(), &msg);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class MavlinkStreamCameraCapture : public MavlinkStream
|
class MavlinkStreamCameraCapture : public MavlinkStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -3893,7 +3785,9 @@ static const StreamListItem streams_list[] = {
|
|||||||
#endif // ATTITUDE_TARGET_HPP
|
#endif // ATTITUDE_TARGET_HPP
|
||||||
create_stream_list_item<MavlinkStreamRCChannels>(),
|
create_stream_list_item<MavlinkStreamRCChannels>(),
|
||||||
create_stream_list_item<MavlinkStreamManualControl>(),
|
create_stream_list_item<MavlinkStreamManualControl>(),
|
||||||
|
#if defined(TRAJECTORY_REPRESENTATION_WAYPOINTS_HPP)
|
||||||
create_stream_list_item<MavlinkStreamTrajectoryRepresentationWaypoints>(),
|
create_stream_list_item<MavlinkStreamTrajectoryRepresentationWaypoints>(),
|
||||||
|
#endif // TRAJECTORY_REPRESENTATION_WAYPOINTS_HPP
|
||||||
#if defined(OPTICAL_FLOW_RAD_HPP)
|
#if defined(OPTICAL_FLOW_RAD_HPP)
|
||||||
create_stream_list_item<MavlinkStreamOpticalFlowRad>(),
|
create_stream_list_item<MavlinkStreamOpticalFlowRad>(),
|
||||||
#endif // OPTICAL_FLOW_RAD_HPP
|
#endif // OPTICAL_FLOW_RAD_HPP
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef TRAJECTORY_REPRESENTATION_WAYPOINTS_HPP
|
||||||
|
#define TRAJECTORY_REPRESENTATION_WAYPOINTS_HPP
|
||||||
|
|
||||||
|
#include <uORB/topics/vehicle_trajectory_waypoint.h>
|
||||||
|
|
||||||
|
class MavlinkStreamTrajectoryRepresentationWaypoints: public MavlinkStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static MavlinkStream *new_instance(Mavlink *mavlink) { return new MavlinkStreamTrajectoryRepresentationWaypoints(mavlink); }
|
||||||
|
|
||||||
|
const char *get_name() const override { return get_name_static(); }
|
||||||
|
uint16_t get_id() override { return get_id_static(); }
|
||||||
|
|
||||||
|
static constexpr const char *get_name_static() { return "TRAJECTORY_REPRESENTATION_WAYPOINTS"; }
|
||||||
|
static constexpr uint16_t get_id_static() { return MAVLINK_MSG_ID_TRAJECTORY_REPRESENTATION_WAYPOINTS; }
|
||||||
|
|
||||||
|
unsigned get_size() override
|
||||||
|
{
|
||||||
|
if (_traj_wp_avoidance_sub.advertised()) {
|
||||||
|
return MAVLINK_MSG_ID_TRAJECTORY_REPRESENTATION_WAYPOINTS_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit MavlinkStreamTrajectoryRepresentationWaypoints(Mavlink *mavlink) : MavlinkStream(mavlink) {}
|
||||||
|
|
||||||
|
uORB::Subscription _traj_wp_avoidance_sub{ORB_ID(vehicle_trajectory_waypoint_desired)};
|
||||||
|
|
||||||
|
bool send() override
|
||||||
|
{
|
||||||
|
vehicle_trajectory_waypoint_s traj_wp_avoidance_desired;
|
||||||
|
|
||||||
|
if (_traj_wp_avoidance_sub.update(&traj_wp_avoidance_desired)) {
|
||||||
|
mavlink_trajectory_representation_waypoints_t msg{};
|
||||||
|
|
||||||
|
msg.time_usec = traj_wp_avoidance_desired.timestamp;
|
||||||
|
int number_valid_points = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < vehicle_trajectory_waypoint_s::NUMBER_POINTS; ++i) {
|
||||||
|
msg.pos_x[i] = traj_wp_avoidance_desired.waypoints[i].position[0];
|
||||||
|
msg.pos_y[i] = traj_wp_avoidance_desired.waypoints[i].position[1];
|
||||||
|
msg.pos_z[i] = traj_wp_avoidance_desired.waypoints[i].position[2];
|
||||||
|
|
||||||
|
msg.vel_x[i] = traj_wp_avoidance_desired.waypoints[i].velocity[0];
|
||||||
|
msg.vel_y[i] = traj_wp_avoidance_desired.waypoints[i].velocity[1];
|
||||||
|
msg.vel_z[i] = traj_wp_avoidance_desired.waypoints[i].velocity[2];
|
||||||
|
|
||||||
|
msg.acc_x[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[0];
|
||||||
|
msg.acc_y[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[1];
|
||||||
|
msg.acc_z[i] = traj_wp_avoidance_desired.waypoints[i].acceleration[2];
|
||||||
|
|
||||||
|
msg.pos_yaw[i] = traj_wp_avoidance_desired.waypoints[i].yaw;
|
||||||
|
msg.vel_yaw[i] = traj_wp_avoidance_desired.waypoints[i].yaw_speed;
|
||||||
|
|
||||||
|
switch (traj_wp_avoidance_desired.waypoints[i].type) {
|
||||||
|
case position_setpoint_s::SETPOINT_TYPE_TAKEOFF:
|
||||||
|
msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_TAKEOFF;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case position_setpoint_s::SETPOINT_TYPE_LOITER:
|
||||||
|
msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_LOITER_UNLIM;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case position_setpoint_s::SETPOINT_TYPE_LAND:
|
||||||
|
msg.command[i] = vehicle_command_s::VEHICLE_CMD_NAV_LAND;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
msg.command[i] = UINT16_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (traj_wp_avoidance_desired.waypoints[i].point_valid) {
|
||||||
|
number_valid_points++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.valid_points = number_valid_points;
|
||||||
|
|
||||||
|
mavlink_msg_trajectory_representation_waypoints_send_struct(_mavlink->get_channel(), &msg);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TRAJECTORY_REPRESENTATION_WAYPOINTS_HPP
|
||||||
Reference in New Issue
Block a user