Firmware
StraightLine.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2018 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 
42 #pragma once
43 
44 #include <px4_module_params.h>
45 #include <matrix/matrix/math.hpp>
46 
47 class StraightLine : public ModuleParams
48 {
49 public:
50  StraightLine(ModuleParams *parent, const float &deltatime, const matrix::Vector3f &pos);
51  ~StraightLine() = default;
52 
53  // setter functions
54  void setLineFromTo(const matrix::Vector3f &origin, const matrix::Vector3f &target);
55  void setSpeed(const float &speed);
56  void setSpeedAtTarget(const float &speed_at_target);
57  void setAcceleration(const float &acc);
58  void setDeceleration(const float &dec);
59 
63  void setAllDefaults();
64 
69  float getMaxAcc();
70 
75  float getMaxVel();
76 
83  void generateSetpoints(matrix::Vector3f &position_setpoint, matrix::Vector3f &velocity_setpoint);
84 
85 private:
86  const float &_deltatime;
87  const matrix::Vector3f &_pos;
89  float _desired_acceleration{0.0f};
90  float _desired_deceleration{0.0f};
91  float _desired_speed{0.0f};
92  float _desired_speed_at_target{0.0f};
94  matrix::Vector3f _target{};
95  matrix::Vector3f _origin{};
97  // parameters for default values
98  DEFINE_PARAMETERS(
99  (ParamFloat<px4::params::MPC_ACC_HOR_MAX>) _param_mpc_acc_hor_max,
100  (ParamFloat<px4::params::MPC_ACC_UP_MAX>) _param_mpc_acc_up_max,
101  (ParamFloat<px4::params::MPC_ACC_DOWN_MAX>) _param_mpc_acc_down_max,
102  (ParamFloat<px4::params::MPC_XY_VEL_MAX>) _param_mpc_xy_vel_max,
103  (ParamFloat<px4::params::MPC_Z_VEL_MAX_UP>) _param_mpc_z_vel_max_up,
104  (ParamFloat<px4::params::MPC_Z_VEL_MAX_DN>) _param_mpc_z_vel_max_dn,
105  (ParamFloat<px4::params::NAV_ACC_RAD>) _param_nav_acc_rad
106  )
107 
108 };
void setAllDefaults()
Set all parameters to their default value depending on the direction of the line. ...
Definition: StraightLine.cpp:177
Definition: StraightLine.hpp:47
Definition: px4_param.h:318
C++ base class for modules/classes using configuration parameters.
Definition: px4_module_params.h:46
void generateSetpoints(matrix::Vector3f &position_setpoint, matrix::Vector3f &velocity_setpoint)
Generate setpoints on a straight line according to parameters.
Definition: StraightLine.cpp:55
float getMaxAcc()
Get the maximum possible acceleration depending on the direction of the line Respects horizontal and ...
Definition: StraightLine.cpp:106
float getMaxVel()
Get the maximum possible velocity depending on the direction of the line Respects horizontal and vert...
Definition: StraightLine.cpp:141