控制工具PID

举报
zhangrelay 发表于 2022/03/15 00:52:11 2022/03/15
【摘要】 前一篇: pressbooks.online.ucf.edu/phy2048tjb/chapter/15-5-damped-oscillations/ byjus.com/jee/damped-oscillation/ 阻尼振荡器原理上面两个链接,程序下面一个链接。 ​​​​​​控制工具基础案例 如何控制呢?PID?&nbsp...

前一篇:

pressbooks.online.ucf.edu/phy2048tjb/chapter/15-5-damped-oscillations/

byjus.com/jee/damped-oscillation/

阻尼振荡器原理上面两个链接,程序下面一个链接。

​​​​​​控制工具基础案例

如何控制呢?PID? 


看的如何很懵,正常,后续会把这些点串起来。


  
  1. /**********************************************************************************************************************
  2. This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
  3. Licensed under the BSD-2 license (see LICENSE file in main directory)
  4. **********************************************************************************************************************/
  5. #pragma once
  6. class CustomController : public ct::core::Controller<2, 1>
  7. {
  8. public:
  9. static const size_t state_dim = 2; // two states
  10. static const size_t control_dim = 1; // one control action
  11. CustomController(const ct::core::ControlVector<control_dim>& uff, // feedforward control
  12. const double& kp, // P gain
  13. const double& kd // D gain
  14. )
  15. : uff_(uff), kp_(kp), kd_(kd)
  16. {
  17. }
  18. ~CustomController() {}
  19. CustomController(const CustomController& other) : uff_(other.uff_), kp_(other.kp_), kd_(other.kd_) {}
  20. CustomController* clone() const override
  21. {
  22. return new CustomController(*this); // calls copy constructor
  23. }
  24. void computeControl(const ct::core::StateVector<state_dim>& state,
  25. const double& t,
  26. ct::core::ControlVector<control_dim>& controlAction) override
  27. {
  28. controlAction = uff_; // apply feedforward control
  29. controlAction(0) -= kp_ * state(0) + kd_ * state(1); // add feedback control
  30. }
  31. private:
  32. ct::core::ControlVector<control_dim> uff_;
  33. double kp_;
  34. double kd_;
  35. };


  
  1. /**********************************************************************************************************************
  2. This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
  3. Licensed under the BSD-2 license (see LICENSE file in main directory)
  4. **********************************************************************************************************************/
  5. #include <ct/core/core.h>
  6. #include <ct/core/examples/CustomController.h>
  7. int main(int argc, char** argv)
  8. {
  9. // a damped oscillator has two states, position and velocity
  10. const size_t state_dim = ct::core::SecondOrderSystem::STATE_DIM; // = 2
  11. const size_t control_dim = ct::core::SecondOrderSystem::CONTROL_DIM; // = 1
  12. // create a state
  13. ct::core::StateVector<state_dim> x;
  14. // we initialize it at a point with unit deflection and zero velocity
  15. x(0) = 1.0;
  16. x(1) = 0.0;
  17. // create our oscillator
  18. double w_n = 50;
  19. std::shared_ptr<ct::core::SecondOrderSystem> oscillator(new ct::core::SecondOrderSystem(w_n));
  20. // create our controller
  21. double kp = 10;
  22. double kd = 1;
  23. ct::core::ControlVector<control_dim> uff;
  24. uff << 2.0;
  25. std::shared_ptr<CustomController> controller(new CustomController(uff, kp, kd));
  26. // assign our controller
  27. oscillator->setController(controller);
  28. // create an integrator
  29. ct::core::Integrator<state_dim> integrator(oscillator, ct::core::IntegrationType::RK4);
  30. // simulate 1000 steps
  31. double dt = 0.001;
  32. ct::core::Time t0 = 0.0;
  33. size_t nSteps = 1000;
  34. integrator.integrate_n_steps(x, t0, nSteps, dt);
  35. // print the new state
  36. std::cout << "state after integration: " << x.transpose() << std::endl;
  37. return 0;
  38. }

文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。

原文链接:zhangrelay.blog.csdn.net/article/details/123487993

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。