PX4 Firmware
PX4 Autopilot Software http://px4.io
CatapultLaunchMethod.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2013, 2014 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 CatapultLaunchMethod.cpp
36  * Catapult Launch detection
37  *
38  * @author Thomas Gubler <thomasgubler@gmail.com>
39  *
40  */
41 
42 #include "CatapultLaunchMethod.h"
43 
44 #include <px4_platform_common/log.h>
45 
46 namespace launchdetection
47 {
48 
50  ModuleParams(parent)
51 {
53 }
54 
55 void CatapultLaunchMethod::update(float accel_x)
56 {
57  float dt = hrt_elapsed_time(&_last_timestamp) * 1e-6f;
59 
60  switch (state) {
62 
63  /* Detect a acceleration that is longer and stronger as the minimum given by the params */
64  if (accel_x > _param_laun_cat_a.get()) {
65  _integrator += dt;
66 
67  if (_integrator > _param_laun_cat_t.get()) {
68  if (_param_laun_cat_mdel.get() > 0.0f) {
70  PX4_WARN("Launch detected: enablecontrol, waiting %8.4fs until full throttle",
71  double(_param_laun_cat_mdel.get()));
72 
73  } else {
74  /* No motor delay set: go directly to enablemotors state */
76  PX4_WARN("Launch detected: enablemotors (delay not activated)");
77  }
78  }
79 
80  } else {
81  reset();
82  }
83 
84  break;
85 
87  /* Vehicle is currently controlling attitude but not with full throttle. Waiting until delay is
88  * over to allow full throttle */
90 
91  if (_motorDelayCounter > _param_laun_cat_mdel.get()) {
92  PX4_INFO("Launch detected: state enablemotors");
94  }
95 
96  break;
97 
98  default:
99  break;
100 
101  }
102 }
103 
105 {
106  return state;
107 }
108 
110 {
111  _integrator = 0.0f;
112  _motorDelayCounter = 0.0f;
114 }
115 
116 float CatapultLaunchMethod::getPitchMax(float pitchMaxDefault)
117 {
118  /* If motor is turned on do not impose the extra limit on maximum pitch */
120  return pitchMaxDefault;
121 
122  } else {
123  return _param_laun_cat_pmax.get();
124  }
125 }
126 
127 } // namespace launchdetection
Launch has been detected, the controller should control attitude and also throttle up the motors...
Definition: LaunchMethod.h:53
No launch has been detected.
Definition: LaunchMethod.h:48
float getPitchMax(float pitchMaxDefault) override
Launch has been detected, the controller should control the attitude.
Definition: LaunchMethod.h:49
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Definition: integration.cpp:8
static hrt_abstime hrt_elapsed_time(const hrt_abstime *then)
Compute the delta between a timestamp taken in the past and now.
Definition: drv_hrt.h:102
LaunchDetectionResult getLaunchDetected() const override
float dt
Definition: px4io.c:73
Catpult Launch detection.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).