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
63
64class Profile {
65 public:
66 Profile(Cia402Drive& cia402_drive, int64_t target, uint32_t velocity,
67 uint32_t acceleration, uint32_t deceleration, uint32_t torque_slope,
68 float sine_frequency, uint32_t sustain_time_ms, bool repeat,
69 bool master_generated = false, bool absolute_target = false);
70
71 ~Profile();
72
82 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
83
93 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
94
105 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
106
113
124 std::function<void(MotionMasterWarning)> warning_callback = nullptr,
125 bool non_stop = false);
126
136 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
137
148 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
149
156
166 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
167
177 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
178
189 std::function<void(MotionMasterWarning)> warning_callback = nullptr);
190
197
201 void stop();
202
208 bool was_aborted() const;
209
210 private:
211 Cia402Drive& cia402_drive_;
212 MotionProfile motion_profile_ = {};
213 int32_t target_;
214 uint32_t velocity_;
215 uint32_t acceleration_;
216 uint32_t deceleration_;
217 uint32_t torque_slope_;
218 uint32_t sustain_time_ms_;
219
220 uint32_t encoder_resolution_ = 0;
221 double feed_constant_ = 0;
222 int32_t position_delta_ = 0;
223
224 bool repeat_;
225 bool absolute_target_;
226 bool stop_ = false;
227 bool aborted_ = false;
228
229 // Master generated profile values
230 bool master_generated_;
231 int32_t min_position_range_limit_ = 0;
232 int32_t max_position_range_limit_ = 0;
233 float sine_frequency_;
234
235 uint32_t object_id_;
236
242 MotionMasterError init_master_position_profile();
243
249 MotionMasterError init_master_velocity_profile();
250
256 MotionMasterError init_master_torque_profile();
257
258 bool is_slave_position_profile_supported();
259 bool is_slave_velocity_profile_supported();
260 bool is_slave_torque_profile_supported();
261 MotionMasterError setup_slave_position_profile(
262 std::function<void(MotionMasterWarning)>& warning_callback,
263 bool bidirectional = false);
264 MotionMasterError setup_slave_velocity_profile(
265 std::function<void(MotionMasterWarning)>& warning_callback);
266 MotionMasterError setup_slave_torque_profile(
267 std::function<void(MotionMasterWarning)>& warning_callback);
268
272 void deinit_master_profile();
273
280 void execute_master_position_profile_stage(int32_t start, int32_t target);
281
289 void execute_master_position_profile_sin(int32_t start, int32_t target,
290 bool repeat);
291
298 void execute_master_velocity_profile_stage(int32_t start, int32_t target);
299
307 void execute_master_velocity_profile_sin(int32_t start, int32_t target,
308 bool repeat);
309
316 void execute_master_torque_profile_stage(int32_t start, int32_t target);
317
325 void execute_master_torque_profile_sin(int32_t start, int32_t target,
326 bool repeat);
327
336 int32_t calculate_position_profile_steps(int32_t start, int32_t target);
337
346 int32_t calculate_velocity_profile_steps(int32_t start, int32_t target);
347
356 int32_t calculate_torque_profile_steps(int32_t start, int32_t target);
357
366 void init_master_profile_limits(int32_t max_torque_acceleration,
367 int32_t max_acceleration,
368 int32_t max_position, int32_t min_position);
369
375 int32_t init_linear_profile();
376
384 int32_t position_profile_generate(int32_t step);
385
391 int32_t linear_profile_generate_in_steps(int32_t step);
392
401 static double rpm_to_ticks(uint32_t rpm, uint32_t encoder_resolution);
402
411 static double ticks_to_rpm(double ticks, uint32_t encoder_resolution);
412
422 void validate_position_profile_acceleration_deceleration();
423
430 void interruptible_sustain(uint32_t sustain_time_ms);
431};
MotionMasterWarning
Definition util.h:154
Definition cia402_drive.h:48
Definition motion_master_error.h:6
MotionMasterError start_sine_wave_velocity_profile()
Start executing a velocity sine wave profile.
Definition profile.cc:1230
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:981
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:523
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:677
bool was_aborted() const
Indicates if the profile has been aborted before it finished.
Definition profile.cc:1620
void stop()
Stop the currently running (repeating) profile after a full cycle.
Definition profile.cc:1618
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:424
MotionMasterError start_sine_wave_torque_profile()
Start executing a torque sine wave profile.
Definition profile.cc:1587
~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:1453
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:1097
MotionMasterError start_sine_wave_position_profile()
Start executing a position sine wave profile.
Definition profile.cc:860
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:1261
Profile(Cia402Drive &cia402_drive, int64_t target, uint32_t velocity, uint32_t acceleration, uint32_t deceleration, uint32_t torque_slope, float sine_frequency, uint32_t sustain_time_ms, bool repeat, bool master_generated=false, bool absolute_target=false)
Definition profile.cc:21
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:1335
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:902
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