Motion Master
Loading...
Searching...
No Matches
profile.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <functional>
6
7#include "util.h"
8
9typedef struct {
10 double max_acceleration; // max acceleration
12 int32_t max_torque; // permill
13 int32_t max_torque_acceleration; // permill/s
14
15 /*User Inputs*/
16
17 double acc; // acceleration
18 double dec; // deceleration
19 double vi; // velocity
20 double qi; // initial position
21 double qf; // final position
22
23 /*Profile time*/
24
25 double T; // total no. of Samples
26 double s_time; // sampling time
27
28 int32_t direction;
29
30 /*LFPB motion profile constants*/
31
32 double ai;
33 double bi;
34 double ci;
35 double di;
36 double ei;
37 double fi;
38 double gi;
39
40 /*internal velocity variables*/
41
42 double qid; // initial velocity
43 double qfd; // final velocity
44
47 double distance_acc; // distance covered during acceleration
48 double distance_dec; // distance covered during deceleration
49
50 double tb_acc; // blend time for acceleration profile
51 double tb_dec; // blend time for deceleration profile
52 double tf; // total time for profile
53 double t_cruise; // time for cruise velocity profile
54 double ts; // variable to hold current sample time
55
56 double q; // position profile
57
60
61 int32_t steps; // number of steps required to execute this profile
62
64
65class Profile {
66 public:
67 Profile(Cia402Drive &cia402_drive, int64_t target, uint32_t velocity,
68 uint32_t acceleration, uint32_t deceleration, uint32_t torque_slope,
69 float sine_frequency, uint32_t sustain_time_ms, bool repeat,
70 bool master_generated = false, bool absolute_target = false);
71
72 ~Profile();
73
83 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
84
94 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
95
106 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
107
114
125 std::function<void(MotionMasterWarning)> warning_callback = nullptr,
126 bool non_stop = false);
127
137 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
138
149 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
150
157
167 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
168
178 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
179
190 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
191
198
202 void stop();
203
209 bool was_aborted() const;
210
211 private:
212 Cia402Drive &cia402_drive_;
213 MotionProfile motion_profile_ = {};
214 int32_t target_;
215 uint32_t velocity_;
216 uint32_t acceleration_;
217 uint32_t deceleration_;
218 uint32_t torque_slope_;
219 uint32_t sustain_time_ms_;
220
221 uint32_t encoder_resolution_ = 0;
222 double feed_constant_ = 0;
223 int32_t position_delta_ = 0;
224
225 bool repeat_;
226 bool absolute_target_;
227 bool stop_ = false;
228 bool aborted_ = false;
229
230 // Master generated profile values
231 bool master_generated_;
232 int32_t min_position_range_limit_ = 0;
233 int32_t max_position_range_limit_ = 0;
234 float sine_frequency_;
235
236 uint32_t object_id_;
237
243 MotionMasterError init_master_position_profile();
244
250 MotionMasterError init_master_velocity_profile();
251
257 MotionMasterError init_master_torque_profile();
258
259 bool is_slave_position_profile_supported();
260 bool is_slave_velocity_profile_supported();
261 bool is_slave_torque_profile_supported();
262 MotionMasterError setup_slave_position_profile(
263 std::function<void(MotionMasterWarning)> &warning_callback,
264 bool bidirectional = false);
265 MotionMasterError setup_slave_velocity_profile(
266 std::function<void(MotionMasterWarning)> &warning_callback);
267 MotionMasterError setup_slave_torque_profile(
268 std::function<void(MotionMasterWarning)> &warning_callback);
269
273 void deinit_master_profile();
274
281 void execute_master_position_profile_stage(int32_t start, int32_t target);
282
290 void execute_master_position_profile_sin(int32_t start, int32_t target,
291 bool repeat);
292
299 void execute_master_velocity_profile_stage(int32_t start, int32_t target);
300
308 void execute_master_velocity_profile_sin(int32_t start, int32_t target,
309 bool repeat);
310
317 void execute_master_torque_profile_stage(int32_t start, int32_t target);
318
326 void execute_master_torque_profile_sin(int32_t start, int32_t target,
327 bool repeat);
328
337 int32_t calculate_position_profile_steps(int32_t start, int32_t target);
338
347 int32_t calculate_velocity_profile_steps(int32_t start, int32_t target);
348
357 int32_t calculate_torque_profile_steps(int32_t start, int32_t target);
358
367 void init_master_profile_limits(int32_t max_torque_acceleration,
368 int32_t max_acceleration,
369 int32_t max_position, int32_t min_position);
370
376 int32_t init_linear_profile();
377
385 int32_t position_profile_generate(int32_t step);
386
392 int32_t linear_profile_generate_in_steps(int32_t step);
393
402 static double rpm_to_ticks(uint32_t rpm, uint32_t encoder_resolution);
403
412 static double ticks_to_rpm(double ticks, uint32_t encoder_resolution);
413
423 void validate_position_profile_acceleration_deceleration();
424
431 void interruptible_sustain(uint32_t sustain_time_ms);
432};
Definition: cia402_drive.h:48
Definition: motion_master_error.h:6
Definition: profile.h:65
MotionMasterError start_sine_wave_velocity_profile()
Start executing a velocity sine wave profile.
Definition: profile.cc:1225
MotionMasterError start_trapezoidal_velocity_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr)
Start executing a velocity trapezoidal profile from zero to target, then back to zero....
Definition: profile.cc:976
MotionMasterError start_trapezoidal_position_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr)
Start executing a position trapezoidal profile from zero to target, then back to zero....
Definition: profile.cc:518
MotionMasterError start_bidirectional_position_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr)
Start executing a position trapezoidal profile from zero to target, then back to negative target and ...
Definition: profile.cc:672
bool was_aborted() const
Indicates if the profile has been aborted before it finished.
Definition: profile.cc:1615
void stop()
Stop the currently running (repeating) profile after a full cycle.
Definition: profile.cc:1613
MotionMasterError start_ramp_position_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr)
Start executing a position trapezoidal profile from zero to target. (Z - zero; T - target)
Definition: profile.cc:419
MotionMasterError start_sine_wave_torque_profile()
Start executing a torque sine wave profile.
Definition: profile.cc:1582
~Profile()
Definition: profile.cc:39
MotionMasterError start_bidirectional_torque_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr)
Start executing a torque trapezoidal profile from zero to target, then back to negative target and th...
Definition: profile.cc:1448
MotionMasterError start_bidirectional_velocity_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr)
Start executing a velocity trapezoidal profile from zero to target, then back to negative target and ...
Definition: profile.cc:1092
MotionMasterError start_sine_wave_position_profile()
Start executing a position sine wave profile.
Definition: profile.cc:855
MotionMasterError start_ramp_torque_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr)
Start executing a torque trapezoidal profile from zero to target. (Z - zero; T - target)
Definition: profile.cc:1256
MotionMasterError start_trapezoidal_torque_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr)
Start executing a torque trapezoidal profile from zero to target, then back to zero....
Definition: profile.cc:1330
MotionMasterError start_ramp_velocity_profile(std::function< void(MotionMasterWarning)> warning_callback=nullptr, bool non_stop=false)
Start executing a velocity trapezoidal profile from zero to target. (Z - zero; T - target)
Definition: profile.cc:897
Definition: profile.h:9
double t_cruise
Definition: profile.h:53
double acc
Definition: profile.h:17
double gi
Definition: profile.h:38
double min_position
Definition: profile.h:59
double bi
Definition: profile.h:33
double di
Definition: profile.h:35
double qfd
Definition: profile.h:43
int32_t steps
Definition: profile.h:61
double ai
Definition: profile.h:32
double tb_acc
Definition: profile.h:50
double q
Definition: profile.h:56
double ei
Definition: profile.h:36
double ts
Definition: profile.h:54
int32_t max_torque_acceleration
Definition: profile.h:13
double max_velocity
Definition: profile.h:11
int32_t max_torque
Definition: profile.h:12
double ci
Definition: profile.h:34
double distance_acc
Definition: profile.h:47
double T
Definition: profile.h:25
double distance_cruise
Definition: profile.h:45
double s_time
Definition: profile.h:26
double distance_dec
Definition: profile.h:48
double dec
Definition: profile.h:18
double max_acceleration
Definition: profile.h:10
double qi
Definition: profile.h:20
double total_distance
Definition: profile.h:46
int32_t direction
Definition: profile.h:28
double fi
Definition: profile.h:37
double tb_dec
Definition: profile.h:51
double qid
Definition: profile.h:42
double max_position
Definition: profile.h:58
double vi
Definition: profile.h:19
double qf
Definition: profile.h:21
double tf
Definition: profile.h:52
MotionMasterWarning
Definition: util.h:155