Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: backdrive backdrive_3
Diff: pid.h
- Revision:
- 0:40cfee72b03a
diff -r 000000000000 -r 40cfee72b03a pid.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pid.h Mon Jul 01 06:44:11 2019 +0000
@@ -0,0 +1,60 @@
+#ifndef PID_H
+#define PID_H
+#include "mbed.h"
+
+enum INDEX{
+ NOW,
+ OLD,
+ TWO_OLD,
+ INDEX_NUMBER,
+};
+
+enum RESULT{
+ P,
+ I,
+ D,
+ OUTPUT,
+ RESULT_NUMBER
+};
+
+namespace pid_constant{
+ const float UPPER_LIMIT = 1.0f;
+ const float LOWER_LIMIT = -1.0f;
+};
+
+class PositionPid{
+ public:
+ void period(float control_cycle);
+ void gain(float kp_, float ki_, float kd_);
+ void reset();
+
+ void cal(float current,float target);
+
+ float getState(int channel);
+
+
+ private:
+ float result[RESULT_NUMBER]; // = {P計算値, I計算値, D計算値, 出力値};
+ float difference[INDEX_NUMBER]; // = {現在の目標値と現在値の差分, 1つ前の目標値と現在地の差分};
+ float distance[INDEX_NUMBER]; // = {現在の位置, 1つ前のい位置};
+ float kp, ki, kd, dt,dt_reciprocal;
+
+};
+
+class SpeedPid{
+ public:
+ void cal(float target_speed, float now_speed);
+
+ float getState(int channel);
+
+ void init(float kp_, float ki_, float kd_, float dt_);
+ private:
+ float dt,
+ gain[RESULT_NUMBER],
+ diffelence[RESULT_NUMBER],
+ result[RESULT_NUMBER];
+
+};
+
+
+#endif