gwnavruntime/pathfollower/splinetrajectory.h Source File

splinetrajectory.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
17 
18 
19 namespace Kaim
20 {
21 
22 class VisualDebugServer;
23 class SplineTrajectoryConfig;
24 class PositionOnLivePath;
25 class CircleArcSplineComputer;
26 class Trajectory;
27 class ComputeVelocityVisualDebug;
28 class BaseShortcutTrajectory;
29 class Bot;
30 class IAvoidanceComputer;
31 
32 
37 class SplineTrajectory: public RefCountBase<SplineTrajectory, MemStat_PathFollowing>
38 {
39  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_PathFollowing)
41 
42 public:
43  SplineTrajectory(Trajectory* trajectory);
44 
45  ~SplineTrajectory() {}
46 
47  void Compute(KyFloat32 simulationTimeInSeconds, KyUInt32 worldUpdateIdx, Ptr<BaseShortcutTrajectory> shortcutTrajectory);
48 
52 
53 public: // internal
54 
56  // High-level internal methods
57 
58  Bot* GetBot() const;
59 
60  void Clear(); // fully clear the trajectory and default its config
61  void ClearTrajectory(); // only clear the current computed trajectory
62 
63  void SetSplineTrajectoryConfig(const SplineTrajectoryConfig& other);
64 
66  // VisualDebug
67 
68  virtual void SendVisualDebugBlob(VisualDebugServer& visualDebugServer, VisualDebugSendChangeEvent changeEvent);
69  void RemoveAllVisualDebugBeforeTrajectoryChange(VisualDebugServer& visualDebugServer);
70 
71 protected:
72  void ForceClearTrajectory(); // clear trajectory without checking Bot::IsPathRecomputationNeeded();
73  void ClearSplineComputer();
74  void ClearSplineCut();
75 
76  void UpdateCircleArcSpline(KyFloat32 simulationTimeInSeconds, FollowedCircleArcSpline& previousShortcutSpline);
77  void UpdateShortcutSpline(KyFloat32 simulationTimeInSeconds, KyUInt32 worldUpdateIdx, const FollowedCircleArcSpline& previousShortcutSpline, Ptr<BaseShortcutTrajectory> shortcutTrajectory);
78 
79  bool CanUseChannel();
80  bool IsBotBackInChannel();
81  bool IsBotOutOfChannel();
82  bool IsEndOfChannelReached();
83  bool IsFallbackToShortcutRequired();
84 
85  void FollowFrozenSpline(KyFloat32 simulationTimeInSeconds);
86  bool CanFrozenSplineBeFollowed();
87 
89  // Spline computation internal methods
90 
91  void RequestSplineComputation();
92  void IntegrateSplineFromQuery();
93 
94  bool ShouldRecomputeSpline(const ChannelSectionPtr& upperBoundSection);
95  void ComputeSpline(KyFloat32 simulationTimeInSeconds, const ChannelSectionPtr& upperBoundSection);
96 
97  void InitSplineStartPosition();
98  void ComputeSplineStartPosition();
99  void UpdateStartCutWithUpperBound(const ChannelSectionPtr& upperBoundSection);
100  KyResult ComputeNewSplineEndPosition();
101  void CutFrozenSpline(KyFloat32 simulationTimeInSeconds);
102  void AddStartConstraintToSplineQuery();
103  KyUInt32 SelectSpline(const CircleArcSplineComputer& circleArcSplineComputer);
104 
105  void ComputeSplineFromShortcutTrajectory(KyFloat32 simulationTimeInSeconds, Ptr<BaseShortcutTrajectory> shortcutTrajectory);
106 
108  // Spline follow internal methods
109 
110  void UpdateSplinePosition(KyFloat32 simulationTimeInSeconds);
111  void UpdateSplineTargetPosition(KyFloat32 simulationTimeInSeconds);
112  void ComputeMovingDirection2D(KyFloat32 simulationTimeInSeconds, Vec2f& out_movingDirection);
113  void ComputeVelocity(KyFloat32 simulationTimeInSeconds);
114 
115  void ComputeAvoidanceTrajectory(KyFloat32 simulationTimeInSeconds, KyFloat32 desiredSpeed, const Kaim::Vec2f& movingDirection);
116  void StopBot(const Vec2f& frontDirection);
117 
118  void DrawComputeVelocityVisualDebug(const ComputeVelocityVisualDebug& collectedDebugData);
119 
120 public: // internal
121  class SplineCut
122  {
123  public:
124  SplineCut() { Clear(); }
125  ~SplineCut() { Clear(); }
126 
127  bool IsValid() { return m_channelSectionIdx != KyUInt32MAXVAL && m_positionOnSpline.IsValid() && m_splineSection.IsInitialized(); }
128 
129  void Clear()
130  {
131  m_positionOnSpline.Invalidate();
132  m_splineSection.Reset();
133  m_channelSectionIdx = KyUInt32MAXVAL;
134  m_mode = CutSplineAtArcStart;
135  }
136 
137  public:
138  PositionOnCircleArcSpline m_positionOnSpline;
139  CircleArcSplineSection m_splineSection;
140  KyUInt32 m_channelSectionIdx;
141  SplineCutMode m_mode;
142  };
143 
144  Trajectory* m_trajectory;
145  ResetTrajectoryStatus m_trajectoryStatus; // maintain internal status of the SplineTrajectory
146  Ptr<IAvoidanceComputer> m_avoidanceComputer;
147  FollowedCircleArcSpline m_followedSpline;
148  KyUInt32 m_positionOnSplineChannelSectionIdx; // The channel section of the current bot position on spline, computed only at the time a spline is computed
149 
150  // information used for computation of spline (full spline or new end part of current spline)
151  ChannelSectionPtr m_splineComputerStartSection;
152  Vec3f m_splineComputerStartPosition;
153 
154  // Some spline information computed when identifying spline cut position
155  // and used once the new spline is computed to append it to the kept part
156  // of the former spline.
157  SplineCutMode m_botPosSplineCutMode;
158  SplineCut m_splineCutThisFrame;
159  SplineCut m_splineCutWhenSplineRequested;
160 
161  Ptr<CircleArcSplineComputationQuery> m_splineComputationQuery;
162 
163  SplineTrajectoryConfig m_splineTrajectoryConfig;
164  RadiusProfile m_currentSplineRadiusProfile;
165 
166  Vec2f m_previousMovingDirection;
167  float m_stopWaitTime;
168 
169  bool m_advancedVisualDebuggingEnabled;
170 };
171 
172 } // namespace Kaim
173 
This class is the world element that represent an active character in Autodesk Navigation.
Definition: bot.h:128
SplineTrajectory computes a CircleArcSpline that allows to anticipate and adapt the velocity in the t...
Definition: splinetrajectory.h:37
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Maintains a position moving along a given CricleArcSpline.
Definition: positiononcirclearcspline.h:60
RadiusProfile is an array of preferred radii.
Definition: radiusprofile.h:26
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:196
KyUInt32 m_positionOnSplineChannelSectionIdx
CircleArcSpline with start/end information as well current position and target.
Definition: splinetrajectory.h:148
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Class that configures how the trajectory is computed from the Channel.
Definition: splinetrajectoryconfig.h:28
const FollowedCircleArcSpline * GetFollowedCircleArcSpline() const
Returns information about the currently followed circleArcSpline if any.
Definition: splinetrajectory.cpp:486
2d vector using KyFloat32.
Definition: vec2f.h:18
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Class used to compute a CircleArcSpline in a Channel.
Definition: circlearcsplinecomputer.h:86
CircleArcSpline with computation information and current position of follow.
Definition: followedcirclearcspline.h:30
Class representing either an oriented circle arc or a straight line segment, to be aggregated into a ...
Definition: circlearcsplinesection.h:23
#define KyUInt32MAXVAL
KyUInt32 max value
Definition: types.h:68
This class computes the trajectory either with ShortcutTrajectory or with SplineTrajectory.
Definition: trajectory.h:26
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16
ResetTrajectoryStatus
Definition: resettrajectorystatus.h:13