From 1671c322380a4ba8f88dd1e7fd7ec5dcf905872d Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Fri, 2 Jun 2017 20:48:59 -0400 Subject: [PATCH] BlockParamExt replace with BlockParam reference types --- src/lib/controllib/block/Block.cpp | 2 + src/lib/controllib/block/BlockParam.cpp | 88 +++++++------------------ src/lib/controllib/block/BlockParam.hpp | 80 +++++++++------------- src/lib/ecl | 2 +- src/modules/ekf2/ekf2_main.cpp | 4 +- 5 files changed, 58 insertions(+), 118 deletions(-) diff --git a/src/lib/controllib/block/Block.cpp b/src/lib/controllib/block/Block.cpp index 16b415463e..291468d28d 100644 --- a/src/lib/controllib/block/Block.cpp +++ b/src/lib/controllib/block/Block.cpp @@ -41,6 +41,8 @@ #include #include +#include + #include #include diff --git a/src/lib/controllib/block/BlockParam.cpp b/src/lib/controllib/block/BlockParam.cpp index 83e9b09c0f..c23f5f17fe 100644 --- a/src/lib/controllib/block/BlockParam.cpp +++ b/src/lib/controllib/block/BlockParam.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Copyright (C) 2012-2017 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,19 +37,16 @@ * Controller library code */ -#include -#include -#include - #include "BlockParam.hpp" +#include + #include namespace control { -BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_prefix) : - _handle(PARAM_INVALID) +BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_prefix) { char fullname[blockNameLengthMax]; @@ -60,7 +57,7 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref char parentName[blockNameLengthMax]; parent->getName(parentName, blockNameLengthMax); - if (!strcmp(name, "")) { + if (strcmp(name, "") == 0) { strncpy(fullname, parentName, blockNameLengthMax); // ensure string is terminated fullname[sizeof(fullname) - 1] = '\0'; @@ -80,81 +77,40 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref _handle = param_find(fullname); if (_handle == PARAM_INVALID) { - printf("error finding param: %s\n", fullname); + PX4_ERR("error finding param: %s\n", fullname); } }; -template -BlockParam::BlockParam(Block *block, const char *name, - bool parent_prefix) : +template <> +BlockParam::BlockParam(Block *block, const char *name, bool parent_prefix) : BlockParamBase(block, name, parent_prefix), _val() { update(); } -template -void BlockParam::set(T val) -{ - _val = val; -} - -template -void BlockParam::update() -{ - if (_handle != PARAM_INVALID) { - param_get(_handle, &_val); - } -} - -template -void BlockParam::commit() -{ - if (_handle != PARAM_INVALID) { param_set(_handle, &_val); } -} - -template -void BlockParam::commit_no_notification() -{ - if (_handle != PARAM_INVALID) { param_set_no_notification(_handle, &_val); } -} - -template -BlockParam::~BlockParam() {}; - -template class __EXPORT BlockParam; -template class __EXPORT BlockParam; - - -template -BlockParamExt::BlockParamExt(Block *block, const char *name, - bool parent_prefix, T &extern_val) : - BlockParam(block, name, parent_prefix), - _extern_val(extern_val) +template <> +BlockParam::BlockParam(Block *block, const char *name, bool parent_prefix) : + BlockParamBase(block, name, parent_prefix), + _val() { update(); } -template -void BlockParamExt::set(T val) +template <> +BlockParam::BlockParam(Block *block, const char *name, bool parent_prefix, int32_t &extern_val) : + BlockParamBase(block, name, parent_prefix), + _val(extern_val) { - this->_val = val; - _extern_val = val; + update(); } -template -void BlockParamExt::update() +template <> +BlockParam::BlockParam(Block *block, const char *name, bool parent_prefix, float &extern_val) : + BlockParamBase(block, name, parent_prefix), + _val(extern_val) { - if (this->_handle != PARAM_INVALID) { - param_get(this->_handle, &this->_val); - _extern_val = this->_val; - } + update(); } -template -BlockParamExt::~BlockParamExt() {}; - -template class __EXPORT BlockParamExt; -template class __EXPORT BlockParamExt; - } // namespace control diff --git a/src/lib/controllib/block/BlockParam.hpp b/src/lib/controllib/block/BlockParam.hpp index b461a7377f..814d394bef 100644 --- a/src/lib/controllib/block/BlockParam.hpp +++ b/src/lib/controllib/block/BlockParam.hpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Copyright (C) 2012-2017 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -43,17 +43,14 @@ #include "Block.hpp" #include -#include // NULL namespace control { class Block; -/** - * A base class for block params that enables traversing linked list. - */ -class __EXPORT BlockParamBase : public ListNode +// A base class for block params that enables traversing linked list. +class BlockParamBase : public ListNode { public: /** @@ -63,70 +60,53 @@ public: */ BlockParamBase(Block *parent, const char *name, bool parent_prefix = true); virtual ~BlockParamBase() {}; + virtual void update() = 0; const char *getName() { return param_name(_handle); } + protected: - param_t _handle; + param_t _handle{PARAM_INVALID}; }; -/** - * Parameters that are tied to blocks for updating and nameing. - */ - +// Parameters that are tied to blocks for updating and naming. template -class BlockParam : public BlockParamBase +class __EXPORT BlockParam : public BlockParamBase { public: - BlockParam(Block *block, const char *name, - bool parent_prefix = true); + BlockParam(Block *block, const char *name, bool parent_prefix = true); + BlockParam(Block *block, const char *name, bool parent_prefix, T &extern_val); + + ~BlockParam() = default; + + // no copy, assignment, move, move assignment BlockParam(const BlockParam &) = delete; BlockParam &operator=(const BlockParam &) = delete; + BlockParam(BlockParam &&) = delete; + BlockParam &operator=(BlockParam &&) = delete; - inline T get() const { return _val; } + T get() const { return _val; } - /** - * Store the parameter value to the parameter storage (@see param_set()) - */ - void commit(); + // Store the parameter value to the parameter storage (@see param_set()) + void commit() { param_set(_handle, &_val); }; - /** - * Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification()) - */ - void commit_no_notification(); + // Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification()) + void commit_no_notification() { param_set_no_notification(_handle, &_val); }; + + void set(T val) { _val = val; }; + void update() override { param_get(_handle, &_val); }; - void set(T val); - void update() override; - virtual ~BlockParam(); protected: T _val; }; typedef BlockParam BlockParamFloat; typedef BlockParam BlockParamInt; +typedef BlockParam BlockParamExtFloat; +typedef BlockParam BlockParamExtInt; - -/** - * Same as BlockParam, but in addition with a pointer to an external field that will be - * set to the value of the parameter. - * (BlockParam should be prefered over this) - */ -template -class BlockParamExt : public BlockParam -{ -public: - BlockParamExt(Block *block, const char *name, - bool parent_prefix, T &extern_val); - BlockParamExt(const BlockParamExt &) = delete; - BlockParamExt &operator=(const BlockParamExt &) = delete; - - void set(T val); - void update() override; - virtual ~BlockParamExt(); -protected: - T &_extern_val; -}; - -typedef BlockParamExt BlockParamExtFloat; -typedef BlockParamExt BlockParamExtInt; +template class __EXPORT BlockParam; +template class __EXPORT BlockParam; +template class __EXPORT BlockParam; +template class __EXPORT BlockParam; } // namespace control diff --git a/src/lib/ecl b/src/lib/ecl index 05c3c46f83..9dee57f9ca 160000 --- a/src/lib/ecl +++ b/src/lib/ecl @@ -1 +1 @@ -Subproject commit 05c3c46f839ef0738c2cb0c643dd40a2d6ef01d8 +Subproject commit 9dee57f9ca5b9665fb9fba051bb20a6a010311c0 diff --git a/src/modules/ekf2/ekf2_main.cpp b/src/modules/ekf2/ekf2_main.cpp index 8f6c36e098..94bdde8190 100644 --- a/src/modules/ekf2/ekf2_main.cpp +++ b/src/modules/ekf2/ekf2_main.cpp @@ -130,8 +130,10 @@ private: static constexpr float _dt_max = 0.02; bool _task_should_exit = false; int _control_task = -1; // task handle for task + bool _replay_mode; // should we use replay data from a log - int _publish_replay_mode; // defines if we should publish replay messages + int32_t _publish_replay_mode; // defines if we should publish replay messages + float _default_ev_pos_noise = 0.05f; // external vision position noise used when an invalid value is supplied float _default_ev_ang_noise = 0.05f; // external vision angle noise used when an invalid value is supplied