Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

land_detector initiate cycle immediately #12196

Merged
merged 1 commit into from
Jun 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions src/modules/land_detector/LandDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,30 @@ LandDetector::LandDetector() :
ScheduledWorkItem(px4::wq_configurations::hp_default),
_cycle_perf(perf_alloc(PC_ELAPSED, "land_detector_cycle"))
{
_landDetected.timestamp = hrt_absolute_time();
_landDetected.freefall = false;
_landDetected.landed = true;
_landDetected.ground_contact = false;
_landDetected.maybe_landed = false;
Copy link
Contributor

@mcsauder mcsauder Jun 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to default initialize these values at the struct definition instead?
(Edit: Except for the timestamp, of course.)


_p_total_flight_time_high = param_find("LND_FLIGHT_T_HI");
_p_total_flight_time_low = param_find("LND_FLIGHT_T_LO");
}

LandDetector::~LandDetector()
{
perf_free(_cycle_perf);
}

int LandDetector::start()
void LandDetector::start()
{
ScheduleOnInterval(LAND_DETECTOR_UPDATE_INTERVAL, 10000);

return PX4_OK;
ScheduleOnInterval(LAND_DETECTOR_UPDATE_INTERVAL);
}

void LandDetector::Run()
{
perf_begin(_cycle_perf);

if (_object.load() == nullptr) { // not initialized yet
// Advertise the first land detected uORB.
_landDetected.timestamp = hrt_absolute_time();
_landDetected.freefall = false;
_landDetected.landed = true;
_landDetected.ground_contact = false;
_landDetected.maybe_landed = false;

_p_total_flight_time_high = param_find("LND_FLIGHT_T_HI");
_p_total_flight_time_low = param_find("LND_FLIGHT_T_LO");

_check_params(true);

_object.store(this);
}

_check_params(false);
_armingSub.update(&_arming);
_update_topics();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/land_detector/LandDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class LandDetector : public ModuleBase<LandDetector>, px4::ScheduledWorkItem
/**
* Get the work queue going.
*/
int start();
void start();

protected:

Expand Down
22 changes: 9 additions & 13 deletions src/modules/land_detector/land_detector_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ int LandDetector::task_spawn(int argc, char *argv[])
{
if (argc < 2) {
print_usage();
return -1;
return PX4_ERROR;
}

LandDetector *obj;
LandDetector *obj = nullptr;

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

} else {
print_usage("unknown mode");
return -1;
return PX4_ERROR;
}

if (obj == nullptr) {
PX4_ERR("alloc failed");
return -1;
}

int ret = obj->start();

if (ret < 0) {
delete obj;
return ret;
return PX4_ERROR;
}

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

wait_until_running(); // this will wait until _object is set from the cycle method
_object.store(obj);
_task_id = task_id_is_work_queue;
return 0;

obj->start();

return PX4_OK;
}

int LandDetector::print_status()
Expand Down