gwnavruntime/pathfollower/splinetrajectory.h Source File

splinetrajectory.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 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 // primary contact: LAPA - secondary contact: BRGR
8 #ifndef Navigation_SplineTrajectory_H
9 #define Navigation_SplineTrajectory_H
10 
19 
20 
21 namespace Kaim
22 {
23 
24 class VisualDebugServer;
25 class SplineTrajectoryConfig;
26 class PositionOnLivePath;
27 class CircleArcSplineComputer;
28 class Trajectory;
29 class ComputeVelocityVisualDebug;
30 class BaseShortcutTrajectory;
31 class Bot;
32 class IAvoidanceComputer;
33 
34 
39 class SplineTrajectory: public RefCountBase<SplineTrajectory, MemStat_PathFollowing>
40 {
41  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_PathFollowing)
43 
44 public:
45  SplineTrajectory(Trajectory* trajectory);
46  ~SplineTrajectory() {}
47 
48  void Compute(KyFloat32 simulationTimeInSeconds, Ptr<BaseShortcutTrajectory> shortcutTrajectory);
49 
53 
54 public: // internal
55 
57  // High-level internal methods
58 
59  Bot* GetBot() const;
60 
61  void Clear(); // fully clear the trajectory and default its config
62  void ClearTrajectory(); // only clear the current computed trajectory
63 
64  void SetSplineTrajectoryConfig(const SplineTrajectoryConfig& other);
65 
67  // VisualDebug
68 
69  virtual void SendVisualDebugBlob(VisualDebugServer& visualDebugServer, VisualDebugSendChangeEvent changeEvent);
70  void RemoveAllVisualDebugBeforeTrajectoryChange(VisualDebugServer& visualDebugServer);
71 
72 protected:
73  void ForceClearTrajectory(); // clear trajectory without checking Bot::IsPathRecomputationNeeded();
74  void ClearSplineComputer();
75  void ClearSplineCut();
76 
77  void UpdateCircleArcSpline(KyFloat32 simulationTimeInSeconds, FollowedCircleArcSpline& previousShortcutSpline);
78  void UpdateShortcutSpline(KyFloat32 simulationTimeInSeconds, const FollowedCircleArcSpline& previousShortcutSpline, Ptr<BaseShortcutTrajectory> shortcutTrajectory);
79 
80  bool CanUseChannel();
81  bool IsBotBackInChannel();
82  bool IsBotOutOfChannel();
83  bool IsEndOfChannelReached();
84  bool IsFallbackToShortcutRequired();
85 
86  void FollowFrozenSpline(KyFloat32 simulationTimeInSeconds);
87  bool CanFrozenSplineBeFollowed();
88 
90  // Spline computation internal methods
91 
92  void RequestSplineComputation();
93  void IntegrateSplineFromQuery();
94 
95  bool ShouldRecomputeSpline(const ChannelSectionPtr& upperBoundSection);
96  void ComputeSpline(KyFloat32 simulationTimeInSeconds, const ChannelSectionPtr& upperBoundSection);
97 
98  void InitSplineStartPosition();
99  void ComputeSplineStartPosition();
100  void UpdateStartCutWithUpperBound(const ChannelSectionPtr& upperBoundSection);
101  KyResult ComputeNewSplineEndPosition();
102  void CutFrozenSpline(KyFloat32 simulationTimeInSeconds);
103  void AddStartConstraintToSplineQuery();
104  KyUInt32 SelectSpline(const CircleArcSplineComputer& circleArcSplineComputer);
105 
106  void ComputeSplineFromShortcutTrajectory(KyFloat32 simulationTimeInSeconds, Ptr<BaseShortcutTrajectory> shortcutTrajectory);
107 
109  // Spline follow internal methods
110 
111  void UpdateSplinePosition(KyFloat32 simulationTimeInSeconds);
112  void UpdateSplineTargetPosition(KyFloat32 simulationTimeInSeconds);
113  void ComputeMovingDirection2D(KyFloat32 simulationTimeInSeconds, Vec2f& out_movingDirection);
114  void ComputeVelocity(KyFloat32 simulationTimeInSeconds);
115 
116  void ComputeAvoidanceTrajectory(KyFloat32 simulationTimeInSeconds, KyFloat32 desiredSpeed, const Kaim::Vec2f& movingDirection);
117  void StopBot(const Vec2f& frontDirection);
118 
119  void DrawComputeVelocityVisualDebug(const ComputeVelocityVisualDebug& collectedDebugData);
120 
121  bool CapDirectionChangeAngle(const Vec2f& normalizedFrom, const Vec2f& normalizedTo, Vec2f& result, KyFloat32 maxAngleInRad) const;
122 
123 public: // internal
124  class SplineCut
125  {
126  public:
127  SplineCut() { Clear(); }
128  ~SplineCut() { Clear(); }
129 
130  bool IsValid() { return m_channelSectionIdx != KyUInt32MAXVAL && m_positionOnSpline.IsValid() && m_splineSection.IsInitialized(); }
131 
132  void Clear()
133  {
134  m_positionOnSpline.Invalidate();
135  m_splineSection.Reset();
136  m_channelSectionIdx = KyUInt32MAXVAL;
137  m_mode = CutSplineAtArcStart;
138  }
139 
140  public:
141  PositionOnCircleArcSpline m_positionOnSpline;
142  CircleArcSplineSection m_splineSection;
143  KyUInt32 m_channelSectionIdx;
144  SplineCutMode m_mode;
145  };
146 
147  Trajectory* m_trajectory;
148  ResetTrajectoryStatus m_trajectoryStatus; // maintain internal status of the SplineTrajectory
149  Ptr<IAvoidanceComputer> m_avoidanceComputer;
150  FollowedCircleArcSpline m_followedSpline;
151  KyUInt32 m_positionOnSplineChannelSectionIdx; // The channel section of the current bot position on spline, computed only at the time a spline is computed
152 
153  // information used for computation of spline (full spline or new end part of current spline)
154  ChannelSectionPtr m_splineComputerStartSection;
155  Vec3f m_splineComputerStartPosition;
156 
157  // Some spline information computed when identifying spline cut position
158  // and used once the new spline is computed to append it to the kept part
159  // of the former spline.
160  SplineCutMode m_botPosSplineCutMode;
161  SplineCut m_splineCutThisFrame;
162  SplineCut m_splineCutWhenSplineRequested;
163 
164  Ptr<CircleArcSplineComputationQuery> m_splineComputationQuery;
165 
166  SplineTrajectoryConfig m_splineTrajectoryConfig;
167  RadiusProfile m_currentSplineRadiusProfile;
168 
169  Vec2f m_previousMovingDirection;
170  float m_stopWaitTime;
171 
172  bool m_advancedVisualDebuggingEnabled;
173 };
174 
175 } // namespace Kaim
176 
177 #endif // Navigation_SplineTrajectory_H
This class is the world element that represent an active character in Gameware Navigation.
Definition: bot.h:150
SplineTrajectory computes a CircleArcSpline that allows to anticipate and adapt the velocity in the t...
Definition: splinetrajectory.h:40
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Maintains a position moving along a given CricleArcSpline.
Definition: positiononcirclearcspline.h:64
RadiusProfile is an array of preferred radii.
Definition: radiusprofile.h:29
const FollowedCircleArcSpline * GetFollowedCircleArcSpline() const
Returns information about the currently followed circleArcSpline if any.
#define KY_CLASS_WITHOUT_COPY(ClassName)
Define to forbid copy constructor and copy assignment.
Definition: types.h:387
KyUInt32 m_positionOnSplineChannelSectionIdx
CircleArcSpline with start/end information as well current position and target.
Definition: splinetrajectory.h:161
Class that configures how the trajectory is computed from the Channel.
Definition: splinetrajectoryconfig.h:31
This class defines a two-dimensional vector whose coordinates are stored using floating-point numbers...
Definition: vec2f.h:24
Definition: gamekitcrowddispersion.h:20
Class used to compute a CircleArcSpline in a Channel.
Definition: circlearcsplinecomputer.h:89
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
CircleArcSpline with computation information and current position of follow.
Definition: followedcirclearcspline.h:31
The VisualDebugServer manages the sending of data to clients.
Definition: visualdebugserver.h:254
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
Class representing either an oriented circle arc or a straight line segment, to be aggregated into a ...
Definition: circlearcsplinesection.h:25
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
This class computes the trajectory either with ShortcutTrajectory or with SplineTrajectory.
Definition: trajectory.h:30
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23
ResetTrajectoryStatus
Definition: resettrajectorystatus.h:14