PX4 Firmware
PX4 Autopilot Software http://px4.io
landing_target_estimator_main.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2013-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 
34 /**
35  * @file landing_target_estimator_main.cpp
36  * Landing target position estimator. Filter and publish the position of a landing target on the ground as observed by an onboard sensor.
37  *
38  * @author Nicolas de Palezieux (Sunflower Labs) <ndepal@gmail.com>
39  * @author Mohammed Kabir <kabir@uasys.io>
40  *
41  */
42 
43 #include <px4_platform_common/px4_config.h>
44 #include <px4_platform_common/defines.h>
45 #include <px4_platform_common/tasks.h>
46 #include <px4_platform_common/posix.h>
47 #include <unistd.h>
48 #include <stdio.h>
49 #include <string.h>
50 #include <stdlib.h>
51 #include <errno.h>
52 #include <drivers/drv_hrt.h>
53 #include <systemlib/err.h>
54 
55 #include "LandingTargetEstimator.h"
56 
57 
59 {
60 
61 static bool thread_should_exit = false; /**< daemon exit flag */
62 static bool thread_running = false; /**< daemon status flag */
63 static int daemon_task; /**< Handle of daemon task / thread */
64 
65 /* Run main loop at this rate in Hz. */
66 static constexpr uint32_t landing_target_estimator_UPDATE_RATE_HZ = 50;
67 
68 /**
69  * Landing target position estimator app start / stop handling function
70  * This makes the module accessible from the nuttx shell
71  * @ingroup apps
72  */
73 extern "C" __EXPORT int landing_target_estimator_main(int argc, char *argv[]);
74 
75 /**
76  * Mainloop of daemon.
77  */
78 int landing_target_estimator_thread_main(int argc, char *argv[]);
79 
80 /**
81 * Main entry point for this module
82 **/
83 int landing_target_estimator_main(int argc, char *argv[])
84 {
85 
86  if (argc < 2) {
87  goto exiterr;
88  }
89 
90  if (argc >= 2 && !strcmp(argv[1], "start")) {
91  if (thread_running) {
92  PX4_INFO("already running");
93  /* this is not an error */
94  return 0;
95  }
96 
97  thread_should_exit = false;
98  daemon_task = px4_task_spawn_cmd("landing_target_estimator",
99  SCHED_DEFAULT,
100  SCHED_PRIORITY_DEFAULT,
101  2000,
103  (argv) ? (char *const *)&argv[2] : nullptr);
104  return 0;
105  }
106 
107  if (!strcmp(argv[1], "stop")) {
108  thread_should_exit = true;
109 
110  if (!thread_running) {
111  PX4_WARN("landing_target_estimator not running");
112  }
113 
114  return 0;
115  }
116 
117  if (!strcmp(argv[1], "status")) {
118  if (thread_running) {
119  PX4_INFO("running");
120 
121  } else {
122  PX4_INFO("not started");
123  }
124 
125  return 0;
126  }
127 
128 exiterr:
129  PX4_WARN("usage: landing_target_estimator {start|stop|status}");
130  return 1;
131 }
132 
133 int landing_target_estimator_thread_main(int argc, char *argv[])
134 {
135  PX4_DEBUG("starting");
136 
137  thread_running = true;
138 
140 
141  while (!thread_should_exit) {
142  est.update();
143  px4_usleep(1000000 / landing_target_estimator_UPDATE_RATE_HZ);
144  }
145 
146  PX4_DEBUG("exiting");
147 
148  thread_running = false;
149 
150  return 0;
151 }
152 
153 }
static constexpr uint32_t landing_target_estimator_UPDATE_RATE_HZ
int landing_target_estimator_thread_main(int argc, char *argv[])
Mainloop of daemon.
__EXPORT int landing_target_estimator_main(int argc, char *argv[])
Landing target position estimator app start / stop handling function This makes the module accessible...
Definition: I2C.hpp:51
static bool thread_running
daemon status flag
High-resolution timer with callouts and timekeeping.
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
static int daemon_task
Handle of daemon task / thread.
static bool thread_should_exit
daemon exit flag