Motion Master
Loading...
Searching...
No Matches
standalone_autotuning.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef _WIN32
4#include <windows.h>
5#endif
6#ifdef __linux__
7#include <sys/types.h>
8#endif
9
10#include <nlohmann/json.hpp>
11#include <string>
12
20class PIDGains {
21 public:
23 double kp;
24
26 double ki;
27
29 double kd;
30};
31
33
34
42 public:
45
48};
49
51
52
59 public:
62};
63
65
66
75 public:
77 double gm;
78
80 double pm;
81
83 double msens;
84
86 double act_bw;
87
89 double vel_cl;
90
92 double noise_resp;
93
95 double max_KS;
96};
97
99 act_bw, vel_cl, noise_resp, max_KS)
100
101
110 public:
112 double gm_p;
113
115 double pm_p;
116
118 double msens_p;
119
121 double gm_v;
122
124 double pm_v;
125
127 double msens_v;
128
130 double noise_resp;
131
133 double max_KS;
134
136 double bw_p;
137
139 double bw_v;
140
142 double act_st;
143
145 double pos_cl;
146};
147
149 gm_v, pm_v, msens_v, noise_resp, max_KS,
150 bw_p, bw_v, act_st, pos_cl)
151
152
162 public:
164 ControllerGains gains;
165
167 double demanded_bw;
168
173 double demanded_zeta;
174
177};
178
180 demanded_bw, demanded_zeta, state)
181
182
192 public:
194 ControllerGains gains;
195
197 double demanded_st;
198
203 double demanded_zeta;
204
207};
208
210 demanded_st, demanded_zeta, state)
211
212
220class PlantModelResult {
221 public:
223 std::vector<double> numerators;
224
226 std::vector<double> denominators;
227};
228
240 private:
242 std::string programPath;
243
248 std::string pipeAddress;
249#ifdef _WIN32
251 HANDLE hPipe;
252
254 PROCESS_INFORMATION pi;
255#endif
256#ifdef __linux__
258 pid_t pid;
259
261 int sock;
262#endif
263
267 bool connected;
268
269 public:
271 static const int BUFFER_SIZE = 4096;
272
284 StandaloneAutotuning(const std::string& programPath,
285 const std::string& pipeAddress);
286
295
313 bool start();
314
326 void stop();
327
341 bool connect();
342
351 void disconnect();
352
367 bool send(const nlohmann::json& jsonObj);
368
386 nlohmann::json receive(unsigned int timeoutMilliseconds = 5000);
387
406 ControllerGains auto_tune_velocity_controller(const nlohmann::json& data);
407
426 ControllerGains auto_tune_position_controller(const nlohmann::json& data);
427
448 const nlohmann::json& data);
449
470 const nlohmann::json& data);
471
492 ControllerGains compute_position_controller_gains(const nlohmann::json& data);
493
513 PlantModelResult identify_plant_model(const nlohmann::json& data);
514};
Holds the gains resulting from the autotuning process.
Definition: standalone_autotuning.h:58
ControllerGains gains
The resulting controller gains for velocity and position.
Definition: standalone_autotuning.h:61
Holds position and velocity PID gains for a controller.
Definition: standalone_autotuning.h:41
PIDGains velocity
PID gains for the velocity controller.
Definition: standalone_autotuning.h:47
PIDGains position
PID gains for the position controller.
Definition: standalone_autotuning.h:44
Represents the result of a full position autotuning process.
Definition: standalone_autotuning.h:179
Represents the result of a full velocity autotuning process.
Definition: standalone_autotuning.h:148
Represents the gains for a PID controller.
Definition: standalone_autotuning.h:20
double ki
Integral gain.
Definition: standalone_autotuning.h:26
double kd
Derivative gain.
Definition: standalone_autotuning.h:29
double kp
Proportional gain.
Definition: standalone_autotuning.h:23
Represents the result of a plant model identification process.
Definition: standalone_autotuning.h:209
Represents the state of the position autotuning process.
Definition: standalone_autotuning.h:98
Manages communication and control for an external autotuning process.
Definition: standalone_autotuning.h:239
FullVelocityAutoTuningResult full_auto_tune_velocity_controller(const nlohmann::json &data)
Performs a full velocity controller autotuning sequence using external autotuning program.
Definition: standalone_autotuning.cc:381
ControllerGains auto_tune_position_controller(const nlohmann::json &data)
Performs position controller autotuning using external autotuning program.
Definition: standalone_autotuning.cc:351
PlantModelResult identify_plant_model(const nlohmann::json &data)
Identifies the plant model based on the input data.
Definition: standalone_autotuning.cc:459
~StandaloneAutotuning()
Destroys the StandaloneAutotuning instance.
Definition: standalone_autotuning.cc:32
bool send(const nlohmann::json &jsonObj)
Sends a JSON object to the external autotuning program through the named pipe or Unix domain socket.
Definition: standalone_autotuning.cc:217
nlohmann::json receive(unsigned int timeoutMilliseconds=5000)
Receives a JSON response from the external autotuning program through the named pipe.
Definition: standalone_autotuning.cc:245
ControllerGains compute_position_controller_gains(const nlohmann::json &data)
Computes the position controller gains without performing full autotuning.
Definition: standalone_autotuning.cc:430
bool connect()
Establishes a connection to the named pipe (Windows) or Unix domain socket (Linux) for communication ...
Definition: standalone_autotuning.cc:151
void disconnect()
Disconnects from the named pipe and terminates the communication with the external autotuning program...
Definition: standalone_autotuning.cc:204
void stop()
Stops the external autotuning process.
Definition: standalone_autotuning.cc:125
FullPositionAutoTuningResult full_auto_tune_position_controller(const nlohmann::json &data)
Performs a full position controller autotuning sequence using external autotuning program.
Definition: standalone_autotuning.cc:406
ControllerGains auto_tune_velocity_controller(const nlohmann::json &data)
Performs velocity controller autotuning using external autotuning program.
Definition: standalone_autotuning.cc:322
bool start()
Starts the external autotuning program by creating a new process.
Definition: standalone_autotuning.cc:34
static const int BUFFER_SIZE
Size of the communication buffer for pipe transfers.
Definition: standalone_autotuning.h:271
Represents the state of the velocity autotuning process.
Definition: standalone_autotuning.h:74
double vel_cl
Closed-loop velocity value of the system.
Definition: standalone_autotuning.h:89
double noise_resp
Noise response in the velocity autotuning process.
Definition: standalone_autotuning.h:92
double pm
Phase margin of the velocity system.
Definition: standalone_autotuning.h:80
double act_bw
Active bandwidth of the system.
Definition: standalone_autotuning.h:86
double max_KS
Maximum allowed gain scale factor.
Definition: standalone_autotuning.h:95
double gm
Gain margin of the velocity system.
Definition: standalone_autotuning.h:77
double msens
Measurement sensitivity of the velocity system.
Definition: standalone_autotuning.h:83
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(PlantModelResult, numerators, denominators)