Motion Master
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef LINUX_BUILD
4#include "dl_syscalls.h"
5#endif
6
7#include <chrono>
8#include <cmath>
9#include <deque>
10#include <future>
11#include <list>
12#include <nlohmann/json.hpp>
13#include <numeric>
14#include <semver.hpp>
15#include <string>
16#include <thread>
17#include <zmq.hpp>
18
19#include "cia402_drive.h"
20#include "motion-master.pb.h"
21#include "notifier.h"
23#include "virtual_device.h"
24
25const char* const HARDWARE_DESCRIPTION_FILENAME = ".hardware_description";
26const char* const STACK_INFO_FILENAME = "stack_info.json";
27const char* const STACK_IMAGE_FILENAME = "stack_image.svg";
28const char* const ESI_FILENAME = "SOMANET_CiA_402.xml";
29const char* const CONFIG_FILENAME = "config.csv";
30const char* const PLANT_MODEL_FILENAME = "plant_model.csv";
31const char* const VARIANT_FILENAME = ".variant";
32
33struct PlantModel {
34 std::vector<double> numerator;
35 std::vector<double> denominator;
36 nlohmann::json to_json() {
37 nlohmann::json j;
38 j["numerator"] = numerator;
39 j["denominator"] = denominator;
40 return j;
41 }
42};
43
44enum class ControllerType { kPiP, kPpi };
45
47
48enum class CirculoType {
54};
55
57 kUndefined = 0,
62};
63
65
66#define JSON_TO_DOUBLE(jx) jx.is_number() ? double(jx) : 0.0
67
68// clang-format off
70 uint8_t vel_lp_type = 1; // 0 - disabled, 1 - 1st order, 2 - 2nd order (0x2021, 1)
71 uint32_t vel_lp_fc = 300; // [Hz] (0x2021, 2)
72 uint8_t pos_lp_type = 1; // 0 - disabled, 1 - 1st order, 2 - 2nd order (0x2022, 1)
73 uint32_t pos_lp_fc = 300; // [Hz] (0x2022, 2)
74 bool notch_en = true; // Enabled / disabled (0x2023, 1)
75 uint16_t notch_fw = 10; // [Hz] (0x2023, 3)
76 uint16_t notch_fc = 1000; // [Hz] (0x2023, 2)
77 int16_t vel_ff_gain = 0; // Permill, 0 - disabled (0x2015, 1)
78 uint16_t vel_ff_fc = 1000; // [Hz] (0x2015, 2)
79 int32_t L = 200; // Inductance, [μH] (0x2003, 4)
80 int32_t R = 300000; // Resistance, [μOhm] (0x2003, 3)
81 uint32_t vdc = 48000; // DC voltage, [mV] (0x6079, 0)
82 double current_ratio = 16384; // ADC conversion factor, [mA / inc] (from BSP file)
83 double tc_kp = 2500; // kp gain from FW v4.x.x, [-] (0x2010, 1)
84 double tc_ki = 40000; // ki gain from FW v4.x.x, [-] (0x2010, 2)
85 uint8_t switch_F = 0; // Switching frequency: 0 - 16kHz, 1 - 32kHz, 2 - 64kHz (0x2010, 9)
86 uint16_t tc_st = 1000; // Torque controller settling time, FW v5.x.x, [us] (0x2010, 10)
87 uint16_t tc_damping = 2000; // Torque controller damping ratio, FW v5.x.x, [permill] (0x2010, 11)
88 std::string software_version = "v4.4.1"; // FW version
89 unsigned int rated_torque; // Motor rated torque, [mNm]
90 double max_vel_noise; // Max value of the pre-recorded encoder noise, [RPM]
91 nlohmann::json to_json() {
92 nlohmann::json j;
93 j["vel_lp_type"] = vel_lp_type;
94 j["vel_lp_fc"] = vel_lp_fc;
95 j["pos_lp_type"] = pos_lp_type;
96 j["pos_lp_fc"] = pos_lp_fc;
97 j["notch_en"] = notch_en;
98 j["notch_fw"] = notch_fw;
99 j["notch_fc"] = notch_fc;
100 j["vel_ff_gain"] = vel_ff_gain;
101 j["vel_ff_fc"] = vel_ff_fc;
102 j["L"] = L;
103 j["R"] = R;
104 j["vdc"] = vdc;
105 j["current_ratio"] = current_ratio;
106 j["tc_kp"] = tc_kp;
107 j["tc_ki"] = tc_ki;
108 j["switch_F"] = switch_F;
109 j["tc_st"] = tc_st;
110 j["tc_damping"] = tc_damping;
111 j["software_version"] = software_version;
112 j["rated_torque"] = rated_torque;
113 j["max_vel_noise"] = max_vel_noise;
114 return j;
115 }
117// clang-format on
118
119typedef struct SystemParametersClass {
120 double time_step = 0.001;
121 uint32_t nominal_torque = 0;
122 uint32_t max_torque_mnm_ = 0;
125
126typedef struct TuningParametersClass {
127 // Chirp parameters
128 double duration_seconds = 5.0;
129 uint16_t torque_amplitude = 500;
130 double start_frequency = 3.0;
131 double end_frequency = 60.0;
132 double cutoff_frequency = 30.0;
133
134 // Position auto-tuning parameters
135 ControllerType controller_type = ControllerType::kPpi;
136 double settling_time = 0.2;
137 double position_damping = 2.0;
138 int16_t alpha_mult = 1;
139 uint8_t order = 4;
140
141 // Velocity auto-tuning parameters
143 float velocity_damping = 0.7f;
144
145 // Tuning sharpness limiter (nominal torque * warn_torque_const)
146 double warn_torque_const = 3.0;
147
148 // Position auto-tuning optimization boundaries
149 double lb = 2.0;
150 double ub = 314.0;
152
154
155typedef enum MotionMasterWarning : unsigned int {
160
161const std::map<MotionMasterWarning, std::string>
163 {WAR_NONE, "No warning!"},
165 "Slave profile: The amplitude is outside of the configured limits - "
166 "using a limit value as the new amplitude!"},
167 {WAR_INTERNAL_LIMIT_REACHED, "Internal limit reached!"}};
168
169const std::map<int32_t, std::string> slave_error_map_ = {
170 {0x2110, "Short circuit/earth leakage (input)"},
171 {0x2120, "Earth leakage (input)"},
172 {0x2121, "Earth leakage phase L1"},
173 {0x2122, "Earth leakage phase L2"},
174 {0x2123, "Earth leakage phase L3"},
175 {0x2130, "Short circuit (input)"},
176 {0x2131, "Short circuit phases L1-L2"},
177 {0x2132, "Short circuit phases L2-L3"},
178 {0x2133, "Short circuit phases L3-L1"},
179 {0x2211, "Internal current no.1"},
180 {0x2212, "Internal current no.2"},
181 {0x2213, "Over-current in ramp function"},
182 {0x2214, "Over-current in the sequence"},
183 {0x2220, "Continuous over current (device internal)"},
184 {0x2221, "Continuous over current no.1"},
185 {0x2222, "Continuous over current no.2"},
186 {0x2230, "Short circuit/earth leakage (device internal)"},
187 {0x2240, "Earth leakage (device internal)"},
188 {0x2250, "Short circuit (device internal)"},
189 {0x2310, "Continuous over current"},
190 {0x2311, "Continuous over current no.1"},
191 {0x2312, "Continuous over current no.2"},
192 {0x2320, "Short circuit/earth leakage (motor-side)"},
193 {0x2330, "Earth leakage (motor-side)"},
194 {0x2331, "Earth leakage phase U"},
195 {0x2332, "Earth leakage phase V"},
196 {0x2333, "Earth leakage phase W"},
197 {0x2340, "Short circuit (motor-side)"},
198 {0x2341, "Short circuit phases U-V"},
199 {0x2342, "Earth leakage phase V-W"},
200 {0x2343, "Earth leakage phase W-U"},
201 {0x2350, "Load level fault (I2t, thermal state)"},
202 {0x2351, "Load level warning (I2t, thermal state)"},
203 {0x3110, "Mains overvoltage"},
204 {0x3111, "Mains overvoltage phase L1"},
205 {0x3112, "Mains overvoltage phase L2"},
206 {0x3113, "Mains overvoltage phase L3"},
207 {0x3120, "Mains undervoltage"},
208 {0x3121, "Mains undervoltage phase L1"},
209 {0x3122, "Mains undervoltage phase L2"},
210 {0x3123, "Mains undervoltage phase L3"},
211 {0x3130, "Phase failure"},
212 {0x3131, "Phase failure L1"},
213 {0x3132, "Phase failure L2"},
214 {0x3133, "Phase failure L3"},
215 {0x3134, "Phase sequence"},
216 {0x3140, "Mains frequency"},
217 {0x3141, "Mains frequency too great"},
218 {0x3142, "Mains frequency too small"},
219 {0x3210, "DC link overvoltage"},
220 {0x3211, "Overvoltage no. 1"},
221 {0x3212, "Overvoltage no. 2"},
222 {0x3220, "DC link undervoltage"},
223 {0x3221, "Undervoltage no. 1"},
224 {0x3222, "Undervoltage no. 2"},
225 {0x3230, "Load error"},
226 {0x3310, "Output overvoltage"},
227 {0x3311, "Output overvoltage phase U"},
228 {0x3312, "Output overvoltage phase V"},
229 {0x3313, "Output overvoltage phase W"},
230 {0x3320, "Armature circuit"},
231 {0x3321, "Armature circuit interrupted"},
232 {0x3330, "Field circuit"},
233 {0x3331, "Field circuit interrupted"},
234 {0x4110, "Excess ambient temperature"},
235 {0x4120, "Too low ambient temperature"},
236 {0x4130, "Temperature supply air"},
237 {0x4140, "Temperature air outlet"},
238 {0x4210, "Excess temperature device"},
239 {0x4220, "Too low temperature device"},
240 {0x4300, "Temperature drive"},
241 {0x4310, "Excess temperature drive"},
242 {0x4320, "Too low temperature drive"},
243 {0x4400, "Temperature supply"},
244 {0x4410, "Excess temperature supply"},
245 {0x4420, "Too low temperature supply"},
246 {0x5100, "Supply"},
247 {0x5110, "Supply low voltage"},
248 {0x5111, "U1 = supply ±15V"},
249 {0x5112, "U2 = supply +24 V"},
250 {0x5113, "U3 = supply +5 V"},
251 {0x5114, "U4 = manufacturer-specific"},
252 {0x5115, "U5 = manufacturer-specific"},
253 {0x5116, "U6 = manufacturer-specific"},
254 {0x5117, "U7 = manufacturer-specific"},
255 {0x5118, "U8 = manufacturer-specific"},
256 {0x5119, "U9 = manufacturer-specific"},
257 {0x5120, "Supply intermediate circuit"},
258 {0x5200, "Control"},
259 {0x5210, "Measurement circuit"},
260 {0x5220, "Computing circuit"},
261 {0x5300, "Operating unit"},
262 {0x5400, "Power section"},
263 {0x5410, "Output stages"},
264 {0x5420, "Chopper"},
265 {0x5430, "Input stages"},
266 {0x5440, "Contacts"},
267 {0x5441, "Contact 1 = manufacturer-specific"},
268 {0x5442, "Contact 2 = manufacturer-specific"},
269 {0x5443, "Contact 3 = manufacturer-specific"},
270 {0x5444, "Contact 4 = manufacturer-specific"},
271 {0x5445, "Contact 5 = manufacturer-specific"},
272 {0x5450, "Fuses"},
273 {0x5451, "S1 = l1"},
274 {0x5452, "S2 = l2"},
275 {0x5453, "S3 = l3"},
276 {0x5454, "S4 = manufacturer-specific"},
277 {0x5455, "S5 = manufacturer-specific"},
278 {0x5456, "S6 = manufacturer-specific"},
279 {0x5457, "S7 = manufacturer-specific"},
280 {0x5458, "S8 = manufacturer-specific"},
281 {0x5459, "S9 = manufacturer-specific"},
282 {0x5500, "Hardware memory"},
283 {0x5510, "RAM"},
284 {0x5520, "ROM/EPROM"},
285 {0x5530, "EEPROM"},
286 {0x6010, "Software reset (watchdog)"},
287 {0x6301, "to 630Fh Data record no. 1 to no. 15"},
288 {0x6310, "Loss of parameters"},
289 {0x6320, "Parameter error"},
290 {0x7100, "Power"},
291 {0x7110, "Brake chopper"},
292 {0x7111, "Failure brake chopper"},
293 {0x7112, "Over current brake chopper"},
294 {0x7113, "Protective circuit brake chopper"},
295 {0x7120, "Motor"},
296 {0x7121, "Motor blocked"},
297 {0x7122, "Motor error or commutation malfunction."},
298 {0x7123, "Motor tilted"},
299 {0x7200, "Measurement circuit"},
300 {0x7300, "Sensor"},
301 {0x7301, "Tacho fault"},
302 {0x7302, "Tacho wrong polarity"},
303 {0x7303, "Resolver 1 fault"},
304 {0x7304, "Resolver 2 fault"},
305 {0x7305, "Incremental encoder 1 fault"},
306 {0x7306, "Incremental encoder 2 fault"},
307 {0x7307, "Incremental encoder 3 fault"},
308 {0x7310, "Speed"},
309 {0x7320, "Position"},
310 {0x7400, "Computation circuit"},
311 {0x7500, "Communication"},
312 {0x7510, "Serial interface no. 1"},
313 {0x7520, "Serial interface no. 2"},
314 {0x7600, "Data storage (external)"},
315 {0x8300, "Torque control"},
316 {0x8311, "Excess torque"},
317 {0x8312, "Difficult start up"},
318 {0x8313, "Standstill torque"},
319 {0x8321, "Insufficient torque"},
320 {0x8331, "Torque fault"},
321 {0x8400, "Velocity speed controller"},
322 {0x8500, "Position controller"},
323 {0x8600, "Positioning controller"},
324 {0x8611, "Following error"},
325 {0x8612, "Reference limit"},
326 {0x8700, "Sync controller"},
327 {0x8800, "Winding controller"},
328 {0x8900, "Process data monitoring"},
329 {0x8A00, "Control"},
330 {0xF001, "Deceleration"},
331 {0xF002, "Sub-synchronous run"},
332 {0xF003, "Stroke operation"},
333 {0xF004, "Control"},
334 {0xFF03, "Warning - Excess temperature device"},
335 {0xFF04, "Pull brake voltage higher than measured on DC bus"},
336 {0xFF05, "Hold brake voltage higher than measured on DC bus"},
337 {0xFF06, "Open circuit: High FET in phase A"},
338 {0xFF07, "Open circuit: Low FET in phase A"},
339 {0xFF08, "Open circuit: High FET in phase B"},
340 {0xFF09, "Open circuit: Low FET in phase B"},
341 {0xFF0A, "Open circuit: High FET in phase C"},
342 {0xFF0B, "Open circuit: Low FET in phase C"},
343 {0xFF0C, "Commutation offset is missing"}};
344
345const std::map<int32_t, std::map<int32_t, int32_t>>
347 {8500, {{01, 20480}, {02, 24576}, {03, 16384}}},
348 {8501, {{01, 8192}, {02, 8192}, {03, 16384}}},
349 {8502, {{01, 20480}, {02, 24576}, {03, 16384}}},
350 {8503, {{01, 8192}, {02, 8192}, {03, 16384}}},
351 {8504, {{01, 20480}, {02, 24576}, {03, 16384}}},
352 {8505, {{01, 8192}, {02, 8192}, {03, 16384}}},
353 {9500, {{00, 32768}, {01, 32768}, {02, 32768}}},
354 {9501, {{01, 81920}, {02, 81920}}},
355 {9502, {{01, 16384}}},
356 {9506, {{01, 32768}}},
357 {9507, {{01, 81920}}},
358 {9508, {{01, 16384}}},
359 {9600, {{01, 32768}}},
360 {9601, {{01, 81920}}},
361 {9602, {{01, 16384}}},
362 {9606, {{01, 32768}}},
363 {9607, {{01, 81920}}},
364 {9608, {{01, 16384}}}};
365
366const std::map<int32_t, std::map<int32_t, int32_t>>
368 {8500, {{01, 40960}, {02, 49152}, {03, 32768}}},
369 {8501, {{01, 16384}, {02, 16384}, {03, 16384}}},
370 {8502, {{01, 40960}, {02, 49152}, {03, 32768}}},
371 {8503, {{01, 16384}, {02, 16384}, {03, 16384}}},
372 {8504, {{01, 40960}, {02, 49152}, {03, 32768}}},
373 {8505, {{01, 16384}, {02, 16384}, {03, 16384}}},
374 {9500, {{00, 32768}, {01, 32768}, {02, 32768}}},
375 {9501, {{01, 81920}, {02, 81920}}},
376 {9502, {{01, 16384}}},
377 {9506, {{01, 32768}}},
378 {9507, {{01, 81920}}},
379 {9508, {{01, 16384}}},
380 {9600, {{01, 32768}}},
381 {9601, {{01, 81920}}},
382 {9602, {{01, 16384}}},
383 {9606, {{01, 32768}}},
384 {9607, {{01, 81920}}},
385 {9608, {{01, 16384}}}};
386
388 kNotFound = 0x00008001,
389 kAccessDenied = 0x00008002,
390 kDiskFull = 0x00008003,
391 kIllegal = 0x00008004,
392 kPacketNumberWrong = 0x00008005,
393 kAlreadyExists = 0x00008006,
394 kNoUser = 0x00008007,
395 kBootstrapOnly = 0x00008008,
396 kNotBootstrap = 0x00008009,
397 kNoRights = 0x0000800a,
398 kProgramError = 0x0000800b
399};
400
409
417std::string get_slave_error_message(int32_t error_code);
418
426void send(zmq::socket_t& socket, const std::string& connection_id,
427 const motionmaster::MotionMasterMessage& message);
428
429#ifdef __linux__
435int32_t set_default_thread_priority();
436
448int32_t set_max_thread_priority();
449#endif
450
459std::string etg1004_unit_string(uint32_t etg1004_unit_value);
460
469int32_t get_pdo_id(uint16_t index, uint8_t subindex,
470 std::map<int32_t, int32_t>& pdo_position_map);
471
477const std::string current_date_time();
478
479#ifdef __linux__
488std::string execute_system_command(const char* cmd);
489#endif
490
499bool abs_compare(float a, float b);
500
509template <typename T>
510bool opposite_signs(const T& a, const T& b) {
511 return ((a ^ b) >> (sizeof(T) * 8 - 1));
512}
513
519void interruptable_wait(size_t seconds);
520
530int32_t wrap_target_position(int32_t target, int32_t max_limit,
531 int32_t min_limit);
532
539
545void unregister_sync_signal(uint32_t signal_id);
546
554uint64_t wait_for_sync_signal(uint32_t signal_id);
562uint64_t wait_for_signal(int signal_fd);
563uint64_t wait_for_signal(uint32_t signal_id);
564
574std::vector<double> linspace(double lb, double ub, size_t n);
575
585
595 const ControllerGains& gains);
596
606 const ControllerGains& gains);
607
618bool check_gains(Cia402Drive& cia402_drive);
619
628bool string_ends_with(const std::string& value, const std::string& ending);
629
637std::vector<uint8_t> read_file_content(const std::string& path);
638
645void set_csv_configuration(VirtualDevice* virtual_device,
646 const std::vector<uint8_t>& csv_data);
647
658uint8_t calculate_crc(const std::vector<uint8_t>& data);
659
668uint32_t random_uint32(uint32_t min = 0, uint32_t max = UINT32_MAX);
669
675unsigned char random_char();
676
684std::string generate_uuid(size_t length);
685
693int32_t limit_int32_target(int64_t target);
694
700std::string run_env_info();
701
710bool validate_sii_data(const std::vector<uint8_t>& content, uint32_t device_id);
711
719bool file_exists(const std::string& path);
720
728std::string string_bytes_to_hex_array_string(const std::string& bytes);
729
739std::string get_firmware_version_string(Cia402Drive& cia402_drive);
740
750semver::version get_firmware_version(Cia402Drive& cia402_drive);
751
761
774 Cia402Drive& cia402_drive);
775
785 ControllerGains gains, uint32_t singleturn_resolution);
786
794CirculoType get_circulo_type(int32_t hardware_id);
795
805bool is_fw_based_on_v5(Cia402Drive& cia402_drive);
806
815bool is_fw_at_least(Cia402Drive& cia402_drive, const std::string& version);
816
825std::vector<uint8_t> zip(const std::string& file_name,
826 std::vector<uint8_t> data);
827
837std::vector<uint8_t> unzip(const std::vector<uint8_t>& data);
838
847uint32_t generate_od_entry_map_key(uint16_t index, uint8_t subindex);
848
857std::list<std::string> get_file_parts(std::list<std::string> file_list,
858 const std::string& file_name);
859
869 uint8_t encoder_ordinal);
870
878template <typename T>
879int32_t find_local_min_index_from_right(std::vector<T>& x) {
880 T min_value = x[x.size() - 1];
881
882 for (int32_t i = x.size() - 2; i >= 0; i--) {
883 if (x[i] <= min_value) {
884 min_value = x[i];
885 } else {
886 return i + 1;
887 }
888 }
889
890 return 1;
891}
892
900template <typename T>
901double compute_mean(const std::vector<T>& numbers) {
902 if (numbers.empty()) {
903 return 0.0;
904 }
905
906 return std::accumulate(numbers.begin(), numbers.end(), 0.0) / numbers.size();
907}
908
916template <typename T>
917double compute_standard_deviation(const std::vector<T>& numbers) {
918 if (numbers.empty()) {
919 return 0.0;
920 }
921
922 double mean = compute_mean(numbers);
923
924 std::vector<double> tmp(numbers.size());
925 std::transform(numbers.begin(), numbers.end(), tmp.begin(),
926 [mean](double x) { return x - mean; });
927
928 double sq_sum = std::inner_product(tmp.begin(), tmp.end(), tmp.begin(), 0.0);
929 return std::sqrt(sq_sum / (numbers.size() - 1));
930}
931
941template <typename T>
942double compute_section_mean(const std::vector<T>& numbers, size_t start,
943 size_t end) {
944 std::vector<T> section(numbers.begin() + start, numbers.begin() + end);
945
946 if (section.empty()) {
947 return 0.0;
948 }
949
950 return std::accumulate(section.begin(), section.end(), 0.0) / section.size();
951}
952
961template <typename T>
962std::vector<T> erase_edge_elements(std::vector<T> v, size_t length) {
963 v.erase(v.begin(), v.begin() + length);
964 v.erase(v.end() - length, v.end());
965 return v;
966}
967
975template <typename R>
976bool is_future_done(std::future<R> const& f) {
977 try {
978 return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
979 } catch (std::future_error& e) {
980 return true; // The future is not running since there is an error
981 }
982}
983
991template <typename T>
992auto to_integral(T e) {
993 return static_cast<std::underlying_type_t<T>>(e);
994}
995
1004template <typename T>
1005static std::vector<T> diff(std::vector<T> vector) {
1006 std::vector<T> result;
1007 result.reserve(vector.size() - 1);
1008
1009 for (size_t i = 1; i < vector.size(); i++) {
1010 result.push_back(vector[i] - vector[i - 1]);
1011 }
1012
1013 return result;
1014}
1015
1019template <typename... Args>
1020std::string string_format(const std::string& format, Args... args) {
1021 int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) +
1022 1; // Extra space for '\0'
1023 if (size_s <= 0) {
1024 throw std::runtime_error("Error during formatting.");
1025 }
1026 auto size = static_cast<size_t>(size_s);
1027 std::unique_ptr<char[]> buf(new char[size]);
1028 std::snprintf(buf.get(), size, format.c_str(), args...);
1029 return std::string(buf.get(),
1030 buf.get() + size - 1); // We don't want the '\0' inside
1031}
1032
1043 public:
1044 LowPassFilter(uint16_t cutoff_frequency, double ts);
1045
1046 double filter(double value);
1047
1048 private:
1049 std::deque<double> input_data_;
1050 std::deque<double> output_data_;
1051 double fc_, a0_, a1_, a2_, b0_, b1_, b2_;
1052};
1053
1063 public:
1064 HighPassFilter(uint16_t cutoff_frequency, double ts);
1065
1066 double filter(double value);
1067
1068 private:
1069 std::deque<double> input_data_;
1070 std::deque<double> output_data_;
1071 double fc_, a0_, a1_, a2_, a3_, a4_, b0_, b1_, b2_, b3_, b4_;
1072};
1073
1075
1076bool compareStringsCaseInsensitive(const std::string& s1,
1077 const std::string& s2);
Definition: cia402_drive.h:48
Holds position and velocity PID gains for a controller.
Definition: standalone_autotuning.h:41
This is a fourth order filter with binomial coefficients.
Definition: util.h:1062
double filter(double value)
Definition: util.cc:1714
This filter is second order with binomial coefficients, damping ratio xi = 1.
Definition: util.h:1042
double filter(double value)
Definition: util.cc:1680
Definition: virtual_device.h:20
uint8_t * value
Definition: co_dictionary.h:9
uint16_t index
Definition: co_dictionary.h:0
uint16_t notch_fw
Definition: util.h:75
int32_t R
Definition: util.h:80
int32_t L
Definition: util.h:79
nlohmann::json to_json()
Definition: util.h:91
double tc_kp
Definition: util.h:83
uint16_t notch_fc
Definition: util.h:76
int16_t vel_ff_gain
Definition: util.h:77
uint16_t tc_st
Definition: util.h:86
uint16_t tc_damping
Definition: util.h:87
double max_vel_noise
Definition: util.h:90
uint32_t vdc
Definition: util.h:81
uint8_t vel_lp_type
Definition: util.h:70
uint8_t switch_F
Definition: util.h:85
uint32_t vel_lp_fc
Definition: util.h:71
bool notch_en
Definition: util.h:74
double tc_ki
Definition: util.h:84
uint8_t pos_lp_type
Definition: util.h:72
uint32_t pos_lp_fc
Definition: util.h:73
std::string software_version
Definition: util.h:88
unsigned int rated_torque
Definition: util.h:89
uint16_t vel_ff_fc
Definition: util.h:78
double current_ratio
Definition: util.h:82
Definition: util.h:33
std::vector< double > denominator
Definition: util.h:35
nlohmann::json to_json()
Definition: util.h:36
std::vector< double > numerator
Definition: util.h:34
Definition: util.h:119
uint32_t nominal_torque
Definition: util.h:121
double time_step
Definition: util.h:120
uint32_t max_torque_mnm_
Definition: util.h:122
uint32_t singleturn_resolution
Definition: util.h:123
Definition: util.h:126
int16_t alpha_mult
Definition: util.h:138
double end_frequency
Definition: util.h:131
double warn_torque_const
Definition: util.h:146
double cutoff_frequency
Definition: util.h:132
double lb
Definition: util.h:149
uint16_t torque_amplitude
Definition: util.h:129
float velocity_loop_bandwidth
Definition: util.h:142
float velocity_damping
Definition: util.h:143
double start_frequency
Definition: util.h:130
ControllerType controller_type
Definition: util.h:135
double duration_seconds
Definition: util.h:128
double position_damping
Definition: util.h:137
double ub
Definition: util.h:150
double settling_time
Definition: util.h:136
uint8_t order
Definition: util.h:139
std::vector< uint8_t > unzip(const std::vector< uint8_t > &data)
Unzip data containing a single file.
Definition: util.cc:1531
const std::map< int32_t, std::string > slave_error_map_
Definition: util.h:169
ControllerGains get_position_controller_gains(Cia402Drive &cia402_drive)
Get the current position controller gains of a drive.
Definition: util.cc:330
const char *const HARDWARE_DESCRIPTION_FILENAME
Definition: util.h:25
double compute_section_mean(const std::vector< T > &numbers, size_t start, size_t end)
Compute the mean of a section of a given vector of integers.
Definition: util.h:942
ControllerGains convert_auto_tuning_controller_gains(ControllerGains gains, uint32_t singleturn_resolution)
Convert gains to inc pos values and rpm velocity values.
Definition: util.cc:1409
const std::map< int32_t, std::map< int32_t, int32_t > > adc_current_ratio_fw_v4_4_2_map
Definition: util.h:367
void send(zmq::socket_t &socket, const std::string &connection_id, const motionmaster::MotionMasterMessage &message)
Send regular Google Protocol Buffers message over ZeroMQ.
Definition: util.cc:65
uint64_t wait_for_signal(int signal_fd)
Wait for the system signal.
std::string controllerTypeToString(ControllerType ct)
Definition: util.cc:200
uint32_t register_sync_signal()
Register a thread sync signal.
bool string_ends_with(const std::string &value, const std::string &ending)
Check if a string ends with another string.
Definition: util.cc:485
const std::map< int32_t, std::map< int32_t, int32_t > > adc_current_ratio_fw_v4_4_1_map
Definition: util.h:346
std::string generate_uuid(size_t length)
Generate a UUID of a custom length.
Definition: util.cc:662
bool set_velocity_controller_gains(Cia402Drive &cia402_drive, const ControllerGains &gains)
Set the velocity controller gains.
Definition: util.cc:432
semver::version get_firmware_version(Cia402Drive &cia402_drive)
Get the (semver) version of the used firmware.
Definition: util.cc:945
std::string get_slave_error_message(int32_t error_code)
Return the appropriate error message.
Definition: util.cc:57
int32_t find_local_min_index_from_right(std::vector< T > &x)
Find a local minimum (from right) in the supplied vector.
Definition: util.h:879
struct AutoTuningDriveConfigurationClass AutoTuningDriveConfiguration
const char *const STACK_INFO_FILENAME
Definition: util.h:26
bool validate_sii_data(const std::vector< uint8_t > &content, uint32_t device_id)
Validate an SII data before writing.
double compute_mean(const std::vector< T > &numbers)
Compute mean given a vector of numbers.
Definition: util.h:901
bool opposite_signs(const T &a, const T &b)
Check if parameters have opposite signs.
Definition: util.h:510
bool get_plant_model_from_flash(Cia402Drive &cia402_drive, PlantModel *m)
Get the plant model from the flash memory of the device.
Definition: util.cc:992
const char *const ESI_FILENAME
Definition: util.h:28
const std::map< MotionMasterWarning, std::string > motion_master_warning_to_message_map_
Definition: util.h:162
void unregister_sync_signal(uint32_t signal_id)
Unregister a thread sync signal.
int32_t limit_int32_target(int64_t target)
Limit a target to integer 32 if necessary.
Definition: util.cc:674
std::string run_env_info()
Get all sorts of run environment information.
Definition: util.cc:694
const char *const CONFIG_FILENAME
Definition: util.h:29
bool compareStringsCaseInsensitive(const std::string &s1, const std::string &s2)
Definition: util.cc:1734
int32_t wrap_target_position(int32_t target, int32_t max_limit, int32_t min_limit)
Wrap the target position over limit.
std::vector< double > linspace(double lb, double ub, size_t n)
Generate equally spaced points inside an interval.
Definition: util.cc:314
CirculoType
Definition: util.h:48
PositionControlStrategy
Definition: util.h:153
ControllerType
Definition: util.h:44
uint64_t wait_for_sync_signal(uint32_t signal_id)
Wait for the system sync signal.
std::string etg1004_unit_string(uint32_t etg1004_unit_value)
Convert ETG.1004 unit format to string.
Definition: util.cc:124
EncoderLocation
Definition: util.h:64
MotionMasterWarning
Definition: util.h:155
@ WAR_PROFILE_TARGET_LIMITED
Definition: util.h:157
@ WAR_INTERNAL_LIMIT_REACHED
Definition: util.h:158
@ WAR_NONE
Definition: util.h:156
const char *const VARIANT_FILENAME
Definition: util.h:31
std::vector< uint8_t > read_file_content(const std::string &path)
Read a file into a byte (uint8_t) vector.
Definition: util.cc:493
uint8_t calculate_crc(const std::vector< uint8_t > &data)
Definition: util.cc:623
uint32_t generate_od_entry_map_key(uint16_t index, uint8_t subindex)
Generate a map key for an OD entry using index/subindex.
Definition: util.cc:1572
unsigned char random_char()
Generate a random character.
Definition: util.cc:655
std::vector< uint8_t > zip(const std::string &file_name, std::vector< uint8_t > data)
Zip a single file.
Definition: util.cc:1479
bool file_exists(const std::string &path)
Check if a file exists on the system where Motion Master is running.
Definition: util.cc:907
std::string get_master_warning_message(MotionMasterWarning warning)
Return the appropriate warning message.
Definition: util.cc:49
bool set_position_controller_gains(Cia402Drive &cia402_drive, const ControllerGains &gains)
Set the position controller gains.
Definition: util.cc:384
bool check_gains(Cia402Drive &cia402_drive)
Check if the required gains are properly set.
Definition: util.cc:454
CirculoEncoderType
Definition: util.h:56
bool abs_compare(float a, float b)
Compare absolute values of the input parameters.
Definition: util.cc:251
void interruptable_wait(size_t seconds)
Blocks for the set amount of time, but allows to be interrupted.
Definition: util.cc:253
uint32_t random_uint32(uint32_t min=0, uint32_t max=UINT32_MAX)
Generate a random unsigned 32-bit integer in a certain range.
Definition: util.cc:648
double compute_standard_deviation(const std::vector< T > &numbers)
Compute the standard deviation given a vector of numbers.
Definition: util.h:917
std::list< std::string > get_file_parts(std::list< std::string > file_list, const std::string &file_name)
Process the provided file list and find the file or its parts.
Definition: util.cc:1576
std::vector< T > erase_edge_elements(std::vector< T > v, size_t length)
Remove a number of the first and last elements in the vector.
Definition: util.h:962
int get_soem_slaves_responding()
Definition: util.cc:1728
EncoderLocation get_encoder_location(Cia402Drive &cia402_drive, uint8_t encoder_ordinal)
Get the location of an encoder.
Definition: util.cc:1606
int32_t get_pdo_id(uint16_t index, uint8_t subindex, std::map< int32_t, int32_t > &pdo_position_map)
Uses a special map and its keys to get the PDO array positions.
Definition: util.cc:175
const char *const STACK_IMAGE_FILENAME
Definition: util.h:27
std::string string_bytes_to_hex_array_string(const std::string &bytes)
Convert bytes (as string) to a string of hex values.
Definition: util.cc:912
bool is_fw_based_on_v5(Cia402Drive &cia402_drive)
Check if the device requires the newer encoder configuration (FW >= v5 or FW >= v0....
Definition: util.cc:1448
EcatSlaveFoeError
Definition: util.h:387
bool is_future_done(std::future< R > const &f)
Check if the future has finished executing.
Definition: util.h:976
bool is_fw_at_least(Cia402Drive &cia402_drive, const std::string &version)
Check if the drive uses at least a certain FW version.
Definition: util.cc:1465
struct TuningParametersClass TuningParameters
struct SystemParametersClass SystemParameters
const char *const PLANT_MODEL_FILENAME
Definition: util.h:30
std::string get_firmware_version_string(Cia402Drive &cia402_drive)
Get the (string) version of the used firmware.
Definition: util.cc:924
std::string string_format(const std::string &format, Args... args)
Format a string like printf()
Definition: util.h:1020
auto to_integral(T e)
Return an integral type value of an enum class.
Definition: util.h:992
AutoTuningDriveConfiguration get_auto_tuning_drive_configuration(Cia402Drive &cia402_drive)
Get the configuration required for full auto-tuning.
Definition: util.cc:1022
const std::string current_date_time()
Get the current time and date as a custom string.
Definition: util.cc:188
CirculoType get_circulo_type(int32_t hardware_id)
Get the Circulo type based on the hardware ID.
void set_csv_configuration(VirtualDevice *virtual_device, const std::vector< uint8_t > &csv_data)
Set the configuration parameter values from CSV data.
Definition: util.cc:523