TR-mbed 1.0
Loading...
Searching...
No Matches
PIDTools.h
Go to the documentation of this file.
1//
2// Created by moksh on 12/24/25.
3//
4
5#ifndef TR_EMBEDDED_PIDTOOLS_H
6#define TR_EMBEDDED_PIDTOOLS_H
8
9enum class TYPE
10{
13};
14
16{
17 public:
18 // constructor
19 PIDTools(DJIMotor *motor, int des_val, TYPE type = TYPE::VELOCITY);
20
21 void init()
22 {
23 if (type == TYPE::VELOCITY)
24 {
25 motor->setSpeed(des_val);
26 current_value = motor->getData(VELOCITY);
27 initial_value = motor->getData(VELOCITY);
28 max_value = current_value;
29 start_settle_time = us_ticker_read();
30 time_in_range = us_ticker_read();
31 start_time = us_ticker_read();
32 }
33 else
34 {
35 motor->setPosition(des_val);
36 current_value = motor->getData(ANGLE);
37 initial_value = motor->getData(ANGLE);
38 max_value = current_value;
39 start_settle_time = us_ticker_read();
40 time_in_range = us_ticker_read();
41 start_time = us_ticker_read();
42 }
43 }
44 void test_velocity();
45 void test_position();
46 std::string run();
47
48
49 private:
50 DJIMotor *motor;
51 int des_val;
52 TYPE type;
53 float current_value;
54 float max_value;
55 static float initial_value;
56 bool print_overshoot = false;
57 bool print_settling_time = false;
58
59 float overshoot;
60 unsigned long rise_time;
61 unsigned long settling_time;
62
63 bool running = true;
64 bool calc_overshoot = true;
65 bool calc_rise_time = true;
66 bool calc_settling_time = true;
67 bool passed_des = false;
68 static uint32_t start_time;
69 uint32_t end_time;
70 static uint32_t start_settle_time;
71 int lower_bound = 0.98 * (des_val - initial_value);
72 int upper_bound = 1.02 * (des_val - initial_value);
73 static uint32_t time_in_range;
74
75 void calculateOvershootVelocity();
76 void calculateOvershootPosition();
77 void calculateSettlingTimeVelocity();
78 void calculateSettlingTimePosition();
79
80 // float calculateOvershootPosition(int des_val);
81 // unsigned long calculateRiseTimePosition(int des_val);
82 // unsigned long calculateSettlingTimePosition(int des_val);
83
84 // float calculateOvershootVelocity(int des_val);
85 // unsigned long calculateRiseTimeVelocity(int des_val);
86 // unsigned long calculateSettlingTimeVelocity(int des_val);
87
88};
89
90#endif //TR_EMBEDDED_PIDTOOLS_H
@ ANGLE
Definition DJIMotor.h:25
TYPE
Definition PIDTools.h:10
@ VELOCITY
@ POSITION
Definition DJIMotor.h:48
void setSpeed(float speed)
Definition DJIMotor.h:113
float getData(motorDataType data)
Definition DJIMotor.cpp:321
void setPosition(float position)
Definition DJIMotor.h:118
Definition PIDTools.h:16
void test_velocity()
Definition PIDTools.cpp:21
void init()
Definition PIDTools.h:21
void test_position()
Definition PIDTools.cpp:46
std::string run()
Definition PIDTools.cpp:71