SMACC2
Loading...
Searching...
No Matches
cl_px4_mr Namespace Reference

Namespaces

namespace  anonymous_namespace{cb_wait_for_heading_stable.cpp}
 
namespace  anonymous_namespace{cp_kml_mission_loader.cpp}
 
namespace  anonymous_namespace{cp_micro_ros_agent.cpp}
 
namespace  anonymous_namespace{cp_tf_broadcaster.cpp}
 
namespace  anonymous_namespace{cp_tunnel_centering.cpp}
 
namespace  anonymous_namespace{pattern_generators.cpp}
 
namespace  geo_detail
 
namespace  pattern_detail
 

Classes

class  CbArmPX4
 
class  CbAscendToAltitude
 
class  CbChangeAltitude
 
class  CbConnectMicroRosAgent
 
class  CbDisarmPX4
 
class  CbFigureEight
 
class  CbFollowNedPath
 
class  CbFollowWaypoints
 
class  CbGoToLocation
 
class  CbGridPattern
 
class  CbHoldPosition
 
class  CbLand
 
class  CbLawnmower
 
class  CbLemniscate
 
class  CbLoadKmlMission
 
class  CbLoiter
 
class  CbObstacleGuard
 
class  CbOrbitLocation
 
class  CbPx4ClientBehaviorBase
 
class  CbPx4PathFollowerBase
 
class  CbReturnToHome
 
class  CbSineAltitudeCruise
 
class  CbSineWaveHorizontal
 
class  CbSineWaveVertical
 
class  CbSpiral
 
class  CbSpiralPattern
 
class  CbSpiralUp
 
class  CbSquareSpiral
 
class  CbTakeOff
 
class  CbVSSearch
 
class  CbWaitForHeadingStable
 
class  CbYawRotate
 
class  CbYawScan
 
class  ClPx4Mr
 
class  CpFailsafeFlags
 
class  CpForwardObstacleGuard
 
class  CpGoalChecker
 
class  CpKmlMissionLoader
 
class  CpMicroRosAgent
 
class  CpOffboardKeepAlive
 
class  CpTfBroadcaster
 
class  CpTrajectorySetpoint
 
class  CpTunnelCentering
 
class  CpVehicleCommand
 
class  CpVehicleCommandAck
 
class  CpVehicleLocalPosition
 
class  CpVehicleStatus
 
struct  EvObstacleCleared
 
struct  EvObstacleTooClose
 
struct  FigureEightParams
 
struct  FlightPatternAscendParams
 
struct  FlightPatternFigureEightParams
 
struct  FlightPatternGridPatternParams
 
struct  FlightPatternLawnmowerParams
 
struct  FlightPatternLoiterParams
 
struct  FlightPatternSineWaveHorizontalParams
 
struct  FlightPatternSineWaveVerticalParams
 
struct  FlightPatternSpiralParams
 
struct  FlightPatternSquareSpiralParams
 
struct  FlightPatternVSSearchParams
 
struct  ForwardObstacleGuardParams
 
struct  GeoPoint
 
struct  HeadingStableParams
 
struct  KmlLoadResult
 
class  MapProjection
 
struct  NedPoint
 
struct  OrbitLocationParams
 
struct  PathFollowerParams
 
struct  SineAltitudeCruiseParams
 
struct  SpiralPatternParams
 
struct  SpiralUpParams
 
struct  TfBroadcasterParams
 
struct  TunnelCenteringParams
 
struct  YawScanParams
 

Enumerations

enum class  YawMode { TANGENT , FIXED , PER_VERTEX , HOLD_ENTRY }
 
enum class  Turn { RIGHT , LEFT }
 

Functions

float wrapPi (float angle)
 
double haversineDistance (double lat1, double lon1, double lat2, double lon2)
 
double haversineDistance (const GeoPoint &a, const GeoPoint &b)
 
double initialBearing (double lat1, double lon1, double lat2, double lon2)
 
float nedDistance (const NedPoint &a, const NedPoint &b)
 
float nedDistanceXY (const NedPoint &a, const NedPoint &b)
 
std::vector< float > cumulativeLengths (const std::vector< NedPoint > &path)
 
float polylineLength (const std::vector< NedPoint > &path)
 
NedPoint sampleAtArcLength (const std::vector< NedPoint > &path, const std::vector< float > &cum, float s, size_t *segmentIndex=nullptr)
 
std::vector< NedPoint > resamplePolyline (const std::vector< NedPoint > &path, float spacing)
 
void levelRotationFromPx4Quaternion (const std::array< float, 4 > &q, std::array< float, 9 > &r)
 
float turnSign (Turn t)
 
const char * turnName (Turn t)
 
std::vector< NedPoint > generateFlightPatternAscend (const FlightPatternAscendParams &p, const NedPoint &current)
 
std::vector< NedPoint > generateFlightPatternLoiter (const FlightPatternLoiterParams &p, const NedPoint &current)
 
std::vector< NedPoint > generateFlightPatternFigureEight (const FlightPatternFigureEightParams &p, const NedPoint &current)
 
float flightPatternFigureEightLength (const FlightPatternFigureEightParams &p)
 
std::vector< NedPoint > generateFlightPatternSineWaveVertical (const FlightPatternSineWaveVerticalParams &p, const NedPoint &current)
 
std::vector< NedPoint > generateFlightPatternSineWaveHorizontal (const FlightPatternSineWaveHorizontalParams &p, const NedPoint &current)
 
std::vector< NedPoint > generateFlightPatternSquareSpiral (const FlightPatternSquareSpiralParams &p, const NedPoint &current)
 
float flightPatternSquareSpiralLength (const FlightPatternSquareSpiralParams &p)
 
std::vector< NedPoint > generateFlightPatternSpiral (const FlightPatternSpiralParams &p, const NedPoint &current)
 
float flightPatternSpiralLength (const FlightPatternSpiralParams &p)
 
std::vector< NedPoint > generateFlightPatternLawnmower (const FlightPatternLawnmowerParams &p, const NedPoint &current)
 
float flightPatternLawnmowerLength (const FlightPatternLawnmowerParams &p)
 
int flightPatternLawnmowerLaneCount (const FlightPatternLawnmowerParams &p)
 
std::vector< NedPoint > generateFlightPatternGridPattern (const FlightPatternGridPatternParams &p, const NedPoint &current)
 
float flightPatternGridPatternLength (const FlightPatternGridPatternParams &p)
 
std::vector< NedPoint > generateFlightPatternVSSearch (const FlightPatternVSSearchParams &p, const NedPoint &current)
 
float flightPatternVSSearchLength (const FlightPatternVSSearchParams &p)
 
float legHeading (const NedPoint &from, const NedPoint &to)
 

Variables

constexpr double kEarthRadiusM = 6371000.0
 

Enumeration Type Documentation

◆ Turn

enum class cl_px4_mr::Turn
strong
Enumerator
RIGHT 
LEFT 

Definition at line 51 of file pattern_generators.hpp.

◆ YawMode

enum class cl_px4_mr::YawMode
strong
Enumerator
TANGENT 
FIXED 
PER_VERTEX 
HOLD_ENTRY 

Definition at line 35 of file cb_px4_path_follower_base.hpp.

36{
37 TANGENT, // along the current path segment
38 FIXED, // PathFollowerParams::fixedYaw
39 PER_VERTEX, // NedPoint::yaw of the segment start (NaN -> tangent)
40 HOLD_ENTRY // heading at entry
41};

Function Documentation

◆ cumulativeLengths()

std::vector< float > cl_px4_mr::cumulativeLengths ( const std::vector< NedPoint > & path)
inline

Definition at line 205 of file geo_utils.hpp.

206{
207 std::vector<float> cum;
208 cum.reserve(path.size());
209 double acc = 0.0;
210 for (size_t i = 0; i < path.size(); ++i)
211 {
212 if (i > 0)
213 {
214 acc += static_cast<double>(nedDistance(path[i - 1], path[i]));
215 }
216 cum.push_back(static_cast<float>(acc));
217 }
218 return cum;
219}
float nedDistance(const NedPoint &a, const NedPoint &b)

References nedDistance().

Referenced by cl_px4_mr::CbPx4PathFollowerBase::onEntry(), and polylineLength().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flightPatternFigureEightLength()

float cl_px4_mr::flightPatternFigureEightLength ( const FlightPatternFigureEightParams & p)

Definition at line 185 of file pattern_generators.cpp.

186{
187 // perimeter of the lemniscate of Bernoulli = 5.2441 a
188 return 5.2441f * std::max(p.size, 0.5f) * static_cast<float>(std::max(p.count, 0));
189}

References cl_px4_mr::FlightPatternFigureEightParams::count, and cl_px4_mr::FlightPatternFigureEightParams::size.

Referenced by cl_px4_mr::CbLemniscate::buildPath().

Here is the caller graph for this function:

◆ flightPatternGridPatternLength()

◆ flightPatternLawnmowerLaneCount()

int cl_px4_mr::flightPatternLawnmowerLaneCount ( const FlightPatternLawnmowerParams & p)

Definition at line 365 of file pattern_generators.cpp.

366{
367 const float spacing = std::max(p.laneSpacing, 0.5f);
368 return std::max(1, static_cast<int>(std::floor(std::max(p.width, 0.0f) / spacing + 1e-3f)) + 1);
369}

References cl_px4_mr::FlightPatternLawnmowerParams::laneSpacing, and cl_px4_mr::FlightPatternLawnmowerParams::width.

Referenced by cl_px4_mr::CbLawnmower::buildPath(), flightPatternLawnmowerLength(), and generateFlightPatternLawnmower().

Here is the caller graph for this function:

◆ flightPatternLawnmowerLength()

float cl_px4_mr::flightPatternLawnmowerLength ( const FlightPatternLawnmowerParams & p)

Definition at line 371 of file pattern_generators.cpp.

372{
373 const int lanes = flightPatternLawnmowerLaneCount(p);
374 return static_cast<float>(lanes) * std::max(p.laneLength, 0.0f) +
375 static_cast<float>(lanes - 1) * std::max(p.laneSpacing, 0.5f);
376}
int flightPatternLawnmowerLaneCount(const FlightPatternLawnmowerParams &p)

References flightPatternLawnmowerLaneCount(), cl_px4_mr::FlightPatternLawnmowerParams::laneLength, and cl_px4_mr::FlightPatternLawnmowerParams::laneSpacing.

Referenced by cl_px4_mr::CbLawnmower::buildPath(), and flightPatternGridPatternLength().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flightPatternSpiralLength()

float cl_px4_mr::flightPatternSpiralLength ( const FlightPatternSpiralParams & p)

Definition at line 356 of file pattern_generators.cpp.

357{
358 // area between the radii divided by the track spacing
359 const float rStart = std::max(p.startRadius, 0.0f);
360 const float rEnd = std::max(p.endRadius, rStart);
361 const float spacing = std::max(p.spacing, 0.5f);
362 return static_cast<float>(M_PI) * (rEnd * rEnd - rStart * rStart) / spacing;
363}

References cl_px4_mr::FlightPatternSpiralParams::endRadius, cl_px4_mr::FlightPatternSpiralParams::spacing, and cl_px4_mr::FlightPatternSpiralParams::startRadius.

Referenced by cl_px4_mr::CbSpiral::buildPath().

Here is the caller graph for this function:

◆ flightPatternSquareSpiralLength()

float cl_px4_mr::flightPatternSquareSpiralLength ( const FlightPatternSquareSpiralParams & p)

Definition at line 293 of file pattern_generators.cpp.

294{
295 const float spacing = std::max(p.spacing, 0.5f);
296 float total = 0.0f;
297 for (int i = 0; i < p.numLegs; ++i)
298 {
299 const float len = spacing * static_cast<float>(i / 2 + 1);
300 if (p.maxLegLength > 0.0f && len > p.maxLegLength)
301 {
302 break;
303 }
304 total += len;
305 }
306 return total;
307}

References cl_px4_mr::FlightPatternSquareSpiralParams::maxLegLength, cl_px4_mr::FlightPatternSquareSpiralParams::numLegs, and cl_px4_mr::FlightPatternSquareSpiralParams::spacing.

Referenced by cl_px4_mr::CbSquareSpiral::buildPath().

Here is the caller graph for this function:

◆ flightPatternVSSearchLength()

float cl_px4_mr::flightPatternVSSearchLength ( const FlightPatternVSSearchParams & p)

Definition at line 483 of file pattern_generators.cpp.

484{
485 return 9.0f * std::max(p.radius, 1.0f) * static_cast<float>(std::max(p.cycles, 1));
486}

References cl_px4_mr::FlightPatternVSSearchParams::cycles, and cl_px4_mr::FlightPatternVSSearchParams::radius.

Referenced by cl_px4_mr::CbVSSearch::buildPath().

Here is the caller graph for this function:

◆ generateFlightPatternAscend()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternAscend ( const FlightPatternAscendParams & p,
const NedPoint & current )

Definition at line 33 of file pattern_generators.cpp.

35{
36 NedPoint target;
37 target.x = pick(p.targetX, current.x);
38 target.y = pick(p.targetY, current.y);
39 target.z = -p.altitudeAgl;
40
41 const bool atXy = std::hypot(target.x - current.x, target.y - current.y) <= p.tolerance;
42 if (atXy && std::fabs(current.z - target.z) <= p.tolerance)
43 {
44 return {target};
45 }
46 NedPoint start = current;
47 start.yaw = kNaN;
48 return {start, target};
49}

References cl_px4_mr::FlightPatternAscendParams::altitudeAgl, cl_px4_mr::FlightPatternAscendParams::targetX, cl_px4_mr::FlightPatternAscendParams::targetY, cl_px4_mr::FlightPatternAscendParams::tolerance, cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, cl_px4_mr::NedPoint::yaw, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbAscendToAltitude::buildPath().

Here is the caller graph for this function:

◆ generateFlightPatternFigureEight()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternFigureEight ( const FlightPatternFigureEightParams & p,
const NedPoint & current )

Definition at line 119 of file pattern_generators.cpp.

121{
122 const float cx = pick(p.centerX, current.x);
123 const float cy = pick(p.centerY, current.y);
124 const float z = altitudeToZ(p.altitudeAgl, current.z);
125 const float a = std::max(p.size, 0.5f);
126 const int n = std::max(p.pointsPerLoop, 16);
127 const float sign = turnSign(p.direction);
128
129 if (p.count <= 0)
130 {
131 NedPoint here = current;
132 here.z = z;
133 here.yaw = kNaN;
134 return {here};
135 }
136
137 // lobe axis: given, else the entry heading, else north
138 const float heading =
139 std::isnan(p.heading) ? (std::isnan(current.yaw) ? 0.0f : current.yaw) : p.heading;
140 const float ch = std::cos(heading);
141 const float sh = std::sin(heading);
142
143 // one loop of the lemniscate x = a cos t / (1 + sin^2 t), y = a sin t cos t / (1 + sin^2 t)
144 std::vector<NedPoint> loop;
145 loop.reserve(static_cast<size_t>(n));
146 for (int k = 0; k < n; ++k)
147 {
148 const float t =
149 sign * 2.0f * static_cast<float>(M_PI) * static_cast<float>(k) / static_cast<float>(n);
150 const float st = std::sin(t);
151 const float ct = std::cos(t);
152 const float denom = 1.0f + st * st;
153 const float lx = a * ct / denom;
154 const float ly = a * st * ct / denom;
155 NedPoint v;
156 v.x = cx + lx * ch - ly * sh;
157 v.y = cy + lx * sh + ly * ch;
158 v.z = z;
159 v.yaw = kNaN;
160 loop.push_back(v);
161 }
162
163 // enter at the sample nearest the vehicle
164 int start = 0;
165 float best = std::numeric_limits<float>::infinity();
166 for (int k = 0; k < n; ++k)
167 {
168 const float d = std::hypot(loop[k].x - current.x, loop[k].y - current.y);
169 if (d < best)
170 {
171 best = d;
172 start = k;
173 }
174 }
175
176 std::vector<NedPoint> path;
177 path.reserve(static_cast<size_t>(p.count) * static_cast<size_t>(n) + 1);
178 for (int k = 0; k <= p.count * n; ++k)
179 {
180 path.push_back(loop[static_cast<size_t>((start + k) % n)]);
181 }
182 return path;
183}
float turnSign(Turn t)

References cl_px4_mr::FlightPatternFigureEightParams::altitudeAgl, cl_px4_mr::FlightPatternFigureEightParams::centerX, cl_px4_mr::FlightPatternFigureEightParams::centerY, cl_px4_mr::FlightPatternFigureEightParams::count, cl_px4_mr::FlightPatternFigureEightParams::direction, cl_px4_mr::FlightPatternFigureEightParams::heading, cl_px4_mr::FlightPatternFigureEightParams::pointsPerLoop, cl_px4_mr::FlightPatternFigureEightParams::size, turnSign(), cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, cl_px4_mr::NedPoint::yaw, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbLemniscate::buildPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateFlightPatternGridPattern()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternGridPattern ( const FlightPatternGridPatternParams & p,
const NedPoint & current )

Definition at line 438 of file pattern_generators.cpp.

440{
442 first.originIsCenter = true; // the grid is always centred on the origin
443 first.originX = pick(p.base.originX, current.x);
444 first.originY = pick(p.base.originY, current.y);
445 first.laneHeading = pick(p.base.laneHeading, std::isnan(current.yaw) ? 0.0f : current.yaw);
446
447 std::vector<NedPoint> path = generateFlightPatternLawnmower(first, current);
448 if (!p.secondPass || path.empty())
449 {
450 return path;
451 }
452
453 // second pass: rotated 90 degrees over the same rectangle; try the four
454 // start corners (heading +-90, step side left/right) and take the one that
455 // starts nearest the end of pass 1
456 const NedPoint & joint = path.back();
457 std::vector<NedPoint> best;
458 float bestDist = std::numeric_limits<float>::max();
459 for (int variant = 0; variant < 4; ++variant)
460 {
461 FlightPatternLawnmowerParams second = first;
462 second.laneLength = first.width;
463 second.width = first.laneLength;
464 second.laneHeading =
465 first.laneHeading + ((variant & 1) ? -1.0f : 1.0f) * static_cast<float>(M_PI) / 2.0f;
466 second.firstTurn = (variant & 2) ? Turn::LEFT : Turn::RIGHT;
467 std::vector<NedPoint> candidate = generateFlightPatternLawnmower(second, current);
468 if (candidate.empty())
469 {
470 continue;
471 }
472 const float d = nedDistance(joint, candidate.front());
473 if (d < bestDist)
474 {
475 bestDist = d;
476 best = std::move(candidate);
477 }
478 }
479 path.insert(path.end(), best.begin(), best.end());
480 return path;
481}
std::vector< NedPoint > generateFlightPatternLawnmower(const FlightPatternLawnmowerParams &p, const NedPoint &current)

References cl_px4_mr::FlightPatternGridPatternParams::base, cl_px4_mr::FlightPatternLawnmowerParams::firstTurn, generateFlightPatternLawnmower(), cl_px4_mr::FlightPatternLawnmowerParams::laneHeading, cl_px4_mr::FlightPatternLawnmowerParams::laneLength, LEFT, nedDistance(), cl_px4_mr::FlightPatternLawnmowerParams::originIsCenter, cl_px4_mr::FlightPatternLawnmowerParams::originX, cl_px4_mr::FlightPatternLawnmowerParams::originY, RIGHT, cl_px4_mr::FlightPatternGridPatternParams::secondPass, cl_px4_mr::FlightPatternLawnmowerParams::width, cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, and cl_px4_mr::NedPoint::yaw.

Referenced by cl_px4_mr::CbGridPattern::buildPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateFlightPatternLawnmower()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternLawnmower ( const FlightPatternLawnmowerParams & p,
const NedPoint & current )

Definition at line 378 of file pattern_generators.cpp.

380{
381 const float z = altitudeToZ(p.altitudeAgl, current.z);
382 const float heading = pick(p.laneHeading, std::isnan(current.yaw) ? 0.0f : current.yaw);
383 const float ux = std::cos(heading);
384 const float uy = std::sin(heading);
385 // side normal: RIGHT of the heading in NED (x north, y east) is (-uy, ux)
386 const float side = turnSign(p.firstTurn);
387 const float nx = -uy * side;
388 const float ny = ux * side;
389
390 const int lanes = flightPatternLawnmowerLaneCount(p);
391 const float spacing = std::max(p.laneSpacing, 0.5f);
392 const float length = std::max(p.laneLength, 0.0f);
393 const float coveredWidth = static_cast<float>(lanes - 1) * spacing;
394
395 float ox = pick(p.originX, current.x);
396 float oy = pick(p.originY, current.y);
397 if (p.originIsCenter)
398 {
399 ox -= 0.5f * length * ux + 0.5f * coveredWidth * nx;
400 oy -= 0.5f * length * uy + 0.5f * coveredWidth * ny;
401 }
402
403 std::vector<NedPoint> path;
404 path.reserve(2 * static_cast<size_t>(lanes));
405 for (int i = 0; i < lanes; ++i)
406 {
407 NedPoint a;
408 a.x = ox + static_cast<float>(i) * spacing * nx;
409 a.y = oy + static_cast<float>(i) * spacing * ny;
410 a.z = z;
411 NedPoint b;
412 b.x = a.x + length * ux;
413 b.y = a.y + length * uy;
414 b.z = z;
415 if (i % 2 == 0)
416 {
417 path.push_back(a);
418 path.push_back(b);
419 }
420 else
421 {
422 path.push_back(b);
423 path.push_back(a);
424 }
425 }
426 return path;
427}

References cl_px4_mr::FlightPatternLawnmowerParams::altitudeAgl, cl_px4_mr::FlightPatternLawnmowerParams::firstTurn, flightPatternLawnmowerLaneCount(), cl_px4_mr::FlightPatternLawnmowerParams::laneHeading, cl_px4_mr::FlightPatternLawnmowerParams::laneLength, cl_px4_mr::FlightPatternLawnmowerParams::laneSpacing, cl_px4_mr::FlightPatternLawnmowerParams::originIsCenter, cl_px4_mr::FlightPatternLawnmowerParams::originX, cl_px4_mr::FlightPatternLawnmowerParams::originY, turnSign(), cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, cl_px4_mr::NedPoint::yaw, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbLawnmower::buildPath(), and generateFlightPatternGridPattern().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateFlightPatternLoiter()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternLoiter ( const FlightPatternLoiterParams & p,
const NedPoint & current )

Definition at line 51 of file pattern_generators.cpp.

53{
54 const float cx = pick(p.centerX, current.x);
55 const float cy = pick(p.centerY, current.y);
56 const float z = altitudeToZ(p.altitudeAgl, current.z);
57 const float r = std::max(p.radius, 0.5f);
58 const int n = std::max(p.pointsPerCircle, 8);
59 const float sign = turnSign(p.direction);
60
61 if (p.count <= 0)
62 {
63 // nothing to fly: hold the entry point (the follower posts success at once)
64 NedPoint here = current;
65 here.z = z;
66 here.yaw = kNaN;
67 return {here};
68 }
69 const int count = p.count;
70
71 // enter at the point of the circle nearest the vehicle; if at the centre
72 // use the entry heading to pick a start
73 const float dx = current.x - cx;
74 const float dy = current.y - cy;
75 float theta0 =
76 std::hypot(dx, dy) > 0.1f ? std::atan2(dy, dx) : (std::isnan(current.yaw) ? 0.0f : current.yaw);
77
78 std::vector<NedPoint> path;
79 path.reserve(static_cast<size_t>(count) * static_cast<size_t>(n) + 1);
80 for (int k = 0; k <= count * n; ++k)
81 {
82 const float theta = theta0 + sign * 2.0f * static_cast<float>(M_PI) * static_cast<float>(k) /
83 static_cast<float>(n);
84 NedPoint v;
85 v.x = cx + r * std::cos(theta);
86 v.y = cy + r * std::sin(theta);
87 v.z = z;
88 v.yaw = p.faceCenter ? std::atan2(cy - v.y, cx - v.x) : kNaN;
89 path.push_back(v);
90 }
91 return path;
92}

References cl_px4_mr::FlightPatternLoiterParams::altitudeAgl, cl_px4_mr::FlightPatternLoiterParams::centerX, cl_px4_mr::FlightPatternLoiterParams::centerY, cl_px4_mr::FlightPatternLoiterParams::count, cl_px4_mr::FlightPatternLoiterParams::direction, cl_px4_mr::FlightPatternLoiterParams::faceCenter, cl_px4_mr::FlightPatternLoiterParams::pointsPerCircle, cl_px4_mr::FlightPatternLoiterParams::radius, turnSign(), cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, cl_px4_mr::NedPoint::yaw, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbLoiter::buildPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateFlightPatternSineWaveHorizontal()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternSineWaveHorizontal ( const FlightPatternSineWaveHorizontalParams & p,
const NedPoint & current )

Definition at line 223 of file pattern_generators.cpp.

225{
226 const float endX = pick(p.endX, current.x);
227 const float endY = pick(p.endY, current.y);
228 const float z = altitudeToZ(p.altitudeAgl, current.z);
229 const float lambda = std::max(p.wavelength, 0.1f);
230 const float spacing = std::max(p.sampleSpacing, 0.1f);
231 const Leg leg = legFrom(current, endX, endY);
232
233 std::vector<NedPoint> path;
234 if (leg.length <= 1e-3f)
235 {
236 path.push_back(NedPoint{endX, endY, z, kNaN});
237 return path;
238 }
239
240 // left-of-track normal in NED (x north, y east): rotate u by -90 deg
241 const float nx = leg.uy;
242 const float ny = -leg.ux;
243
244 const int n = static_cast<int>(std::floor(leg.length / spacing));
245 path.reserve(static_cast<size_t>(n) + 2);
246 for (int k = 0; k < n; ++k)
247 {
248 const float s = static_cast<float>(k) * spacing;
249 const float offset = p.amplitude * std::sin(2.0f * static_cast<float>(M_PI) * s / lambda);
250 NedPoint v;
251 v.x = current.x + s * leg.ux + offset * nx;
252 v.y = current.y + s * leg.uy + offset * ny;
253 v.z = z;
254 path.push_back(v);
255 }
256 path.push_back(NedPoint{endX, endY, z, kNaN});
257 return path;
258}

References cl_px4_mr::FlightPatternSineWaveHorizontalParams::altitudeAgl, cl_px4_mr::FlightPatternSineWaveHorizontalParams::amplitude, cl_px4_mr::FlightPatternSineWaveHorizontalParams::endX, cl_px4_mr::FlightPatternSineWaveHorizontalParams::endY, cl_px4_mr::FlightPatternSineWaveHorizontalParams::sampleSpacing, cl_px4_mr::FlightPatternSineWaveHorizontalParams::wavelength, cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbSineWaveHorizontal::buildPath().

Here is the caller graph for this function:

◆ generateFlightPatternSineWaveVertical()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternSineWaveVertical ( const FlightPatternSineWaveVerticalParams & p,
const NedPoint & current )

Definition at line 191 of file pattern_generators.cpp.

193{
194 const float endX = pick(p.endX, current.x);
195 const float endY = pick(p.endY, current.y);
196 const float zBase = altitudeToZ(p.baseAltitudeAgl, current.z);
197 const float lambda = std::max(p.wavelength, 0.1f);
198 const float spacing = std::max(p.sampleSpacing, 0.1f);
199 const Leg leg = legFrom(current, endX, endY);
200
201 std::vector<NedPoint> path;
202 if (leg.length <= 1e-3f)
203 {
204 path.push_back(NedPoint{endX, endY, zBase, kNaN});
205 return path;
206 }
207
208 const int n = static_cast<int>(std::floor(leg.length / spacing));
209 path.reserve(static_cast<size_t>(n) + 2);
210 for (int k = 0; k < n; ++k)
211 {
212 const float s = static_cast<float>(k) * spacing;
213 NedPoint v;
214 v.x = current.x + s * leg.ux;
215 v.y = current.y + s * leg.uy;
216 v.z = zBase - p.amplitude * std::sin(2.0f * static_cast<float>(M_PI) * s / lambda);
217 path.push_back(v);
218 }
219 path.push_back(NedPoint{endX, endY, zBase, kNaN});
220 return path;
221}

References cl_px4_mr::FlightPatternSineWaveVerticalParams::amplitude, cl_px4_mr::FlightPatternSineWaveVerticalParams::baseAltitudeAgl, cl_px4_mr::FlightPatternSineWaveVerticalParams::endX, cl_px4_mr::FlightPatternSineWaveVerticalParams::endY, cl_px4_mr::FlightPatternSineWaveVerticalParams::sampleSpacing, cl_px4_mr::FlightPatternSineWaveVerticalParams::wavelength, cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbSineWaveVertical::buildPath().

Here is the caller graph for this function:

◆ generateFlightPatternSpiral()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternSpiral ( const FlightPatternSpiralParams & p,
const NedPoint & current )

Definition at line 309 of file pattern_generators.cpp.

311{
312 const float cx = pick(p.centerX, current.x);
313 const float cy = pick(p.centerY, current.y);
314 const float z = altitudeToZ(p.altitudeAgl, current.z);
315 const float spacing = std::max(p.spacing, 0.5f);
316 const float a = spacing / (2.0f * static_cast<float>(M_PI)); // r = a * theta
317 const float rStart = std::max(p.startRadius, 0.0f);
318 const float rEnd = std::max(p.endRadius, rStart);
319 const float sign = turnSign(p.direction);
320 const float ds = std::max(p.sampleSpacing, 0.1f);
321
322 // angular origin: bearing of the vehicle from the centre, else entry heading
323 const float dx = current.x - cx;
324 const float dy = current.y - cy;
325 const float theta0 =
326 std::hypot(dx, dy) > 0.1f ? std::atan2(dy, dx) : (std::isnan(current.yaw) ? 0.0f : current.yaw);
327
328 const float thetaStart = rStart / a;
329 const float thetaEnd = rEnd / a;
330
331 std::vector<NedPoint> path;
332 float theta = thetaStart;
333 while (theta < thetaEnd)
334 {
335 const float r = a * theta;
336 NedPoint v;
337 v.x = cx + r * std::cos(theta0 + sign * theta);
338 v.y = cy + r * std::sin(theta0 + sign * theta);
339 v.z = z;
340 path.push_back(v);
341 theta += ds / std::max(r, a); // constant arc-length steps
342 }
343 NedPoint last;
344 last.x = cx + rEnd * std::cos(theta0 + sign * thetaEnd);
345 last.y = cy + rEnd * std::sin(theta0 + sign * thetaEnd);
346 last.z = z;
347 path.push_back(last);
348
349 if (p.inward)
350 {
351 std::reverse(path.begin(), path.end());
352 }
353 return path;
354}

References cl_px4_mr::FlightPatternSpiralParams::altitudeAgl, cl_px4_mr::FlightPatternSpiralParams::centerX, cl_px4_mr::FlightPatternSpiralParams::centerY, cl_px4_mr::FlightPatternSpiralParams::direction, cl_px4_mr::FlightPatternSpiralParams::endRadius, cl_px4_mr::FlightPatternSpiralParams::inward, cl_px4_mr::FlightPatternSpiralParams::sampleSpacing, cl_px4_mr::FlightPatternSpiralParams::spacing, cl_px4_mr::FlightPatternSpiralParams::startRadius, turnSign(), cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, cl_px4_mr::NedPoint::yaw, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbSpiral::buildPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateFlightPatternSquareSpiral()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternSquareSpiral ( const FlightPatternSquareSpiralParams & p,
const NedPoint & current )

Definition at line 260 of file pattern_generators.cpp.

262{
263 const float ox = pick(p.originX, current.x);
264 const float oy = pick(p.originY, current.y);
265 const float z = altitudeToZ(p.altitudeAgl, current.z);
266 const float spacing = std::max(p.spacing, 0.5f);
267 const float sign = turnSign(p.direction);
268 float heading = pick(p.initialHeading, std::isnan(current.yaw) ? 0.0f : current.yaw);
269
270 std::vector<NedPoint> path;
271 path.reserve(static_cast<size_t>(std::max(p.numLegs, 0)) + 1);
272 NedPoint v;
273 v.x = ox;
274 v.y = oy;
275 v.z = z;
276 path.push_back(v);
277
278 for (int i = 0; i < p.numLegs; ++i)
279 {
280 const float len = spacing * static_cast<float>(i / 2 + 1);
281 if (p.maxLegLength > 0.0f && len > p.maxLegLength)
282 {
283 break;
284 }
285 v.x += len * std::cos(heading);
286 v.y += len * std::sin(heading);
287 path.push_back(v);
288 heading += sign * static_cast<float>(M_PI) / 2.0f;
289 }
290 return path;
291}

References cl_px4_mr::FlightPatternSquareSpiralParams::altitudeAgl, cl_px4_mr::FlightPatternSquareSpiralParams::direction, cl_px4_mr::FlightPatternSquareSpiralParams::initialHeading, cl_px4_mr::FlightPatternSquareSpiralParams::maxLegLength, cl_px4_mr::FlightPatternSquareSpiralParams::numLegs, cl_px4_mr::FlightPatternSquareSpiralParams::originX, cl_px4_mr::FlightPatternSquareSpiralParams::originY, cl_px4_mr::FlightPatternSquareSpiralParams::spacing, turnSign(), cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, cl_px4_mr::NedPoint::yaw, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbSquareSpiral::buildPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateFlightPatternVSSearch()

std::vector< NedPoint > cl_px4_mr::generateFlightPatternVSSearch ( const FlightPatternVSSearchParams & p,
const NedPoint & current )

Definition at line 488 of file pattern_generators.cpp.

490{
491 const float dx = pick(p.datumX, current.x);
492 const float dy = pick(p.datumY, current.y);
493 const float z = altitudeToZ(p.altitudeAgl, current.z);
494 const float r = std::max(p.radius, 1.0f);
495 const float sign = turnSign(p.direction);
496 const float h0 = pick(p.initialHeading, std::isnan(current.yaw) ? 0.0f : current.yaw);
497 const int cycles = std::max(p.cycles, 1);
498
499 // leg headings in units of 120 degrees relative to the cycle's base heading:
500 // legs 3->4 and 6->7 continue straight through the datum
501 static const int kSteps[9] = {0, 1, 2, 2, 0, 1, 1, 2, 0};
502 const float third = 2.0f * static_cast<float>(M_PI) / 3.0f;
503
504 std::vector<NedPoint> path;
505 path.reserve(9 * static_cast<size_t>(cycles) + 1);
506 NedPoint v;
507 v.x = dx;
508 v.y = dy;
509 v.z = z;
510 path.push_back(v);
511
512 for (int c = 0; c < cycles; ++c)
513 {
514 const float base = h0 + sign * p.reorientation * static_cast<float>(c);
515 for (int leg = 0; leg < 9; ++leg)
516 {
517 const float heading = base + sign * third * static_cast<float>(kSteps[leg]);
518 v.x += r * std::cos(heading);
519 v.y += r * std::sin(heading);
520 path.push_back(v);
521 }
522 // snap back onto the datum to cancel accumulated float drift
523 path.back().x = dx;
524 path.back().y = dy;
525 }
526 return path;
527}

References cl_px4_mr::FlightPatternVSSearchParams::altitudeAgl, cl_px4_mr::FlightPatternVSSearchParams::cycles, cl_px4_mr::FlightPatternVSSearchParams::datumX, cl_px4_mr::FlightPatternVSSearchParams::datumY, cl_px4_mr::FlightPatternVSSearchParams::direction, cl_px4_mr::FlightPatternVSSearchParams::initialHeading, cl_px4_mr::FlightPatternVSSearchParams::radius, cl_px4_mr::FlightPatternVSSearchParams::reorientation, turnSign(), cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, cl_px4_mr::NedPoint::yaw, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbVSSearch::buildPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ haversineDistance() [1/2]

double cl_px4_mr::haversineDistance ( const GeoPoint & a,
const GeoPoint & b )
inline

Definition at line 169 of file geo_utils.hpp.

170{
171 return haversineDistance(a.lat, a.lon, b.lat, b.lon);
172}
double haversineDistance(double lat1, double lon1, double lat2, double lon2)

References haversineDistance(), cl_px4_mr::GeoPoint::lat, and cl_px4_mr::GeoPoint::lon.

Here is the call graph for this function:

◆ haversineDistance() [2/2]

double cl_px4_mr::haversineDistance ( double lat1,
double lon1,
double lat2,
double lon2 )
inline

Definition at line 156 of file geo_utils.hpp.

157{
158 const double p1 = geo_detail::radians(lat1);
159 const double p2 = geo_detail::radians(lat2);
160 const double dLat = p2 - p1;
161 const double dLon = geo_detail::radians(lon2 - lon1);
162
163 const double a = std::sin(dLat / 2.0) * std::sin(dLat / 2.0) +
164 std::sin(dLon / 2.0) * std::sin(dLon / 2.0) * std::cos(p1) * std::cos(p2);
165 const double c = 2.0 * std::atan2(std::sqrt(a), std::sqrt(1.0 - a));
166 return kEarthRadiusM * c;
167}
constexpr double kEarthRadiusM
Definition geo_utils.hpp:59

References kEarthRadiusM, and cl_px4_mr::geo_detail::radians().

Referenced by haversineDistance().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialBearing()

double cl_px4_mr::initialBearing ( double lat1,
double lon1,
double lat2,
double lon2 )
inline

Definition at line 176 of file geo_utils.hpp.

177{
178 const double p1 = geo_detail::radians(lat1);
179 const double p2 = geo_detail::radians(lat2);
180 const double dLon = geo_detail::radians(lon2 - lon1);
181
182 const double y = std::sin(dLon) * std::cos(p2);
183 const double x = std::cos(p1) * std::sin(p2) - std::sin(p1) * std::cos(p2) * std::cos(dLon);
184 return std::atan2(y, x);
185}

References cl_px4_mr::geo_detail::radians().

Here is the call graph for this function:

◆ legHeading()

float cl_px4_mr::legHeading ( const NedPoint & from,
const NedPoint & to )
inline

Definition at line 239 of file pattern_generators.hpp.

240{
241 return std::atan2(to.y - from.y, to.x - from.x);
242}

References cl_px4_mr::NedPoint::x, and cl_px4_mr::NedPoint::y.

Referenced by cl_px4_mr::CbSineWaveHorizontal::buildPath().

Here is the caller graph for this function:

◆ levelRotationFromPx4Quaternion()

void cl_px4_mr::levelRotationFromPx4Quaternion ( const std::array< float, 4 > & q,
std::array< float, 9 > & r )
inline

Definition at line 30 of file level_frame.hpp.

31{
32 // px4_ros_com frame_transforms constants (tf2 order x, y, z, w)
33 const tf2::Quaternion kNedEnuQ(0.70710678118654752, 0.70710678118654752, 0.0, 0.0);
34 const tf2::Quaternion kFrdFluQ(1.0, 0.0, 0.0, 0.0);
35 const tf2::Quaternion qNedFrd(q[1], q[2], q[3], q[0]);
36 tf2::Quaternion qEnuFlu = kNedEnuQ * qNedFrd * kFrdFluQ;
37 qEnuFlu.normalize();
38 const tf2::Matrix3x3 m(qEnuFlu);
39 const double yaw = std::atan2(m[1][0], m[0][0]);
40 tf2::Matrix3x3 unyaw;
41 unyaw.setRPY(0.0, 0.0, -yaw);
42 const tf2::Matrix3x3 level = unyaw * m;
43 for (int i = 0; i < 3; ++i)
44 {
45 for (int j = 0; j < 3; ++j)
46 {
47 r[i * 3 + j] = static_cast<float>(level[i][j]);
48 }
49 }
50}

Referenced by cl_px4_mr::CpTunnelCentering::onCloud().

Here is the caller graph for this function:

◆ nedDistance()

float cl_px4_mr::nedDistance ( const NedPoint & a,
const NedPoint & b )
inline

Definition at line 188 of file geo_utils.hpp.

189{
190 const float dx = b.x - a.x;
191 const float dy = b.y - a.y;
192 const float dz = b.z - a.z;
193 return std::sqrt(dx * dx + dy * dy + dz * dz);
194}

References cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, and cl_px4_mr::NedPoint::z.

Referenced by cumulativeLengths(), generateFlightPatternGridPattern(), cl_px4_mr::CbPx4PathFollowerBase::onEntry(), resamplePolyline(), cl_px4_mr::CbFollowNedPath::setPath(), and cl_px4_mr::CbPx4PathFollowerBase::update().

Here is the caller graph for this function:

◆ nedDistanceXY()

float cl_px4_mr::nedDistanceXY ( const NedPoint & a,
const NedPoint & b )
inline

Definition at line 196 of file geo_utils.hpp.

197{
198 const float dx = b.x - a.x;
199 const float dy = b.y - a.y;
200 return std::sqrt(dx * dx + dy * dy);
201}

References cl_px4_mr::NedPoint::x, and cl_px4_mr::NedPoint::y.

Referenced by cl_px4_mr::CbPx4PathFollowerBase::update().

Here is the caller graph for this function:

◆ polylineLength()

float cl_px4_mr::polylineLength ( const std::vector< NedPoint > & path)
inline

Definition at line 221 of file geo_utils.hpp.

222{
223 if (path.empty())
224 {
225 return 0.0f;
226 }
227 return cumulativeLengths(path).back();
228}

References cumulativeLengths().

Here is the call graph for this function:

◆ resamplePolyline()

std::vector< NedPoint > cl_px4_mr::resamplePolyline ( const std::vector< NedPoint > & path,
float spacing )
inline

Definition at line 271 of file geo_utils.hpp.

272{
273 std::vector<NedPoint> out;
274 if (path.empty() || spacing <= 0.0f)
275 {
276 return path;
277 }
278 out.push_back(path.front());
279 for (size_t i = 1; i < path.size(); ++i)
280 {
281 const NedPoint & a = path[i - 1];
282 const NedPoint & b = path[i];
283 const float len = nedDistance(a, b);
284 const int n = std::max(1, static_cast<int>(std::ceil(len / spacing)));
285 for (int k = 1; k < n; ++k)
286 {
287 const float t = static_cast<float>(k) / static_cast<float>(n);
288 NedPoint p;
289 p.x = a.x + t * (b.x - a.x);
290 p.y = a.y + t * (b.y - a.y);
291 p.z = a.z + t * (b.z - a.z);
292 out.push_back(p);
293 }
294 out.push_back(b);
295 }
296 return out;
297}

References nedDistance(), cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, and cl_px4_mr::NedPoint::z.

Here is the call graph for this function:

◆ sampleAtArcLength()

NedPoint cl_px4_mr::sampleAtArcLength ( const std::vector< NedPoint > & path,
const std::vector< float > & cum,
float s,
size_t * segmentIndex = nullptr )
inline

Definition at line 233 of file geo_utils.hpp.

236{
237 if (path.empty())
238 {
239 return NedPoint{};
240 }
241 if (path.size() == 1 || s <= 0.0f)
242 {
243 if (segmentIndex) *segmentIndex = 0;
244 return path.front();
245 }
246 if (s >= cum.back())
247 {
248 if (segmentIndex) *segmentIndex = path.size() - 2;
249 return path.back();
250 }
251
252 // first vertex whose cumulative length exceeds s
253 auto it = std::upper_bound(cum.begin(), cum.end(), s);
254 size_t i1 = static_cast<size_t>(it - cum.begin());
255 size_t i0 = i1 - 1;
256 const float segLen = cum[i1] - cum[i0];
257 const float t = segLen > 0.0f ? (s - cum[i0]) / segLen : 0.0f;
258
259 if (segmentIndex) *segmentIndex = i0;
260
261 NedPoint p;
262 p.x = path[i0].x + t * (path[i1].x - path[i0].x);
263 p.y = path[i0].y + t * (path[i1].y - path[i0].y);
264 p.z = path[i0].z + t * (path[i1].z - path[i0].z);
265 p.yaw = path[i0].yaw; // yaw is per-vertex, not interpolated
266 return p;
267}

References cl_px4_mr::NedPoint::x, cl_px4_mr::NedPoint::y, cl_px4_mr::NedPoint::yaw, and cl_px4_mr::NedPoint::z.

Referenced by cl_px4_mr::CbPx4PathFollowerBase::commandFor().

Here is the caller graph for this function:

◆ turnName()

const char * cl_px4_mr::turnName ( Turn t)
inline

Definition at line 58 of file pattern_generators.hpp.

58{ return t == Turn::RIGHT ? "RIGHT" : "LEFT"; }

References RIGHT.

Referenced by cl_px4_mr::CbLemniscate::buildPath(), cl_px4_mr::CbLoiter::buildPath(), cl_px4_mr::CbSpiral::buildPath(), cl_px4_mr::CbSquareSpiral::buildPath(), and cl_px4_mr::CbVSSearch::buildPath().

Here is the caller graph for this function:

◆ turnSign()

float cl_px4_mr::turnSign ( Turn t)
inline

Definition at line 57 of file pattern_generators.hpp.

57{ return t == Turn::RIGHT ? 1.0f : -1.0f; }

References RIGHT.

Referenced by generateFlightPatternFigureEight(), generateFlightPatternLawnmower(), generateFlightPatternLoiter(), generateFlightPatternSpiral(), generateFlightPatternSquareSpiral(), and generateFlightPatternVSSearch().

Here is the caller graph for this function:

◆ wrapPi()

float cl_px4_mr::wrapPi ( float angle)
inline

Definition at line 25 of file angle_utils.hpp.

26{
27 angle = std::fmod(angle + static_cast<float>(M_PI), 2.0f * static_cast<float>(M_PI));
28 if (angle < 0.0f)
29 {
30 angle += 2.0f * static_cast<float>(M_PI);
31 }
32 return angle - static_cast<float>(M_PI);
33}

Referenced by cl_px4_mr::CbPx4PathFollowerBase::applyCentering(), cl_px4_mr::CbPx4PathFollowerBase::commandFor(), cl_px4_mr::CbSineAltitudeCruise::onEntry(), cl_px4_mr::CbWaitForHeadingStable::onEntry(), cl_px4_mr::CbYawScan::onEntry(), and cl_px4_mr::CbYawScan::update().

Here is the caller graph for this function:

Variable Documentation

◆ kEarthRadiusM

double cl_px4_mr::kEarthRadiusM = 6371000.0
constexpr