Skip to content

Commit 106ee28

Browse files
authoredJun 16, 2019
land_detector initiate cycle immediately
- fixes #12190
1 parent ce784d1 commit 106ee28

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed
 

‎src/modules/land_detector/LandDetector.cpp

+10-20
Original file line numberDiff line numberDiff line change
@@ -57,40 +57,30 @@ LandDetector::LandDetector() :
5757
ScheduledWorkItem(px4::wq_configurations::hp_default),
5858
_cycle_perf(perf_alloc(PC_ELAPSED, "land_detector_cycle"))
5959
{
60+
_landDetected.timestamp = hrt_absolute_time();
61+
_landDetected.freefall = false;
62+
_landDetected.landed = true;
63+
_landDetected.ground_contact = false;
64+
_landDetected.maybe_landed = false;
65+
66+
_p_total_flight_time_high = param_find("LND_FLIGHT_T_HI");
67+
_p_total_flight_time_low = param_find("LND_FLIGHT_T_LO");
6068
}
6169

6270
LandDetector::~LandDetector()
6371
{
6472
perf_free(_cycle_perf);
6573
}
6674

67-
int LandDetector::start()
75+
void LandDetector::start()
6876
{
69-
ScheduleOnInterval(LAND_DETECTOR_UPDATE_INTERVAL, 10000);
70-
71-
return PX4_OK;
77+
ScheduleOnInterval(LAND_DETECTOR_UPDATE_INTERVAL);
7278
}
7379

7480
void LandDetector::Run()
7581
{
7682
perf_begin(_cycle_perf);
7783

78-
if (_object.load() == nullptr) { // not initialized yet
79-
// Advertise the first land detected uORB.
80-
_landDetected.timestamp = hrt_absolute_time();
81-
_landDetected.freefall = false;
82-
_landDetected.landed = true;
83-
_landDetected.ground_contact = false;
84-
_landDetected.maybe_landed = false;
85-
86-
_p_total_flight_time_high = param_find("LND_FLIGHT_T_HI");
87-
_p_total_flight_time_low = param_find("LND_FLIGHT_T_LO");
88-
89-
_check_params(true);
90-
91-
_object.store(this);
92-
}
93-
9484
_check_params(false);
9585
_armingSub.update(&_arming);
9686
_update_topics();

‎src/modules/land_detector/LandDetector.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class LandDetector : public ModuleBase<LandDetector>, px4::ScheduledWorkItem
9696
/**
9797
* Get the work queue going.
9898
*/
99-
int start();
99+
void start();
100100

101101
protected:
102102

‎src/modules/land_detector/land_detector_main.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ int LandDetector::task_spawn(int argc, char *argv[])
6262
{
6363
if (argc < 2) {
6464
print_usage();
65-
return -1;
65+
return PX4_ERROR;
6666
}
6767

68-
LandDetector *obj;
68+
LandDetector *obj = nullptr;
6969

7070
if (strcmp(argv[1], "fixedwing") == 0) {
7171
obj = new FixedwingLandDetector();
@@ -81,28 +81,24 @@ int LandDetector::task_spawn(int argc, char *argv[])
8181

8282
} else {
8383
print_usage("unknown mode");
84-
return -1;
84+
return PX4_ERROR;
8585
}
8686

8787
if (obj == nullptr) {
8888
PX4_ERR("alloc failed");
89-
return -1;
90-
}
91-
92-
int ret = obj->start();
93-
94-
if (ret < 0) {
95-
delete obj;
96-
return ret;
89+
return PX4_ERROR;
9790
}
9891

9992
// Remember current active mode
10093
strncpy(_currentMode, argv[1], sizeof(_currentMode) - 1);
10194
_currentMode[sizeof(_currentMode) - 1] = '\0';
10295

103-
wait_until_running(); // this will wait until _object is set from the cycle method
96+
_object.store(obj);
10497
_task_id = task_id_is_work_queue;
105-
return 0;
98+
99+
obj->start();
100+
101+
return PX4_OK;
106102
}
107103

108104
int LandDetector::print_status()

0 commit comments

Comments
 (0)