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
21 public:
25 std::string message;
26};
27
29
30
37class PIDGains {
38 public:
40 double kp;
41
43 double ki;
44
46 double kd;
47};
48
50
51
59 public:
62
65};
66
68
69
76 public:
79};
80
82
83
92 public:
94 double gm;
95
97 double pm;
98
100 double msens;
101
103 double act_bw;
104
106 double vel_cl;
107
110
112 double max_KS;
113};
114
116 act_bw, vel_cl, noise_resp, max_KS)
117
118
127 public:
129 double gm_p;
130
132 double pm_p;
133
135 double msens_p;
136
138 double gm_v;
139
141 double pm_v;
142
144 double msens_v;
145
147 double noise_resp;
148
150 double max_KS;
151
153 double bw_p;
154
156 double bw_v;
157
159 double act_st;
160
162 double pos_cl;
163};
164
166 gm_v, pm_v, msens_v, noise_resp, max_KS,
167 bw_p, bw_v, act_st, pos_cl)
168
169
179 public:
181 ControllerGains gains;
182
184 double demanded_bw;
185
190 double demanded_zeta;
191
194};
195
197 demanded_bw, demanded_zeta, state)
198
199
209 public:
211 ControllerGains gains;
212
214 double demanded_st;
215
220 double demanded_zeta;
221
224};
225
227 demanded_st, demanded_zeta, state)
228
229
237class PlantModelResult {
238 public:
240 std::vector<double> numerators;
241
243 std::vector<double> denominators;
244
246 std::string bode_file_path;
247};
248
250 bode_file_path);
251
253 public:
255 std::string bode_file_path;
256};
257
259
270 private:
272 std::string programPath;
273
278 std::string pipeAddress;
279#ifdef _WIN32
281 HANDLE hPipe;
282
284 PROCESS_INFORMATION pi;
285#endif
286#ifdef __linux__
288 pid_t pid;
289
291 int sock;
292#endif
293
297 bool connected;
298
299 public:
301 static const int BUFFER_SIZE = 4096;
302
314 StandaloneAutotuning(const std::string& programPath,
315 const std::string& pipeAddress);
316
325
343 bool start();
344
356 void stop();
357
371 bool connect();
372
381 void disconnect();
382
397 bool send(const nlohmann::json& jsonObj);
398
416 nlohmann::json receive(unsigned int timeoutMilliseconds = 5000);
417
435 nlohmann::json exchange(const nlohmann::json& jsonObj,
436 unsigned int timeoutMilliseconds = 5000);
437
456 ControllerGains auto_tune_velocity_controller(const nlohmann::json& data);
457
476 ControllerGains auto_tune_position_controller(const nlohmann::json& data);
477
498 const nlohmann::json& data);
499
520 const nlohmann::json& data);
521
542 ControllerGains compute_position_controller_gains(const nlohmann::json& data);
543
563 PlantModelResult identify_plant_model(const nlohmann::json& data);
564
580 const nlohmann::json& data);
581};
Holds the gains resulting from the autotuning process.
Definition: standalone_autotuning.h:75
ControllerGains gains
The resulting controller gains for velocity and position.
Definition: standalone_autotuning.h:78
Holds position and velocity PID gains for a controller.
Definition: standalone_autotuning.h:58
PIDGains velocity
PID gains for the velocity controller.
Definition: standalone_autotuning.h:64
PIDGains position
PID gains for the position controller.
Definition: standalone_autotuning.h:61
Represents the result of a full position autotuning process.
Definition: standalone_autotuning.h:196
Represents the result of a full velocity autotuning process.
Definition: standalone_autotuning.h:165
Definition: standalone_autotuning.h:252
std::string bode_file_path
Full path to the CSV file containing Bode plot data.
Definition: standalone_autotuning.h:255
Represents the gains for a PID controller.
Definition: standalone_autotuning.h:37
double ki
Integral gain.
Definition: standalone_autotuning.h:43
double kd
Derivative gain.
Definition: standalone_autotuning.h:46
double kp
Proportional gain.
Definition: standalone_autotuning.h:40
Represents the result of a plant model identification process.
Definition: standalone_autotuning.h:226
Represents the state of the position autotuning process.
Definition: standalone_autotuning.h:115
Represents an error that occurs during standalone autotuning.
Definition: standalone_autotuning.h:20
std::string message
Descriptive error message.
Definition: standalone_autotuning.h:25
Manages communication and control for an external autotuning process.
Definition: standalone_autotuning.h:269
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:380
ControllerGains auto_tune_position_controller(const nlohmann::json &data)
Performs position controller autotuning using external autotuning program.
Definition: standalone_autotuning.cc:363
nlohmann::json exchange(const nlohmann::json &jsonObj, unsigned int timeoutMilliseconds=5000)
Sends a JSON request and receives a JSON response.
Definition: standalone_autotuning.cc:324
PlantModelResult identify_plant_model(const nlohmann::json &data)
Identifies the plant model based on the input data.
Definition: standalone_autotuning.cc:419
~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:219
nlohmann::json receive(unsigned int timeoutMilliseconds=5000)
Receives a JSON response from the external autotuning program through the named pipe.
Definition: standalone_autotuning.cc:247
ControllerGains compute_position_controller_gains(const nlohmann::json &data)
Computes the position controller gains without performing full autotuning.
Definition: standalone_autotuning.cc:403
bool connect()
Establishes a connection to the named pipe (Windows) or Unix domain socket (Linux) for communication ...
Definition: standalone_autotuning.cc:153
void disconnect()
Disconnects from the named pipe and terminates the communication with the external autotuning program...
Definition: standalone_autotuning.cc:206
void stop()
Stops the external autotuning process.
Definition: standalone_autotuning.cc:127
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:392
ControllerGains auto_tune_velocity_controller(const nlohmann::json &data)
Performs velocity controller autotuning using external autotuning program.
Definition: standalone_autotuning.cc:347
bool start()
Starts the external autotuning program by creating a new process.
Definition: standalone_autotuning.cc:34
GeneratePlantBodeFileResult generate_plant_bode_file(const nlohmann::json &data)
Generates the Bode plot CSV file given plant model input data.
Definition: standalone_autotuning.cc:440
static const int BUFFER_SIZE
Size of the communication buffer for pipe transfers.
Definition: standalone_autotuning.h:301
Represents the state of the velocity autotuning process.
Definition: standalone_autotuning.h:91
double vel_cl
Closed-loop velocity value of the system.
Definition: standalone_autotuning.h:106
double noise_resp
Noise response in the velocity autotuning process.
Definition: standalone_autotuning.h:109
double pm
Phase margin of the velocity system.
Definition: standalone_autotuning.h:97
double act_bw
Active bandwidth of the system.
Definition: standalone_autotuning.h:103
double max_KS
Maximum allowed gain scale factor.
Definition: standalone_autotuning.h:112
double gm
Gain margin of the velocity system.
Definition: standalone_autotuning.h:94
double msens
Measurement sensitivity of the velocity system.
Definition: standalone_autotuning.h:100
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(PlantModelResult, numerators, denominators, bode_file_path)