Browse Source

BlockParamExt replace with BlockParam reference types

sbg
Daniel Agar 8 years ago committed by Lorenz Meier
parent
commit
1671c32238
  1. 2
      src/lib/controllib/block/Block.cpp
  2. 88
      src/lib/controllib/block/BlockParam.cpp
  3. 80
      src/lib/controllib/block/BlockParam.hpp
  4. 2
      src/lib/ecl
  5. 4
      src/modules/ekf2/ekf2_main.cpp

2
src/lib/controllib/block/Block.cpp

@ -41,6 +41,8 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <cstring>
#include <uORB/Subscription.hpp> #include <uORB/Subscription.hpp>
#include <uORB/Publication.hpp> #include <uORB/Publication.hpp>

88
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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -37,19 +37,16 @@
* Controller library code * Controller library code
*/ */
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "BlockParam.hpp" #include "BlockParam.hpp"
#include <cstring>
#include <containers/List.hpp> #include <containers/List.hpp>
namespace control namespace control
{ {
BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_prefix) : BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_prefix)
_handle(PARAM_INVALID)
{ {
char fullname[blockNameLengthMax]; char fullname[blockNameLengthMax];
@ -60,7 +57,7 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref
char parentName[blockNameLengthMax]; char parentName[blockNameLengthMax];
parent->getName(parentName, blockNameLengthMax); parent->getName(parentName, blockNameLengthMax);
if (!strcmp(name, "")) { if (strcmp(name, "") == 0) {
strncpy(fullname, parentName, blockNameLengthMax); strncpy(fullname, parentName, blockNameLengthMax);
// ensure string is terminated // ensure string is terminated
fullname[sizeof(fullname) - 1] = '\0'; fullname[sizeof(fullname) - 1] = '\0';
@ -80,81 +77,40 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref
_handle = param_find(fullname); _handle = param_find(fullname);
if (_handle == PARAM_INVALID) { if (_handle == PARAM_INVALID) {
printf("error finding param: %s\n", fullname); PX4_ERR("error finding param: %s\n", fullname);
} }
}; };
template <class T> template <>
BlockParam<T>::BlockParam(Block *block, const char *name, BlockParam<int32_t>::BlockParam(Block *block, const char *name, bool parent_prefix) :
bool parent_prefix) :
BlockParamBase(block, name, parent_prefix), BlockParamBase(block, name, parent_prefix),
_val() _val()
{ {
update(); update();
} }
template <class T> template <>
void BlockParam<T>::set(T val) BlockParam<float>::BlockParam(Block *block, const char *name, bool parent_prefix) :
{ BlockParamBase(block, name, parent_prefix),
_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)
{ {
update(); update();
} }
template <class T> template <>
void BlockParamExt<T>::set(T val) 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; update();
_extern_val = val;
} }
template <class T> template <>
void BlockParamExt<T>::update() 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) { update();
param_get(this->_handle, &this->_val);
_extern_val = this->_val;
}
} }
template <class T>
BlockParamExt<T>::~BlockParamExt() {};
template class __EXPORT BlockParamExt<float>;
template class __EXPORT BlockParamExt<int>;
} // namespace control } // namespace control

80
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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -43,17 +43,14 @@
#include "Block.hpp" #include "Block.hpp"
#include <containers/List.hpp> #include <containers/List.hpp>
#include <cstddef> // NULL
namespace control namespace control
{ {
class Block; class Block;
/** // A base class for block params that enables traversing linked list.
* A base class for block params that enables traversing linked list. class BlockParamBase : public ListNode<BlockParamBase *>
*/
class __EXPORT BlockParamBase : public ListNode<BlockParamBase *>
{ {
public: public:
/** /**
@ -63,70 +60,53 @@ public:
*/ */
BlockParamBase(Block *parent, const char *name, bool parent_prefix = true); BlockParamBase(Block *parent, const char *name, bool parent_prefix = true);
virtual ~BlockParamBase() {}; virtual ~BlockParamBase() {};
virtual void update() = 0; virtual void update() = 0;
const char *getName() { return param_name(_handle); } const char *getName() { return param_name(_handle); }
protected: protected:
param_t _handle; param_t _handle{PARAM_INVALID};
}; };
/** // Parameters that are tied to blocks for updating and naming.
* Parameters that are tied to blocks for updating and nameing.
*/
template <class T> template <class T>
class BlockParam : public BlockParamBase class __EXPORT BlockParam : public BlockParamBase
{ {
public: public:
BlockParam(Block *block, const char *name, BlockParam(Block *block, const char *name, bool parent_prefix = true);
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(const BlockParam &) = delete;
BlockParam &operator=(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())
* Store the parameter value to the parameter storage (@see param_set()) void commit() { param_set(_handle, &_val); };
*/
void commit();
/** // 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); };
*/
void commit_no_notification(); void set(T val) { _val = val; };
void update() override { param_get(_handle, &_val); };
void set(T val);
void update() override;
virtual ~BlockParam();
protected: protected:
T _val; T _val;
}; };
typedef BlockParam<float> BlockParamFloat; typedef BlockParam<float> BlockParamFloat;
typedef BlockParam<int> BlockParamInt; typedef BlockParam<int> BlockParamInt;
typedef BlockParam<float &> BlockParamExtFloat;
typedef BlockParam<int32_t &> BlockParamExtInt;
template class __EXPORT BlockParam<float>;
/** template class __EXPORT BlockParam<int32_t>;
* Same as BlockParam, but in addition with a pointer to an external field that will be template class __EXPORT BlockParam<float &>;
* set to the value of the parameter. template class __EXPORT BlockParam<int32_t &>;
* (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;
} // namespace control } // namespace control

2
src/lib/ecl

@ -1 +1 @@
Subproject commit 05c3c46f839ef0738c2cb0c643dd40a2d6ef01d8 Subproject commit 9dee57f9ca5b9665fb9fba051bb20a6a010311c0

4
src/modules/ekf2/ekf2_main.cpp

@ -130,8 +130,10 @@ private:
static constexpr float _dt_max = 0.02; static constexpr float _dt_max = 0.02;
bool _task_should_exit = false; bool _task_should_exit = false;
int _control_task = -1; // task handle for task int _control_task = -1; // task handle for task
bool _replay_mode; // should we use replay data from a log 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_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 float _default_ev_ang_noise = 0.05f; // external vision angle noise used when an invalid value is supplied

Loading…
Cancel
Save