mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-06 07:31:36 +08:00
BlockParam update() and commit() add returns
This commit is contained in:
committed by
Lorenz Meier
parent
633102e7ca
commit
b620da8f01
@@ -32,7 +32,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file Blockparam.cpp
|
* @file BlockParam.cpp
|
||||||
*
|
*
|
||||||
* Controller library code
|
* Controller library code
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -32,17 +32,18 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file BlockParam.h
|
* @file BlockParam.hpp
|
||||||
*
|
*
|
||||||
* Controller library code
|
* Controller library code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <systemlib/param/param.h>
|
|
||||||
|
|
||||||
#include "Block.hpp"
|
#include "Block.hpp"
|
||||||
|
|
||||||
#include <containers/List.hpp>
|
#include <containers/List.hpp>
|
||||||
|
#include <px4_defines.h>
|
||||||
|
#include <systemlib/param/param.h>
|
||||||
|
|
||||||
namespace control
|
namespace control
|
||||||
{
|
{
|
||||||
@@ -59,9 +60,9 @@ public:
|
|||||||
* @param parent_prefix Set to true to include the parent name in the parameter name
|
* @param parent_prefix Set to true to include the parent name in the parameter name
|
||||||
*/
|
*/
|
||||||
BlockParamBase(Block *parent, const char *name, bool parent_prefix = true);
|
BlockParamBase(Block *parent, const char *name, bool parent_prefix = true);
|
||||||
virtual ~BlockParamBase() {};
|
virtual ~BlockParamBase() = default;
|
||||||
|
|
||||||
virtual void update() = 0;
|
virtual bool update() = 0;
|
||||||
const char *getName() { return param_name(_handle); }
|
const char *getName() { return param_name(_handle); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -70,13 +71,13 @@ protected:
|
|||||||
|
|
||||||
// Parameters that are tied to blocks for updating and naming.
|
// Parameters that are tied to blocks for updating and naming.
|
||||||
template <class T>
|
template <class T>
|
||||||
class __EXPORT BlockParam : public BlockParamBase
|
class __EXPORT BlockParam final : public BlockParamBase
|
||||||
{
|
{
|
||||||
public:
|
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(Block *block, const char *name, bool parent_prefix, T &extern_val);
|
||||||
|
|
||||||
~BlockParam() = default;
|
~BlockParam() override = default;
|
||||||
|
|
||||||
// no copy, assignment, move, move assignment
|
// no copy, assignment, move, move assignment
|
||||||
BlockParam(const BlockParam &) = delete;
|
BlockParam(const BlockParam &) = delete;
|
||||||
@@ -87,13 +88,14 @@ public:
|
|||||||
T get() const { return _val; }
|
T get() const { return _val; }
|
||||||
|
|
||||||
// Store the parameter value to the parameter storage (@see param_set())
|
// Store the parameter value to the parameter storage (@see param_set())
|
||||||
void commit() { param_set(_handle, &_val); };
|
bool commit() { return (param_set(_handle, &_val) == PX4_OK); }
|
||||||
|
|
||||||
// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_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); };
|
bool commit_no_notification() { return (param_set_no_notification(_handle, &_val) == PX4_OK); }
|
||||||
|
|
||||||
void set(T val) { _val = val; };
|
void set(T val) { _val = val; }
|
||||||
void update() override { param_get(_handle, &_val); };
|
|
||||||
|
bool update() override { return (param_get(_handle, &_val) == PX4_OK); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
T _val;
|
T _val;
|
||||||
@@ -104,9 +106,4 @@ typedef BlockParam<int32_t> BlockParamInt;
|
|||||||
typedef BlockParam<float &> BlockParamExtFloat;
|
typedef BlockParam<float &> BlockParamExtFloat;
|
||||||
typedef BlockParam<int32_t &> BlockParamExtInt;
|
typedef BlockParam<int32_t &> BlockParamExtInt;
|
||||||
|
|
||||||
template class __EXPORT BlockParam<float>;
|
|
||||||
template class __EXPORT BlockParam<int32_t>;
|
|
||||||
template class __EXPORT BlockParam<float &>;
|
|
||||||
template class __EXPORT BlockParam<int32_t &>;
|
|
||||||
|
|
||||||
} // namespace control
|
} // namespace control
|
||||||
|
|||||||
Reference in New Issue
Block a user