Skip to content

Commit

Permalink
mavlink: reciever trajectory_representation_waypoints resepect valid_…
Browse files Browse the repository at this point in the history
…points

 - fixes #18369
  • Loading branch information
dagar committed Oct 6, 2021
1 parent 31a599f commit 0bdcd54
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/modules/mavlink/mavlink_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1917,10 +1917,9 @@ MavlinkReceiver::handle_message_trajectory_representation_waypoints(mavlink_mess

vehicle_trajectory_waypoint_s trajectory_waypoint{};

trajectory_waypoint.timestamp = hrt_absolute_time();
const int number_valid_points = trajectory.valid_points;
const int number_valid_points = math::min(trajectory.valid_points, vehicle_trajectory_waypoint_s::NUMBER_POINTS);

for (int i = 0; i < vehicle_trajectory_waypoint_s::NUMBER_POINTS; ++i) {
for (int i = 0; i < number_valid_points; ++i) {
trajectory_waypoint.waypoints[i].position[0] = trajectory.pos_x[i];
trajectory_waypoint.waypoints[i].position[1] = trajectory.pos_y[i];
trajectory_waypoint.waypoints[i].position[2] = trajectory.pos_z[i];
Expand All @@ -1936,17 +1935,12 @@ MavlinkReceiver::handle_message_trajectory_representation_waypoints(mavlink_mess
trajectory_waypoint.waypoints[i].yaw = trajectory.pos_yaw[i];
trajectory_waypoint.waypoints[i].yaw_speed = trajectory.vel_yaw[i];

trajectory_waypoint.waypoints[i].type = UINT8_MAX;
}

for (int i = 0; i < number_valid_points; ++i) {
trajectory_waypoint.waypoints[i].point_valid = true;
}

for (int i = number_valid_points; i < vehicle_trajectory_waypoint_s::NUMBER_POINTS; ++i) {
trajectory_waypoint.waypoints[i].point_valid = false;
trajectory_waypoint.waypoints[i].type = UINT8_MAX;
}

trajectory_waypoint.timestamp = hrt_absolute_time();
_trajectory_waypoint_pub.publish(trajectory_waypoint);
}

Expand Down

0 comments on commit 0bdcd54

Please sign in to comment.