PX4 Firmware
PX4 Autopilot Software http://px4.io
ManualVelocitySmoothingZ.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 ManualVelocitySmoothingZ.hpp
36  *
37  */
38 
39 #pragma once
40 
41 #include "VelocitySmoothing.hpp"
42 
44 {
45 public:
46  ManualVelocitySmoothingZ() = default;
47  ~ManualVelocitySmoothingZ() = default;
48 
49  void reset(float accel, float vel, float pos);
50  void update(float dt, float velocity_target);
51 
52  void setVelSpFeedback(const float fb) { _velocity_setpoint_feedback = fb; }
53 
54  void setMaxJerk(const float max_jerk)
55  {
56  _trajectory.setMaxJerk(max_jerk);
57  }
58  void setMaxAccelUp(const float max_accel_up)
59  {
60  _max_accel_up = max_accel_up;
61  }
62  void setMaxAccelDown(const float max_accel_down)
63  {
64  _max_accel_down = max_accel_down;
65  }
66  void setMaxVelUp(const float max_vel_up)
67  {
68  _max_vel_up = max_vel_up;
69  }
70  void setMaxVelDown(const float max_vel_down)
71  {
72  _max_vel_down = max_vel_down;
73  }
74 
75  float getCurrentJerk() const { return _state.j; }
76  float getCurrentAcceleration() const { return _state.a; }
77  void setCurrentVelocity(const float vel)
78  {
79  _state.v = vel;
81  }
82  float getCurrentVelocity() const { return _state.v; }
83  void setCurrentPosition(const float pos)
84  {
85  _state.x = pos;
87  }
90 
91 private:
92  void resetPositionLock();
93  void updateTrajectories(float dt);
94  void updateTrajConstraints(float vel_target);
95  void checkPositionLock(float velocity_target);
96  void updateTrajDurations(float velocity_target);
97 
98  VelocitySmoothing _trajectory; ///< Trajectory in z direction
99 
101 
103 
106 
107  struct {
108  float j;
109  float a;
110  float v;
111  float x;
112  } _state;
113 
114  float _max_accel_up{0.f};
115  float _max_accel_down{0.f};
116  float _max_vel_up{0.f};
117  float _max_vel_down{0.f};
118 };
void setVelSpFeedback(const float fb)
struct ManualVelocitySmoothingZ::@65 _state
~ManualVelocitySmoothingZ()=default
void setMaxJerk(float max_jerk)
void update(float dt, float velocity_target)
void setCurrentVelocity(const float vel)
void reset(float accel, float vel, float pos)
ManualVelocitySmoothingZ()=default
TODO: document the algorithm |T1| T2 |T3| __| |____ __ Jerk |_| / \ Acceleration ___/ ___ ;" / / V...
void setCurrentVelocity(const float vel)
void setCurrentPosition(const float pos)
void setMaxAccelDown(const float max_accel_down)
void setMaxVelDown(const float max_vel_down)
VelocitySmoothing _trajectory
Trajectory in z direction.
float dt
Definition: px4io.c:73
void updateTrajDurations(float velocity_target)
void setMaxJerk(const float max_jerk)
void updateTrajConstraints(float vel_target)
void setMaxVelUp(const float max_vel_up)
void setCurrentPosition(const float pos)
void checkPositionLock(float velocity_target)
void setMaxAccelUp(const float max_accel_up)