forked from ros-industrial/abb_libegm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathegm_trajectory_interface.h
More file actions
1293 lines (1133 loc) · 39.1 KB
/
Copy pathegm_trajectory_interface.h
File metadata and controls
1293 lines (1133 loc) · 39.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************************************************************
*
* Copyright (c) 2015, ABB Schweiz AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that
* the following conditions are met:
*
* * Redistributions of source code must retain the
* above copyright notice, this list of conditions
* and the following disclaimer.
* * Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions
* and the following disclaimer in the documentation
* and/or other materials provided with the
* distribution.
* * Neither the name of ABB nor the names of its
* contributors may be used to endorse or promote
* products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
***********************************************************************************************************************
*/
#ifndef EGM_TRAJECTORY_INTERFACE_H
#define EGM_TRAJECTORY_INTERFACE_H
#include <memory>
#include <queue>
#include "egm_wrapper_trajectory.pb.h" // Generated by Google Protocol Buffer compiler protoc
#include "egm_base_interface.h"
#include "egm_common.h"
#include "egm_interpolator.h"
namespace abb
{
namespace egm
{
/**
* \brief Class for an EGM trajectory user interface.
*
* The class provides behavior for following trajectories provided by an external user, and this includes:
* - Processing asynchronous callbacks from an UDP server.
* - Queuing ordered trajectories, and follow them in order.
* - Providing methods for interacting with the trajectory execution (e.g. stop and resume execution).
*/
class EGMTrajectoryInterface : public EGMBaseInterface
{
public:
/**
* \brief A constructor.
*
* \param io_service for operating asio's asynchronous functions.
* \param port_number for the server's UDP socket.
* \param configuration for the interface's configuration.
*/
EGMTrajectoryInterface(asio::io_service& io_service,
const unsigned short port_number,
const TrajectoryConfiguration& configuration = TrajectoryConfiguration());
/**
* \brief Retrive the interface's current configuration.
*
* \return TrajectoryConfiguration containing the current configuration.
*/
TrajectoryConfiguration getConfiguration();
/**
* \brief Update the interface's configuration (update is only applied for new EGM communication sessions).
*
* \param configuration containing the configuration update.
*/
void setConfiguration(const TrajectoryConfiguration& configuration);
/**
* \brief Add a trajectory to the execution queue.
*
* \param trajectory containing the trajectory to add.
* \param override_trajectories indicating if all pending trajectories should be overridden (i.e. removed).
*
* \return bool indicating if the interface accepted the command or not.
*/
bool addTrajectory(const wrapper::trajectory::TrajectoryGoal trajectory, const bool override_trajectories = false);
/**
* \brief Stop the trajectory motion execution.
*
* Note: The intention is to only use this for short temporary stops, for long stops it is recommended to stop the
* EGM communication session completely. A resume normally needs to be ordered for execution to start again.
*
* \param discard_trajectories indicating if all pending trajectories should be discarded (i.e. removed).
*
* \return bool indicating if the interface accepted the command or not.
*/
bool stopTrajectory(const bool discard_trajectories = false);
/**
* \brief Resume the trajectory motion execution (after a stop has occurred).
*
* \return bool indicating if the interface accepted the command or not.
*/
bool resumeTrajectory();
/**
* \brief Update the duration scaling factor for trajectory goals.
*
* Note: Only values between 1.0 and 5.0 will be considered. E.g. if the factor is 2.0,
* then the remaining duration will be doubled. As will all upcoming goal durations.
*
* \param factor containing the new scale factor.
*
* \return bool indicating if the interface accepted the command or not.
*/
bool updateDurationFactor(double factor);
/**
* \brief Start to follow a static goal.
*
* Note: Any current trajectory motions will be stopped before starting to follow the static goal.
*
* \param discard_trajectories indicating if all pending trajectories should be discarded (i.e. removed).
*
* \return bool indicating if the interface accepted the command or not.
*/
bool startStaticGoal(const bool discard_trajectories = false);
/**
* \brief Set a static position goal to follow.
*
* \param position_goal containing the static position goal to follow.
* \param fast_transition indicating if a fast transition should be done. I.e. skip ramp out of current goal.
*
* \return bool indicating if the interface accepted the command or not.
*/
bool setStaticGoal(const wrapper::trajectory::StaticPositionGoal& position_goal, const bool fast_transition = false);
/**
* \brief Set a static velocity goal to follow.
*
* \param velocity_goal containing the static velocity goal to follow.
* \param fast_transition indicating if a fast transition should be done. I.e. skip ramp out of current goal.
*
* \return bool indicating if the interface accepted the command or not.
*/
bool setStaticGoal(const wrapper::trajectory::StaticVelocityGoal& velocity_goal, const bool fast_transition = false);
/**
* \brief Finish following a static goal.
*
* \param resume indicating if normal trajectory motion execution should be resumed automatically.
*
* \return bool indicating if the interface accepted the command or not.
*/
bool finishStaticGoal(const bool resume = false);
/**
* \brief Retrieve an execution progress from the trajectory interface.
*
* \param p_execution_progress for containing the execution progress.
*
* \return bool indicating if the execution progress has been successfully retrieved or not.
*/
bool retrieveExecutionProgress(wrapper::trajectory::ExecutionProgress* p_execution_progress);
private:
/**
* \brief Struct for containing the configuration data.
*/
struct ConfigurationContainer
{
/**
* \brief A constructor.
*
* \param initial specifying the initial configuration.
*/
ConfigurationContainer(const TrajectoryConfiguration& initial)
:
active(initial),
update(initial),
has_pending_update(false)
{}
/**
* \brief The active configuration.
*/
TrajectoryConfiguration active;
/**
* \brief The configuration update.
*/
TrajectoryConfiguration update;
/**
* \brief Flag indicating if the active configuration should be updated.
*/
bool has_pending_update;
/**
* \brief Mutex for protecting the configuration.
*/
std::mutex mutex;
};
/**
* \brief Class for managing the points, in a trajectory, that the robot should pass through.
*/
class Trajectory
{
public:
/**
* \brief Default constructor.
*/
Trajectory() {}
/**
* \brief A constructor.
*
* param trajectory for a trajectory to parse.
*/
Trajectory(const wrapper::trajectory::TrajectoryGoal& trajectory)
{
for (int i = 0; i < trajectory.points_size(); ++i)
{
addTrajectoryPointBack(trajectory.points().Get(i));
}
}
/**
* \brief Add a point to the front of the queue.
*
* \param point to store.
*/
void addTrajectoryPointFront(const wrapper::trajectory::PointGoal& point)
{
points_.push_front(point);
}
/**
* \brief Add a point to the back of the queue.
*
* \param point to store.
*/
void addTrajectoryPointBack(const wrapper::trajectory::PointGoal& point)
{
points_.push_back(point);
}
/**
* \brief Retrive a point from the queue.
*
* \param p_point for storing the retrived point.
*
* \return bool indicating if a point was retrived or not.
*/
bool retriveNextTrajectoryPoint(wrapper::trajectory::PointGoal* p_point)
{
bool result = false;
if (p_point && !points_.empty())
{
p_point->CopyFrom(points_.front());
points_.pop_front();
result = true;
}
return result;
}
/**
* \brief Copy the whole queue to a trajectory container.
*
* \param p_trajectory for containing the queue.
*/
void copyTo(wrapper::trajectory::TrajectoryGoal* p_trajectory)
{
std::deque<wrapper::trajectory::PointGoal>::const_iterator i;
if (p_trajectory)
{
for (i = points_.begin(); i != points_.end(); ++i)
{
p_trajectory->add_points()->CopyFrom(*i);
}
}
}
/**
* \brief Retrive the number of points in the queue.
*
* \return size_t indicating the number of points in the queue.
*/
size_t size()
{
return points_.size();
}
private:
/**
* \brief Container for the points in the trajectory.
*/
std::deque<wrapper::trajectory::PointGoal> points_;
};
/**
* \brief Class for managing trajectory motion data, between an external user and the EGM communication loop.
*/
class TrajectoryMotion
{
public:
/**
* \brief A constructor.
*
* \param configurations specifying the interface's initial configurations.
*/
TrajectoryMotion(const TrajectoryConfiguration& configurations)
:
DURATION_FACTOR_MIN(1.0),
DURATION_FACTOR_MAX(5.0),
configurations_(configurations),
motion_step_(configurations)
{}
/**
* \brief Update the interface's configurations.
*
* \param configurations specifying the interface's new configurations.
*/
void updateConfigurations(const TrajectoryConfiguration& configurations)
{
configurations_ = configurations;
motion_step_.updateConfigurations(configurations);
}
/**
* \brief Generate outputs, based on the current goal and e.g. the use of spline interpolation.
*
* \param p_outputs for containing the outputs.
* \param inputs containing the inputs from the robot controller.
*/
void generateOutputs(wrapper::Output* p_outputs, const InputContainer& inputs);
/**
* \brief Add a trajectory to the execution queue.
*
* \param trajectory containing the trajectory to add.
* \param override_trajectories indicating if all pending trajectories should be overridden (i.e. removed).
*
* \return bool indicating if the interface accepted the command or not.
*/
bool addTrajectory(const wrapper::trajectory::TrajectoryGoal& trajectory, const bool override_trajectories);
/**
* \brief Stop the trajectory motion execution.
*
* Note: A resume normally needs to be ordered for execution to start again.
*
* \param discard_trajectories indicating if all pending trajectories should be discarded (i.e. removed).
*
* \return bool indicating if the interface accepted the command or not.
*/
bool stopTrajectory(const bool discard_trajectories);
/**
* \brief Resume the trajectory motion execution (after a stop has occurred).
*
* \return bool indicating if the interface accepted the command or not.
*/
bool resumeTrajectory();
/**
* \brief Update the duration scaling factor for trajectory goals.
*
* Note: Only values between 1.0 and 5.0 will be considered. E.g. if the factor is 2.0,
* then the remaining duration will be doubled. As will all upcoming goal durations.
*
* \param factor containing the new scale factor.
*
* \return bool indicating if the interface accepted the command or not.
*/
bool updateDurationFactor(double factor);
/**
* \brief Start to follow a static goal.
*
* Note: Any current trajectory motions will be stopped before starting to follow the static goal.
*
* \param discard_trajectories indicating if all pending trajectories should be discarded (i.e. removed).
*
* \return bool indicating if the interface accepted the command or not.
*/
bool startStaticGoal(const bool discard_trajectories);
/**
* \brief Set a static position goal to follow.
*
* \param position_goal containing the static position goal to follow.
* \param fast_transition indicating if a fast transition should be done. I.e. skip ramp out of current goal.
*
* \return bool indicating if the interface accepted the command or not.
*/
bool setStaticGoal(const wrapper::trajectory::StaticPositionGoal& position_goal, const bool fast_transition);
/**
* \brief Set a static velocity goal to follow.
*
* \param velocity_goal containing the static velocity goal to follow.
* \param fast_transition indicating if a fast transition should be done. I.e. skip ramp out of current goal.
*
* \return bool indicating if the interface accepted the command or not.
*/
bool setStaticGoal(const wrapper::trajectory::StaticVelocityGoal& velocity_goal, const bool fast_transition);
/**
* \brief Finish following a static goal.
*
* \param resume indicating if normal trajectory motion execution should be resumed automatically.
*
* \return bool indicating if the interface accepted the command or not.
*/
bool finishStaticGoal(const bool resume);
/**
* \brief Retrieve an execution progress from the trajectory interface.
*
* \param p_progress for containing the execution progress.
*
* \return bool indicating if the execution progress has been recently updated or not.
*/
bool retrieveExecutionProgress(wrapper::trajectory::ExecutionProgress* p_progress);
private:
/**
* \brief Enum for the different execution states the interface can handle.
*/
enum States
{
Normal, ///< \brief Retrieve goals from the current trajectory.
RampDown, ///< \brief Ramp down the current velocity references.
StaticGoal ///< \brief Follow either static position or velocity goals.
};
/**
* \brief Enum for the different execution sub states the interface can handle.
*/
enum SubStates
{
None, ///< \brief The current state has no active sub state.
Running, ///< \brief The current state has a running sub state.
Finished ///< \brief The current state has finished a sub state.
};
/**
* \brief Container for decision data, used to decide what to do during execution of trajectory motions.
*/
struct DecisionData
{
/**
* \brief Container for pending events.
*/
struct PendingEvents
{
/**
* \brief Default constructor.
*/
PendingEvents()
:
do_stop(false),
do_resume(false),
do_discard(false),
do_ramp_down(false),
do_static_goal_start(false),
do_static_goal_fast_update(false),
do_static_position_goal_update(false),
do_static_velocity_goal_update(false),
do_static_goal_finish(false),
do_duration_factor_update(false),
duration_factor(1.0)
{};
/**
* \brief Flag indicating if the current velocities should be completely ramped out.
*/
bool do_stop;
/**
* \brief Flag indicating if the execution should resume after a complete stop has occurred.
*/
bool do_resume;
/**
* \brief Flag indicating if the current trajectories should be discarded.
*/
bool do_discard;
/**
* \brief Flag indicating if the current motion's velocity should be ramped down.
*/
bool do_ramp_down;
/**
* \brief Flag indicating if static goal execution should be started.
*/
bool do_static_goal_start;
/**
* \brief Flag indicating if the static goal should be updated fast.
*/
bool do_static_goal_fast_update;
/**
* \brief Flag indicating if the static position goal should be updated.
*/
bool do_static_position_goal_update;
/**
* \brief Flag indicating if the static velocity goal should be updated.
*/
bool do_static_velocity_goal_update;
/**
* \brief Flag indicating if the static goal execution should be finished.
*/
bool do_static_goal_finish;
/**
* \brief The pending static position goal to follow.
*/
wrapper::trajectory::StaticPositionGoal static_position_goal;
/**
* \brief The pending static velocity goal to follow.
*/
wrapper::trajectory::StaticVelocityGoal static_velocity_goal;
/**
* \brief Flag indicating if the duration scale factor should be updated.
*/
bool do_duration_factor_update;
/**
* \brief The pending duration scale factor update.
*/
double duration_factor;
};
/**
* \brief Default constructor.
*/
DecisionData()
:
has_new_goal(false),
has_active_goal(false),
has_updated_execution_progress(false)
{}
/**
* \brief Flag indicating if there is a new goal.
*
* Note: A new goal implies that the interpolator should be updated (e.g. calculation of coefficients).
*/
bool has_new_goal;
/**
* \brief Flag indicating if there is an active goal.
*/
bool has_active_goal;
/**
* \brief The pending events for the trajectory motion execution.
*/
PendingEvents pending_events;
/**
* \brief Flag indicating if the execution progress has been updated or not.
*/
bool has_updated_execution_progress;
/**
* \brief The interface's execution progress.
*/
wrapper::trajectory::ExecutionProgress execution_progress;
/**
* \brief Mutex for protecting the data.
*/
std::mutex mutex;
};
/**
* \brief Container for trajectory data. E.g. trajectory queues, and the currently active trajectory.
*/
struct TrajectoryContainer
{
/**
* \brief Queue for storing trajectories to execute.
*/
std::deque<std::shared_ptr<Trajectory> > primary_queue;
/**
* \brief Queue for temporary storing trajectories to execute (e.g. during a discard trajectories event).
*/
std::deque<std::shared_ptr<Trajectory> > temporary_queue;
/**
* \brief The currently active trajectory.
*/
std::shared_ptr<Trajectory> p_current;
/**
* \brief Mutex for protecting the data.
*/
std::mutex mutex;
};
/**
* \brief Class for managing the interface's internal states.
*/
class StateManager
{
public:
/**
* \brief Default constructor.
*/
StateManager()
:
has_pending_state_(false),
current_state_(Normal),
current_sub_state_(None),
pending_state_(Normal),
pending_sub_state_(None)
{}
/**
* \brief Activate the state manager.
*/
void activateStateManager()
{
current_state_ = Normal;
current_sub_state_ = Running;
}
/**
* \brief Reset the state manager.
*/
void resetStateManager()
{
current_state_ = Normal;
current_sub_state_ = None;
pending_state_ = Normal;
pending_sub_state_ = None;
has_pending_state_ = false;
}
/**
* \brief Get the current state.
*/
States getState()
{
return current_state_;
}
/**
* \brief Get the current sub state.
*/
SubStates getSubState()
{
return current_sub_state_;
}
/**
* \brief Set the desired pending state and sub state.
*
* \param desired_state specifying the desired state.
* \param desired_sub_state specifying the desired sub state.
*/
void setPendingState(const States& desired_state, const SubStates& desired_sub_state);
/**
* \brief Update the state and sub state.
*/
void updateState()
{
if (has_pending_state_)
{
current_state_ = pending_state_;
current_sub_state_ = pending_sub_state_;
has_pending_state_ = false;
}
}
/**
* \brief Verify the interface's current state and sub state.
*
* \param state specifying the state to verify.
* \param sub_state specifying the sub state to verify.
*
* \return bool indicating if the state and sub state has been verified.
*/
bool verifyState(const States& state, const SubStates& sub_state)
{
return (current_state_ == state && current_sub_state_ == sub_state);
}
/**
* \brief Maps the interface's current internal state to an execution progress state.
*
* The interface can be in any of the following states:
* - Undefined state (should never occur).
* - Normal state (references are generated from trajectories specified by a user).
* - Ramp down state (ramping down any current references).
* - Static goal state (references are generated from a single goal point specified by a user).
*
* \return ExecutionProgress_State with the execution progress state.
*/
wrapper::trajectory::ExecutionProgress_State mapState();
/**
* \brief Maps the interface's current internal sub state to an execution progress sub state.
*
* The interface can be in any of the following sub states (depending on the current state):
* - None sub state (the current state is not active yet).
* - Running sub state (the current state is running).
* - Finished sub state (the current state has finished).
*
* \return ExecutionProgress_SubState with the execution progress sub state.
*/
wrapper::trajectory::ExecutionProgress_SubState mapSubState();
private:
/**
* \brief Flag indicating if there are any pending state change.
*/
bool has_pending_state_;
/**
* \brief The current state.
*/
States current_state_;
/**
* \brief The current sub state.
*/
SubStates current_sub_state_;
/**
* \brief The pending state.
*/
States pending_state_;
/**
* \brief The pending sub state.
*/
SubStates pending_sub_state_;
};
/**
* \brief Class for managing motion step data.
*/
class MotionStep
{
public:
/**
* \brief Container for process data, used for processing motion steps.
*/
struct ProcessData
{
/**
* \brief Default constructor.
*/
ProcessData()
:
mode(EGMJoint),
time_passed(0.0),
estimated_sample_time(Constants::RobotController::LOWEST_SAMPLE_TIME),
duration_factor(1.0)
{}
/**
* \brief The assumed active EGM mode.
*/
EGMModes mode;
/**
* \brief The time passed for the current goal execution.
*/
double time_passed;
/**
* \brief The estimated sample time.
*/
double estimated_sample_time;
/**
* \brief A scaling factor for the goal duration.
*/
double duration_factor;
/**
* \brief Container for the current robot feedback values.
*/
wrapper::Feedback feedback;
};
/**
* \brief A constructor.
*
* \param configurations specifying the trajectory interface's initial configurations.
*/
MotionStep(const TrajectoryConfiguration& configurations)
:
CONDITION(0.005),
RAMP_DOWN_STOP_DURATION(1.0),
STATIC_GOAL_DURATION(5.0),
STATIC_GOAL_DURATION_SHORT(0.1),
condition_met_(true),
configurations_(configurations)
{}
/**
* \brief Update the interface's configurations.
*
* \param configurations specifying the interface's new configurations.
*/
void updateConfigurations(const TrajectoryConfiguration& configurations)
{
configurations_ = configurations;
}
/**
* \brief Reset the motion step data.
*/
void resetMotionStep();
/**
* \brief Prepare for a normal goal.
*
* \param last_point indicating if it is the last point in the current trajectory.
*/
void prepareNormalGoal(const bool last_point);
/**
* \brief Prepare for a ramp down goal.
*
* \param do_stop indicating if a stop should be performed.
*/
void prepareRampDownGoal(const bool do_stop);
/**
* \brief Prepare for a static position goal.
*
* \param position_goal containing the static goal to follow.
* \param fast_transition indicating if a fast transition should be done.
*/
void prepareStaticGoal(const wrapper::trajectory::StaticPositionGoal& position_goal, const bool fast_transition);
/**
* \brief Prepare for a static velocity goal.
*
* \param velocity_goal containing the static goal to follow.
* \param fast_transition indicating if a fast transition should be done.
*/
void prepareStaticGoal(const wrapper::trajectory::StaticVelocityGoal& velocity_goal, const bool fast_transition);
/**
* \brief Check if the goal conditions has been met.
*
* \return bool indicating if the goal condition has been met or not.
*/
bool conditionMet();
/**
* \brief Check if the interpolation duration has been reached.
*
* \return bool indicating if the interpolation duration has been reached or not.
*/
bool interpolationDurationReached()
{
return ((interpolator.getDuration() - data.time_passed) < 0.5*Constants::RobotController::LOWEST_SAMPLE_TIME);
}
/**
* \brief Update the interpolator according to the specified internal goal.
*
* E.g. used after a new point has been activated in a trajectory.
*/
void updateInterpolator()
{
data.time_passed = 0.0;
interpolation.set_reach(internal_goal.reach());
interpolation.set_duration(interpolator_conditions_.duration);
interpolator.update(interpolation, internal_goal, interpolator_conditions_);
}
/**
* \brief Evaluate the interpolator (at the next time instance).
*/
void evaluateInterpolator()
{
data.time_passed += data.estimated_sample_time;
interpolator.evaluate(&interpolation, data.estimated_sample_time, data.time_passed);
}
/**
* \brief Data used during the processing of motion steps.
*/
ProcessData data;
/**
* \brief The internal goal point (updated with the data present in the external goal point).
*/
wrapper::trajectory::PointGoal internal_goal;
/**
* \brief The external goal point (retrieved from external user input).
*/
wrapper::trajectory::PointGoal external_goal;
/**
* \brief The interpolation (i.e. reference point to the robot controller).
*/
wrapper::trajectory::PointGoal interpolation;
/**
* \brief The interpolation manager.
*/
EGMInterpolator interpolator;
private:
/**
* \brief Estimate the duration for the internal goal.
*
* Note: Should only be used if no duration has been specified externally.
*
* \return double containing the estimation.
*/
double estimateDuration();
/**
* \brief Check if the conditions has been satisfied for a joint goal.
*
* \param goal containing the goal.
* \param feedback containing the feedback.
*/
void checkConditions(const wrapper::Joints& goal, const wrapper::Joints& feedback);
/**
* \brief Check if the conditions has been satisfied for a Cartesian goal.
*
* \param goal containing the goal.
* \param feedback containing the feedback.
*/
void checkConditions(const wrapper::Cartesian& goal, const wrapper::Cartesian& feedback);
/**
* \brief Check if the conditions has been satisfied for a quaternion goal.
*
* \param goal containing the goal.
* \param feedback containing the feedback.
*/
void checkConditions(const wrapper::Quaternion& goal, const wrapper::Quaternion& feedback);
/**
* \brief Transfer values from an external robot goal to the internal goal.
*
* \param source containing the values to transfer.
*/
void transfer(const wrapper::trajectory::RobotGoal& source);
/**
* \brief Transfer values from an external external goal to the internal goal.
*
* \param source containing the values to transfer.
*/
void transfer(const wrapper::trajectory::ExternalGoal& source);
/**
* \brief Transfer values from an external static position goal to the internal goal.
*
* \param source containing the values to transfer.
*/
void transfer(const wrapper::trajectory::StaticPositionGoal& source);
/**
* \brief Transfer values from an external static velocity goal to the internal goal.
*
* \param source containing the values to transfer.