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 <string>
11#include <vector>
12
13#include <nlohmann/json.hpp>
14
23 public:
27 std::string message;
28};
29
31
32
39class PIDGains {
40 public:
42 double kp;
43
45 double ki;
46
48 double kd;
49};
50
52
53
68
70
71
82
84
85
94 public:
96 double gm;
97
99 double pm;
100
102 double msens;
103
105 double act_bw;
106
108 double vel_cl;
109
112
114 double max_KS;
115};
116
118 act_bw, vel_cl, noise_resp, max_KS)
119
120
129 public:
131 double gm_p;
132
134 double pm_p;
135
137 double msens_p;
138
140 double gm_v;
141
143 double pm_v;
144
146 double msens_v;
147
149 double noise_resp;
150
152 double max_KS;
153
155 double bw_p;
156
158 double bw_v;
159
161 double act_st;
162
164 double pos_cl;
165};
166
168 gm_v, pm_v, msens_v, noise_resp, max_KS,
169 bw_p, bw_v, act_st, pos_cl)
170
171
181 public:
183 ControllerGains gains;
184
186 double demanded_bw;
187
192 double demanded_zeta;
193
196};
197
199 demanded_bw, demanded_zeta, state)
200
201
211 public:
213 ControllerGains gains;
214
216 double demanded_st;
217
222 double demanded_zeta;
223
226};
227
229 demanded_st, demanded_zeta, state)
230
231
239class PlantModelResult {
240 public:
242 std::vector<double> numerators;
243
245 std::vector<double> denominators;
246
248 std::string bode_file_path;
249};
250
252 bode_file_path);
253
255 public:
257 std::string bode_file_path;
258};
259
261
272 private:
274 std::string programPath;
275
280 std::string pipeAddress;
281#ifdef _WIN32
283 HANDLE hPipe;
284
286 PROCESS_INFORMATION pi;
287#endif
288#ifdef __linux__
290 pid_t pid;
291
293 int sock;
294#endif
295
299 bool connected;
300
301 public:
303 static const int BUFFER_SIZE = 4096;
304
316 StandaloneAutotuning(const std::string& programPath,
317 const std::string& pipeAddress);
318
327
345 bool start();
346
358 void stop();
359
373 bool connect();
374
383 void disconnect();
384
399 bool send(const nlohmann::json& jsonObj);
400
418 nlohmann::json receive(unsigned int timeoutMilliseconds = 5000);
419
437 nlohmann::json exchange(const nlohmann::json& jsonObj,
438 unsigned int timeoutMilliseconds = 5000);
439
458 ControllerGains auto_tune_velocity_controller(const nlohmann::json& data);
459
478 ControllerGains auto_tune_position_controller(const nlohmann::json& data);
479
500 const nlohmann::json& data);
501
522 const nlohmann::json& data);
523
544 ControllerGains compute_position_controller_gains(const nlohmann::json& data);
545
565 PlantModelResult identify_plant_model(const nlohmann::json& data);
566
582 const nlohmann::json& data);
583};
Holds the gains resulting from the autotuning process.
Definition standalone_autotuning.h:77
ControllerGains gains
The resulting controller gains for velocity and position.
Definition standalone_autotuning.h:80
Holds position and velocity PID gains for a controller.
Definition standalone_autotuning.h:60
PIDGains velocity
PID gains for the velocity controller.
Definition standalone_autotuning.h:66
PIDGains position
PID gains for the position controller.
Definition standalone_autotuning.h:63
Represents the result of a full position autotuning process.
Definition standalone_autotuning.h:198
Represents the result of a full velocity autotuning process.
Definition standalone_autotuning.h:167
Definition standalone_autotuning.h:254
std::string bode_file_path
Full path to the CSV file containing Bode plot data.
Definition standalone_autotuning.h:257
Represents the gains for a PID controller.
Definition standalone_autotuning.h:39
double ki
Integral gain.
Definition standalone_autotuning.h:45
double kd
Derivative gain.
Definition standalone_autotuning.h:48
double kp
Proportional gain.
Definition standalone_autotuning.h:42
Represents the result of a plant model identification process.
Definition standalone_autotuning.h:228
Represents the state of the position autotuning process.
Definition standalone_autotuning.h:117
Represents an error that occurs during standalone autotuning.
Definition standalone_autotuning.h:22
std::string message
Descriptive error message.
Definition standalone_autotuning.h:27
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:364
nlohmann::json exchange(const nlohmann::json &jsonObj, unsigned int timeoutMilliseconds=5000)
Sends a JSON request and receives a JSON response.
Definition standalone_autotuning.cc:325
PlantModelResult identify_plant_model(const nlohmann::json &data)
Identifies the plant model based on the input data.
Definition standalone_autotuning.cc:420
~StandaloneAutotuning()
Destroys the StandaloneAutotuning instance.
Definition standalone_autotuning.cc:34
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:220
nlohmann::json receive(unsigned int timeoutMilliseconds=5000)
Receives a JSON response from the external autotuning program through the named pipe.
Definition standalone_autotuning.cc:248
ControllerGains compute_position_controller_gains(const nlohmann::json &data)
Computes the position controller gains without performing full autotuning.
Definition standalone_autotuning.cc:404
bool connect()
Establishes a connection to the named pipe (Windows) or Unix domain socket (Linux) for communication ...
Definition standalone_autotuning.cc:154
void disconnect()
Disconnects from the named pipe and terminates the communication with the external autotuning program...
Definition standalone_autotuning.cc:207
void stop()
Stops the external autotuning process.
Definition standalone_autotuning.cc:128
StandaloneAutotuning(const std::string &programPath, const std::string &pipeAddress)
Constructs the StandaloneAutotuning instance.
Definition standalone_autotuning.cc:30
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:393
ControllerGains auto_tune_velocity_controller(const nlohmann::json &data)
Performs velocity controller autotuning using external autotuning program.
Definition standalone_autotuning.cc:348
bool start()
Starts the external autotuning program by creating a new process.
Definition standalone_autotuning.cc:36
GeneratePlantBodeFileResult generate_plant_bode_file(const nlohmann::json &data)
Generates the Bode plot CSV file given plant model input data.
Definition standalone_autotuning.cc:441
static const int BUFFER_SIZE
Size of the communication buffer for pipe transfers.
Definition standalone_autotuning.h:303
Represents the state of the velocity autotuning process.
Definition standalone_autotuning.h:93
double vel_cl
Closed-loop velocity value of the system.
Definition standalone_autotuning.h:108
double noise_resp
Noise response in the velocity autotuning process.
Definition standalone_autotuning.h:111
double pm
Phase margin of the velocity system.
Definition standalone_autotuning.h:99
double act_bw
Active bandwidth of the system.
Definition standalone_autotuning.h:105
double max_KS
Maximum allowed gain scale factor.
Definition standalone_autotuning.h:114
double gm
Gain margin of the velocity system.
Definition standalone_autotuning.h:96
double msens
Measurement sensitivity of the velocity system.
Definition standalone_autotuning.h:102
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(PlantModelResult, numerators, denominators, bode_file_path)