如何在 C++ 中实现传递函数的控制系统块?
我想定义一个控制系统块,如下所示:
class ControlSystemBlock
{
public:
ControlSystemBlock()
{
m_dbTimeStep = 0.001; // time between two consequential inputs
}
// this method can be called anytime,
// but the object will assume
// that it was called
// after m_dbTimeStep before the last call
void LoadNewInput(double dbInputValue);
double GetCurrentOutput();
// ...
private:
double m_dbTimeStep;
// ...
};
系统将接收输入,并根据这些输入和用户定义的传递函数,其输出值将及时改变。
例如,假设我想实现传递函数 H(s) = 1 / (s + 2)
。我该怎么做?有什么算法吗?
I want to define a control system block like:
class ControlSystemBlock
{
public:
ControlSystemBlock()
{
m_dbTimeStep = 0.001; // time between two consequential inputs
}
// this method can be called anytime,
// but the object will assume
// that it was called
// after m_dbTimeStep before the last call
void LoadNewInput(double dbInputValue);
double GetCurrentOutput();
// ...
private:
double m_dbTimeStep;
// ...
};
The system will receive inputs, and according to these inputs and user defined transfer-function in it, its output value will change in time.
For instance, assume that I want to implement the transfer function H(s) = 1 / (s + 2)
. How do I do it? Is there any algorithm for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你觉得我的代码怎么样:
ControlSystemBlock.h
ControlSystemBlock.cpp
我刚刚完成它。
我很快就会测试一下。
What do you think of my code:
ControlSystemBlock.h
ControlSystemBlock.cpp
I have just finished it.
I going to test it soon.
让系统接受一个函数(即 C++0x 中的 std::function 或 Boost 中的等效函数)接受一个 double 值并返回一个 double 值,并使用该函数进行实际计算。
然后,用户可以提供任意函数或函子(重载
operator()
的类)来执行您想要的转换函数。或者,使您的函数需要任意转换模板函数,并按值传递函子/函数指针,就像 STL 算法所做的那样。
Make the system accept a function (i.e.
std::function
in C++0x, or the equivalents in Boost) taking a double and returning a double, and use that function to do the actual calculation.The user can then supply any arbitrary function or functor (a class overloading
operator()
) in order to do the transformation function you want.Alternately, make your functions requiring the arbitrary transformation template functions and pass the functor/function pointer in by value, like the STL algorithms do.