mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 06:13:33 +08:00
BlockParamExt replace with BlockParam reference types
This commit is contained in:
committed by
Lorenz Meier
parent
b03818cd0e
commit
1671c32238
@@ -41,6 +41,8 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/Publication.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
|
||||
@@ -37,19 +37,16 @@
|
||||
* Controller library code
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "BlockParam.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <containers/List.hpp>
|
||||
|
||||
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 <class T>
|
||||
BlockParam<T>::BlockParam(Block *block, const char *name,
|
||||
bool parent_prefix) :
|
||||
template <>
|
||||
BlockParam<int32_t>::BlockParam(Block *block, const char *name, bool parent_prefix) :
|
||||
BlockParamBase(block, name, parent_prefix),
|
||||
_val()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void BlockParam<T>::set(T val)
|
||||
{
|
||||
_val = val;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void BlockParam<T>::update()
|
||||
{
|
||||
if (_handle != PARAM_INVALID) {
|
||||
param_get(_handle, &_val);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void BlockParam<T>::commit()
|
||||
{
|
||||
if (_handle != PARAM_INVALID) { param_set(_handle, &_val); }
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void BlockParam<T>::commit_no_notification()
|
||||
{
|
||||
if (_handle != PARAM_INVALID) { param_set_no_notification(_handle, &_val); }
|
||||
}
|
||||
|
||||
template <class T>
|
||||
BlockParam<T>::~BlockParam() {};
|
||||
|
||||
template class __EXPORT BlockParam<float>;
|
||||
template class __EXPORT BlockParam<int>;
|
||||
|
||||
|
||||
template <class T>
|
||||
BlockParamExt<T>::BlockParamExt(Block *block, const char *name,
|
||||
bool parent_prefix, T &extern_val) :
|
||||
BlockParam<T>(block, name, parent_prefix),
|
||||
_extern_val(extern_val)
|
||||
template <>
|
||||
BlockParam<float>::BlockParam(Block *block, const char *name, bool parent_prefix) :
|
||||
BlockParamBase(block, name, parent_prefix),
|
||||
_val()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void BlockParamExt<T>::set(T val)
|
||||
template <>
|
||||
BlockParam<int32_t &>::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 <class T>
|
||||
void BlockParamExt<T>::update()
|
||||
template <>
|
||||
BlockParam<float &>::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 <class T>
|
||||
BlockParamExt<T>::~BlockParamExt() {};
|
||||
|
||||
template class __EXPORT BlockParamExt<float>;
|
||||
template class __EXPORT BlockParamExt<int>;
|
||||
|
||||
} // namespace control
|
||||
|
||||
@@ -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 <containers/List.hpp>
|
||||
#include <cstddef> // NULL
|
||||
|
||||
namespace control
|
||||
{
|
||||
|
||||
class Block;
|
||||
|
||||
/**
|
||||
* A base class for block params that enables traversing linked list.
|
||||
*/
|
||||
class __EXPORT BlockParamBase : public ListNode<BlockParamBase *>
|
||||
// A base class for block params that enables traversing linked list.
|
||||
class BlockParamBase : public ListNode<BlockParamBase *>
|
||||
{
|
||||
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 T>
|
||||
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<float> BlockParamFloat;
|
||||
typedef BlockParam<int> BlockParamInt;
|
||||
typedef BlockParam<float &> BlockParamExtFloat;
|
||||
typedef BlockParam<int32_t &> 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 T>
|
||||
class BlockParamExt : public BlockParam<T>
|
||||
{
|
||||
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<float> BlockParamExtFloat;
|
||||
typedef BlockParamExt<int> 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
|
||||
|
||||
+1
-1
Submodule src/lib/ecl updated: 05c3c46f83...9dee57f9ca
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user