PX4 Firmware
PX4 Autopilot Software http://px4.io
ManualVelocitySmoothingXY.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file ManualVelocitySmoothingXY.hpp
36  *
37  */
38 
39 #pragma once
40 
41 #include "VelocitySmoothing.hpp"
42 
43 #include <matrix/matrix/math.hpp>
44 
45 using matrix::Vector2f;
46 
48 {
49 public:
50  ManualVelocitySmoothingXY() = default;
51  ~ManualVelocitySmoothingXY() = default;
52 
53  void reset(const Vector2f &accel, const Vector2f &vel, const Vector2f &pos);
54  void update(float dt, const Vector2f &velocity_target);
55 
57 
58  void setMaxJerk(const float max_jerk)
59  {
60  _trajectory[0].setMaxJerk(max_jerk);
61  _trajectory[1].setMaxJerk(max_jerk);
62  }
63  float getMaxJerk() const { return _trajectory[0].getMaxJerk(); }
64 
65  void setMaxAccel(const float max_accel)
66  {
67  _trajectory[0].setMaxAccel(max_accel);
68  _trajectory[1].setMaxAccel(max_accel);
69  }
70  float getMaxAccel() const { return _trajectory[0].getMaxAccel(); }
71 
72  void setMaxVel(const float max_vel)
73  {
74  _trajectory[0].setMaxVel(max_vel);
75  _trajectory[1].setMaxVel(max_vel);
76  }
77  float getMaxVel() const { return _trajectory[0].getMaxVel(); }
78 
79  Vector2f getCurrentJerk() const { return _state.j; }
80  Vector2f getCurrentAcceleration() const { return _state.a; }
81 
82  void setCurrentVelocity(const Vector2f &vel)
83  {
84  _state.v = vel;
87  }
88  Vector2f getCurrentVelocity() const { return _state.v; }
89 
90  void setCurrentPosition(const Vector2f &pos)
91  {
92  _state.x = pos;
95  // TODO: check lock/unlock in case of EKF reset
96  }
98 
100 
101 private:
102  void resetPositionLock();
103  void updateTrajectories(float dt);
104  void checkPositionLock(const Vector2f &velocity_target);
105  void updateTrajDurations(const Vector2f &velocity_target);
106 
107  VelocitySmoothing _trajectory[2]; ///< Trajectory in x and y directions
108 
110 
112 
115 
116  struct {
121  } _state;
122 };
struct ManualVelocitySmoothingXY::@64 _state
void checkPositionLock(const Vector2f &velocity_target)
void update(float dt, const Vector2f &velocity_target)
~ManualVelocitySmoothingXY()=default
void setMaxJerk(float max_jerk)
float getMaxAccel() const
void setMaxVel(const float max_vel)
void setCurrentVelocity(const float vel)
TODO: document the algorithm |T1| T2 |T3| __| |____ __ Jerk |_| / \ Acceleration ___/ ___ ;" / / V...
void setMaxAccel(const float max_accel)
void setCurrentPosition(const Vector2f &pos)
void setCurrentPositionEstimate(const Vector2f &pos)
VelocitySmoothing _trajectory[2]
Trajectory in x and y directions.
Vector2< float > Vector2f
Definition: Vector2.hpp:69
void setCurrentPosition(const float pos)
void updateTrajDurations(const Vector2f &velocity_target)
ManualVelocitySmoothingXY()=default
float getMaxJerk() const
Getters and setters.
float getMaxVel() const
float dt
Definition: px4io.c:73
void setMaxVel(float max_vel)
void reset(const Vector2f &accel, const Vector2f &vel, const Vector2f &pos)
void setCurrentVelocity(const Vector2f &vel)
void setMaxJerk(const float max_jerk)
void setMaxAccel(float max_accel)
void setVelSpFeedback(const Vector2f &fb)