/
robot_state.h
1834 lines (1563 loc) · 85.7 KB
/
robot_state.h
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
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2013, Ioan A. Sucan
* Copyright (c) 2013, Willow Garage, Inc.
* 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 Willow Garage, Inc. 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 OWNER 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.
*********************************************************************/
/* Author: Ioan Sucan */
#pragma once
#include <moveit/robot_model/robot_model.h>
#include <moveit/robot_state/attached_body.h>
#include <moveit/transforms/transforms.h>
#include <sensor_msgs/msg/joint_state.hpp>
#include <visualization_msgs/msg/marker_array.hpp>
#include <std_msgs/msg/color_rgba.hpp>
#include <geometry_msgs/msg/twist.hpp>
#include <cassert>
#include <rclcpp/duration.hpp>
/* Terminology
* Model Frame: RobotModel's root frame == PlanningScene's planning frame
If the SRDF defines a virtual, non-fixed (e.g. floating) joint, this is the parent of this virtual joint.
Otherwise, it is the root link of the URDF model.
* Dirty Link Transforms: a caching tool for reducing the frequency of calculating forward kinematics
*/
namespace moveit
{
namespace core
{
MOVEIT_CLASS_FORWARD(RobotState); // Defines RobotStatePtr, ConstPtr, WeakPtr... etc
/** \brief Signature for functions that can verify that if the group \e joint_group in \e robot_state is set to \e
joint_group_variable_values
the state is valid or not. Returns true if the state is valid. This call is allowed to modify \e robot_state (e.g.,
set \e joint_group_variable_values) */
typedef std::function<bool(RobotState* robot_state, const JointModelGroup* joint_group,
const double* joint_group_variable_values)>
GroupStateValidityCallbackFn;
/** \brief Representation of a robot's state. This includes position,
velocity, acceleration and effort.
At the lowest level, a state is a collection of variables. Each
variable has a name and can have position, velocity, acceleration
and effort associated to it. Effort and acceleration share the
memory area for efficiency reasons (one should not set both
acceleration and effort in the same state and expect things to
work). Often variables correspond to joint names as well (joints
with one degree of freedom have one variable), but joints with
multiple degrees of freedom have more variables. Operations are
allowed at variable level, joint level (see JointModel) and joint
group level (see JointModelGroup).
For efficiency reasons a state computes forward kinematics in a
lazy fashion. This can sometimes lead to problems if the update()
function was not called on the state. */
class RobotState
{
public:
/** \brief A state can be constructed from a specified robot model. No values are initialized.
Call setToDefaultValues() if a state needs to provide valid information. */
RobotState(const RobotModelConstPtr& robot_model);
~RobotState();
/** \brief Copy constructor. */
RobotState(const RobotState& other);
/** \brief Copy operator */
RobotState& operator=(const RobotState& other);
/** \brief Get the robot model this state is constructed for. */
const RobotModelConstPtr& getRobotModel() const
{
return robot_model_;
}
/** \brief Get the number of variables that make up this state. */
std::size_t getVariableCount() const
{
return robot_model_->getVariableCount();
}
/** \brief Get the names of the variables that make up this state, in the order they are stored in memory. */
const std::vector<std::string>& getVariableNames() const
{
return robot_model_->getVariableNames();
}
/** \brief Get the model of a particular link */
const LinkModel* getLinkModel(const std::string& link) const
{
return robot_model_->getLinkModel(link);
}
/** \brief Get the model of a particular joint */
const JointModel* getJointModel(const std::string& joint) const
{
return robot_model_->getJointModel(joint);
}
/** \brief Get the model of a particular joint group */
const JointModelGroup* getJointModelGroup(const std::string& group) const
{
return robot_model_->getJointModelGroup(group);
}
/** \name Getting and setting variable position
* @{
*/
/** \brief Get a raw pointer to the positions of the variables
stored in this state. Use carefully. If you change these values
externally you need to make sure you trigger a forced update for
the state by calling update(true). */
double* getVariablePositions()
{
return position_;
}
/** \brief Get a raw pointer to the positions of the variables
stored in this state. */
const double* getVariablePositions() const
{
return position_;
}
/** \brief It is assumed \e positions is an array containing the new
positions for all variables in this state. Those values are
copied into the state. */
void setVariablePositions(const double* position);
/** \brief It is assumed \e positions is an array containing the new
positions for all variables in this state. Those values are
copied into the state. */
void setVariablePositions(const std::vector<double>& position)
{
assert(robot_model_->getVariableCount() <= position.size()); // checked only in debug mode
setVariablePositions(&position[0]);
}
/** \brief Set the positions of a set of variables. If unknown variable names are specified, an exception is thrown.
*/
void setVariablePositions(const std::map<std::string, double>& variable_map);
/** \brief Set the positions of a set of variables. If unknown variable names are specified, an exception is thrown.
Additionally, \e missing_variables is filled with the names of the variables that are not set. */
void setVariablePositions(const std::map<std::string, double>& variable_map,
std::vector<std::string>& missing_variables);
/** \brief Set the positions of a set of variables. If unknown variable names are specified, an exception is thrown.
Additionally, \e missing_variables is filled with the names of the variables that are not set. */
void setVariablePositions(const std::vector<std::string>& variable_names,
const std::vector<double>& variable_position);
/** \brief Set the position of a single variable. An exception is thrown if the variable name is not known */
void setVariablePosition(const std::string& variable, double value)
{
setVariablePosition(robot_model_->getVariableIndex(variable), value);
}
/** \brief Set the position of a single variable. The variable is specified by its index (a value associated by the
* RobotModel to each variable) */
void setVariablePosition(int index, double value)
{
position_[index] = value;
const JointModel* jm = robot_model_->getJointOfVariable(index);
if (jm)
{
markDirtyJointTransforms(jm);
updateMimicJoint(jm);
}
}
/** \brief Get the position of a particular variable. An exception is thrown if the variable is not known. */
double getVariablePosition(const std::string& variable) const
{
return position_[robot_model_->getVariableIndex(variable)];
}
/** \brief Get the position of a particular variable. The variable is
specified by its index. No checks are performed for the validity
of the index passed */
double getVariablePosition(int index) const
{
return position_[index];
}
/** @} */
/** \name Getting and setting variable velocity
* @{
*/
/** \brief By default, if velocities are never set or initialized,
the state remembers that there are no velocities set. This is
useful to know when serializing or copying the state.*/
bool hasVelocities() const
{
return has_velocity_;
}
/** \brief Get raw access to the velocities of the variables that make up this state. The values are in the same order
* as reported by getVariableNames() */
double* getVariableVelocities()
{
markVelocity();
return velocity_;
}
/** \brief Get const access to the velocities of the variables that make up this state. The values are in the same
* order as reported by getVariableNames() */
const double* getVariableVelocities() const
{
return velocity_;
}
/** \brief Set all velocities to 0.0 */
void zeroVelocities();
/** \brief Given an array with velocity values for all variables, set those values as the velocities in this state */
void setVariableVelocities(const double* velocity)
{
has_velocity_ = true;
// assume everything is in order in terms of array lengths (for efficiency reasons)
memcpy(velocity_, velocity, robot_model_->getVariableCount() * sizeof(double));
}
/** \brief Given an array with velocity values for all variables, set those values as the velocities in this state */
void setVariableVelocities(const std::vector<double>& velocity)
{
assert(robot_model_->getVariableCount() <= velocity.size()); // checked only in debug mode
setVariableVelocities(&velocity[0]);
}
/** \brief Set the velocities of a set of variables. If unknown variable names are specified, an exception is thrown.
*/
void setVariableVelocities(const std::map<std::string, double>& variable_map);
/** \brief Set the velocities of a set of variables. If unknown variable names are specified, an exception is thrown.
Additionally, \e missing_variables is filled with the names of the variables that are not set. */
void setVariableVelocities(const std::map<std::string, double>& variable_map,
std::vector<std::string>& missing_variables);
/** \brief Set the velocities of a set of variables. If unknown variable names are specified, an exception is thrown.
*/
void setVariableVelocities(const std::vector<std::string>& variable_names,
const std::vector<double>& variable_velocity);
/** \brief Set the velocity of a variable. If an unknown variable name is specified, an exception is thrown. */
void setVariableVelocity(const std::string& variable, double value)
{
setVariableVelocity(robot_model_->getVariableIndex(variable), value);
}
/** \brief Set the velocity of a single variable. The variable is specified by its index (a value associated by the
* RobotModel to each variable) */
void setVariableVelocity(int index, double value)
{
markVelocity();
velocity_[index] = value;
}
/** \brief Get the velocity of a particular variable. An exception is thrown if the variable is not known. */
double getVariableVelocity(const std::string& variable) const
{
return velocity_[robot_model_->getVariableIndex(variable)];
}
/** \brief Get the velocity of a particular variable. The variable is
specified by its index. No checks are performed for the validity
of the index passed */
double getVariableVelocity(int index) const
{
return velocity_[index];
}
/** \brief Remove velocities from this state (this differs from setting them to zero) */
void dropVelocities();
/** @} */
/** \name Getting and setting variable acceleration
* @{
*/
/** \brief By default, if accelerations are never set or initialized, the state remembers that there are no
accelerations set. This is
useful to know when serializing or copying the state. If hasAccelerations() reports true, hasEffort() will
certainly report false. */
bool hasAccelerations() const
{
return has_acceleration_;
}
/** \brief Get raw access to the accelerations of the variables that make up this state. The values are in the same
* order as reported by getVariableNames(). The area of memory overlaps with effort (effort and acceleration should
* not be set at the same time) */
double* getVariableAccelerations()
{
markAcceleration();
return acceleration_;
}
/** \brief Get const raw access to the accelerations of the variables that make up this state. The values are in the
* same order as reported by getVariableNames() */
const double* getVariableAccelerations() const
{
return acceleration_;
}
/** \brief Set all accelerations to 0.0 */
void zeroAccelerations();
/** \brief Given an array with acceleration values for all variables, set those values as the accelerations in this
* state */
void setVariableAccelerations(const double* acceleration)
{
has_acceleration_ = true;
has_effort_ = false;
// assume everything is in order in terms of array lengths (for efficiency reasons)
memcpy(acceleration_, acceleration, robot_model_->getVariableCount() * sizeof(double));
}
/** \brief Given an array with acceleration values for all variables, set those values as the accelerations in this
* state */
void setVariableAccelerations(const std::vector<double>& acceleration)
{
assert(robot_model_->getVariableCount() <= acceleration.size()); // checked only in debug mode
setVariableAccelerations(&acceleration[0]);
}
/** \brief Set the accelerations of a set of variables. If unknown variable names are specified, an exception is
* thrown. */
void setVariableAccelerations(const std::map<std::string, double>& variable_map);
/** \brief Set the accelerations of a set of variables. If unknown variable names are specified, an exception is
thrown.
Additionally, \e missing_variables is filled with the names of the variables that are not set. */
void setVariableAccelerations(const std::map<std::string, double>& variable_map,
std::vector<std::string>& missing_variables);
/** \brief Set the accelerations of a set of variables. If unknown variable names are specified, an exception is
* thrown. */
void setVariableAccelerations(const std::vector<std::string>& variable_names,
const std::vector<double>& variable_acceleration);
/** \brief Set the acceleration of a variable. If an unknown variable name is specified, an exception is thrown. */
void setVariableAcceleration(const std::string& variable, double value)
{
setVariableAcceleration(robot_model_->getVariableIndex(variable), value);
}
/** \brief Set the acceleration of a single variable. The variable is specified by its index (a value associated by
* the RobotModel to each variable) */
void setVariableAcceleration(int index, double value)
{
markAcceleration();
acceleration_[index] = value;
}
/** \brief Get the acceleration of a particular variable. An exception is thrown if the variable is not known. */
double getVariableAcceleration(const std::string& variable) const
{
return acceleration_[robot_model_->getVariableIndex(variable)];
}
/** \brief Get the acceleration of a particular variable. The variable is
specified by its index. No checks are performed for the validity
of the index passed */
double getVariableAcceleration(int index) const
{
return acceleration_[index];
}
/** \brief Remove accelerations from this state (this differs from setting them to zero) */
void dropAccelerations();
/** @} */
/** \name Getting and setting variable effort
* @{
*/
/** \brief By default, if effort is never set or initialized, the state remembers that there is no effort set. This is
useful to know when serializing or copying the state. If hasEffort() reports true, hasAccelerations() will
certainly report false. */
bool hasEffort() const
{
return has_effort_;
}
/** \brief Get raw access to the effort of the variables that make up this state. The values are in the same order as
* reported by getVariableNames(). The area of memory overlaps with accelerations (effort and acceleration should not
* be set at the same time) */
double* getVariableEffort()
{
markEffort();
return effort_;
}
/** \brief Get const raw access to the effort of the variables that make up this state. The values are in the same
* order as reported by getVariableNames(). */
const double* getVariableEffort() const
{
return effort_;
}
/** \brief Set all effort values to 0.0 */
void zeroEffort();
/** \brief Given an array with effort values for all variables, set those values as the effort in this state */
void setVariableEffort(const double* effort)
{
has_effort_ = true;
has_acceleration_ = false;
// assume everything is in order in terms of array lengths (for efficiency reasons)
memcpy(effort_, effort, robot_model_->getVariableCount() * sizeof(double));
}
/** \brief Given an array with effort values for all variables, set those values as the effort in this state */
void setVariableEffort(const std::vector<double>& effort)
{
assert(robot_model_->getVariableCount() <= effort.size()); // checked only in debug mode
setVariableEffort(&effort[0]);
}
/** \brief Set the effort of a set of variables. If unknown variable names are specified, an exception is thrown. */
void setVariableEffort(const std::map<std::string, double>& variable_map);
/** \brief Set the effort of a set of variables. If unknown variable names are specified, an exception is thrown.
Additionally, \e missing_variables is filled with the names of the variables that are not set. */
void setVariableEffort(const std::map<std::string, double>& variable_map, std::vector<std::string>& missing_variables);
/** \brief Set the effort of a set of variables. If unknown variable names are specified, an exception is thrown. */
void setVariableEffort(const std::vector<std::string>& variable_names,
const std::vector<double>& variable_acceleration);
/** \brief Set the effort of a variable. If an unknown variable name is specified, an exception is thrown. */
void setVariableEffort(const std::string& variable, double value)
{
setVariableEffort(robot_model_->getVariableIndex(variable), value);
}
/** \brief Set the effort of a single variable. The variable is specified by its index (a value associated by the
* RobotModel to each variable) */
void setVariableEffort(int index, double value)
{
markEffort();
effort_[index] = value;
}
/** \brief Get the effort of a particular variable. An exception is thrown if the variable is not known. */
double getVariableEffort(const std::string& variable) const
{
return effort_[robot_model_->getVariableIndex(variable)];
}
/** \brief Get the effort of a particular variable. The variable is
specified by its index. No checks are performed for the validity
of the index passed */
double getVariableEffort(int index) const
{
return effort_[index];
}
/** \brief Remove effort values from this state (this differs from setting them to zero) */
void dropEffort();
/** \brief Reduce RobotState to kinematic information (remove velocity, acceleration and effort, if present) */
void dropDynamics();
/** \brief Invert velocity if present. */
void invertVelocity();
/** @} */
/** \name Getting and setting joint positions, velocities, accelerations and effort for a single joint
* The joint might be multi-DOF, i.e. require more than one variable to set.
* See setVariablePositions(), setVariableVelocities(), setVariableEffort() to handle multiple joints.
* @{
*/
void setJointPositions(const std::string& joint_name, const double* position)
{
setJointPositions(robot_model_->getJointModel(joint_name), position);
}
void setJointPositions(const std::string& joint_name, const std::vector<double>& position)
{
setJointPositions(robot_model_->getJointModel(joint_name), &position[0]);
}
void setJointPositions(const JointModel* joint, const std::vector<double>& position)
{
setJointPositions(joint, &position[0]);
}
void setJointPositions(const JointModel* joint, const double* position)
{
memcpy(position_ + joint->getFirstVariableIndex(), position, joint->getVariableCount() * sizeof(double));
markDirtyJointTransforms(joint);
updateMimicJoint(joint);
}
void setJointPositions(const std::string& joint_name, const Eigen::Isometry3d& transform)
{
setJointPositions(robot_model_->getJointModel(joint_name), transform);
}
void setJointPositions(const JointModel* joint, const Eigen::Isometry3d& transform)
{
joint->computeVariablePositions(transform, position_ + joint->getFirstVariableIndex());
markDirtyJointTransforms(joint);
updateMimicJoint(joint);
}
void setJointVelocities(const JointModel* joint, const double* velocity)
{
has_velocity_ = true;
memcpy(velocity_ + joint->getFirstVariableIndex(), velocity, joint->getVariableCount() * sizeof(double));
}
void setJointEfforts(const JointModel* joint, const double* effort);
const double* getJointPositions(const std::string& joint_name) const
{
return getJointPositions(robot_model_->getJointModel(joint_name));
}
const double* getJointPositions(const JointModel* joint) const
{
return position_ + joint->getFirstVariableIndex();
}
const double* getJointVelocities(const std::string& joint_name) const
{
return getJointVelocities(robot_model_->getJointModel(joint_name));
}
const double* getJointVelocities(const JointModel* joint) const
{
return velocity_ + joint->getFirstVariableIndex();
}
const double* getJointAccelerations(const std::string& joint_name) const
{
return getJointAccelerations(robot_model_->getJointModel(joint_name));
}
const double* getJointAccelerations(const JointModel* joint) const
{
return acceleration_ + joint->getFirstVariableIndex();
}
const double* getJointEffort(const std::string& joint_name) const
{
return getJointEffort(robot_model_->getJointModel(joint_name));
}
const double* getJointEffort(const JointModel* joint) const
{
return effort_ + joint->getFirstVariableIndex();
}
/** @} */
/** \name Getting and setting group positions
* @{
*/
/** \brief Given positions for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupPositions(const std::string& joint_group_name, const double* gstate)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
setJointGroupPositions(jmg, gstate);
}
/** \brief Given positions for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupPositions(const std::string& joint_group_name, const std::vector<double>& gstate)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
{
assert(gstate.size() == jmg->getVariableCount());
setJointGroupPositions(jmg, &gstate[0]);
}
}
/** \brief Given positions for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupPositions(const JointModelGroup* group, const std::vector<double>& gstate)
{
assert(gstate.size() == group->getVariableCount());
setJointGroupPositions(group, &gstate[0]);
}
/** \brief Given positions for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupPositions(const JointModelGroup* group, const double* gstate);
/** \brief Given positions for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupPositions(const std::string& joint_group_name, const Eigen::VectorXd& values)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
{
assert(values.size() == jmg->getVariableCount());
setJointGroupPositions(jmg, values);
}
}
/** \brief Given positions for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupPositions(const JointModelGroup* group, const Eigen::VectorXd& values);
/** \brief Given positions for the variables of active joints that make up a group,
* in the order found in the group (excluding values of mimic joints), set those
* as the new values that correspond to the group */
void setJointGroupActivePositions(const JointModelGroup* group, const std::vector<double>& gstate);
/** \brief Given positions for the variables of active joints that make up a group,
* in the order found in the group (excluding values of mimic joints), set those
* as the new values that correspond to the group */
void setJointGroupActivePositions(const std::string& joint_group_name, const std::vector<double>& gstate)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
{
assert(gstate.size() == jmg->getActiveVariableCount());
setJointGroupActivePositions(jmg, gstate);
}
}
/** \brief Given positions for the variables of active joints that make up a group,
* in the order found in the group (excluding values of mimic joints), set those
* as the new values that correspond to the group */
void setJointGroupActivePositions(const JointModelGroup* group, const Eigen::VectorXd& values);
/** \brief Given positions for the variables of active joints that make up a group,
* in the order found in the group (excluding values of mimic joints), set those
* as the new values that correspond to the group */
void setJointGroupActivePositions(const std::string& joint_group_name, const Eigen::VectorXd& values)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
{
assert(values.size() == jmg->getActiveVariableCount());
setJointGroupActivePositions(jmg, values);
}
}
/** \brief For a given group, copy the position values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupPositions(const std::string& joint_group_name, std::vector<double>& gstate) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
{
gstate.resize(jmg->getVariableCount());
copyJointGroupPositions(jmg, &gstate[0]);
}
}
/** \brief For a given group, copy the position values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupPositions(const std::string& joint_group_name, double* gstate) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
copyJointGroupPositions(jmg, gstate);
}
/** \brief For a given group, copy the position values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupPositions(const JointModelGroup* group, std::vector<double>& gstate) const
{
gstate.resize(group->getVariableCount());
copyJointGroupPositions(group, &gstate[0]);
}
/** \brief For a given group, copy the position values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupPositions(const JointModelGroup* group, double* gstate) const;
/** \brief For a given group, copy the position values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupPositions(const std::string& joint_group_name, Eigen::VectorXd& values) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
copyJointGroupPositions(jmg, values);
}
/** \brief For a given group, copy the position values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupPositions(const JointModelGroup* group, Eigen::VectorXd& values) const;
/** @} */
/** \name Getting and setting group velocities
* @{
*/
/** \brief Given velocities for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupVelocities(const std::string& joint_group_name, const double* gstate)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
setJointGroupVelocities(jmg, gstate);
}
/** \brief Given velocities for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupVelocities(const std::string& joint_group_name, const std::vector<double>& gstate)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
setJointGroupVelocities(jmg, &gstate[0]);
}
/** \brief Given velocities for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupVelocities(const JointModelGroup* group, const std::vector<double>& gstate)
{
setJointGroupVelocities(group, &gstate[0]);
}
/** \brief Given velocities for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupVelocities(const JointModelGroup* group, const double* gstate);
/** \brief Given velocities for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupVelocities(const std::string& joint_group_name, const Eigen::VectorXd& values)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
setJointGroupVelocities(jmg, values);
}
/** \brief Given velocities for the variables that make up a group, in the order found in the group (including values
* of mimic joints), set those as the new values that correspond to the group */
void setJointGroupVelocities(const JointModelGroup* group, const Eigen::VectorXd& values);
/** \brief For a given group, copy the velocity values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupVelocities(const std::string& joint_group_name, std::vector<double>& gstate) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
{
gstate.resize(jmg->getVariableCount());
copyJointGroupVelocities(jmg, &gstate[0]);
}
}
/** \brief For a given group, copy the velocity values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupVelocities(const std::string& joint_group_name, double* gstate) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
copyJointGroupVelocities(jmg, gstate);
}
/** \brief For a given group, copy the velocity values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupVelocities(const JointModelGroup* group, std::vector<double>& gstate) const
{
gstate.resize(group->getVariableCount());
copyJointGroupVelocities(group, &gstate[0]);
}
/** \brief For a given group, copy the velocity values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupVelocities(const JointModelGroup* group, double* gstate) const;
/** \brief For a given group, copy the velocity values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupVelocities(const std::string& joint_group_name, Eigen::VectorXd& values) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
copyJointGroupVelocities(jmg, values);
}
/** \brief For a given group, copy the velocity values of the variables that make up the group into another location,
* in the order that the variables are found in the group. This is not necessarily a contiguous block of memory in the
* RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupVelocities(const JointModelGroup* group, Eigen::VectorXd& values) const;
/** @} */
/** \name Getting and setting group accelerations
* @{
*/
/** \brief Given accelerations for the variables that make up a group, in the order found in the group (including
* values of mimic joints), set those as the new values that correspond to the group */
void setJointGroupAccelerations(const std::string& joint_group_name, const double* gstate)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
setJointGroupAccelerations(jmg, gstate);
}
/** \brief Given accelerations for the variables that make up a group, in the order found in the group (including
* values of mimic joints), set those as the new values that correspond to the group */
void setJointGroupAccelerations(const std::string& joint_group_name, const std::vector<double>& gstate)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
setJointGroupAccelerations(jmg, &gstate[0]);
}
/** \brief Given accelerations for the variables that make up a group, in the order found in the group (including
* values of mimic joints), set those as the new values that correspond to the group */
void setJointGroupAccelerations(const JointModelGroup* group, const std::vector<double>& gstate)
{
setJointGroupAccelerations(group, &gstate[0]);
}
/** \brief Given accelerations for the variables that make up a group, in the order found in the group (including
* values of mimic joints), set those as the new values that correspond to the group */
void setJointGroupAccelerations(const JointModelGroup* group, const double* gstate);
/** \brief Given accelerations for the variables that make up a group, in the order found in the group (including
* values of mimic joints), set those as the new values that correspond to the group */
void setJointGroupAccelerations(const std::string& joint_group_name, const Eigen::VectorXd& values)
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
setJointGroupAccelerations(jmg, values);
}
/** \brief Given accelerations for the variables that make up a group, in the order found in the group (including
* values of mimic joints), set those as the new values that correspond to the group */
void setJointGroupAccelerations(const JointModelGroup* group, const Eigen::VectorXd& values);
/** \brief For a given group, copy the acceleration values of the variables that make up the group into another
* location, in the order that the variables are found in the group. This is not necessarily a contiguous block of
* memory in the RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupAccelerations(const std::string& joint_group_name, std::vector<double>& gstate) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
{
gstate.resize(jmg->getVariableCount());
copyJointGroupAccelerations(jmg, &gstate[0]);
}
}
/** \brief For a given group, copy the acceleration values of the variables that make up the group into another
* location, in the order that the variables are found in the group. This is not necessarily a contiguous block of
* memory in the RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupAccelerations(const std::string& joint_group_name, double* gstate) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
copyJointGroupAccelerations(jmg, gstate);
}
/** \brief For a given group, copy the acceleration values of the variables that make up the group into another
* location, in the order that the variables are found in the group. This is not necessarily a contiguous block of
* memory in the RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupAccelerations(const JointModelGroup* group, std::vector<double>& gstate) const
{
gstate.resize(group->getVariableCount());
copyJointGroupAccelerations(group, &gstate[0]);
}
/** \brief For a given group, copy the acceleration values of the variables that make up the group into another
* location, in the order that the variables are found in the group. This is not necessarily a contiguous block of
* memory in the RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupAccelerations(const JointModelGroup* group, double* gstate) const;
/** \brief For a given group, copy the acceleration values of the variables that make up the group into another
* location, in the order that the variables are found in the group. This is not necessarily a contiguous block of
* memory in the RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupAccelerations(const std::string& joint_group_name, Eigen::VectorXd& values) const
{
const JointModelGroup* jmg = robot_model_->getJointModelGroup(joint_group_name);
if (jmg)
copyJointGroupAccelerations(jmg, values);
}
/** \brief For a given group, copy the acceleration values of the variables that make up the group into another
* location, in the order that the variables are found in the group. This is not necessarily a contiguous block of
* memory in the RobotState itself, so we copy instead of returning a pointer.*/
void copyJointGroupAccelerations(const JointModelGroup* group, Eigen::VectorXd& values) const;
/** @} */
/** \name Setting from Inverse Kinematics
* @{
*/
/** \brief If the group this state corresponds to is a chain and a solver is available, then the joint values can be
set by computing inverse kinematics.
The pose is assumed to be in the reference frame of the kinematic model. Returns true on success.
@param pose The pose the last link in the chain needs to achieve
@param timeout The timeout passed to the kinematics solver on each attempt
@param constraint A state validity constraint to be required for IK solutions */
bool setFromIK(const JointModelGroup* group, const geometry_msgs::msg::Pose& pose, double timeout = 0.0,
const GroupStateValidityCallbackFn& constraint = GroupStateValidityCallbackFn(),
const kinematics::KinematicsQueryOptions& options = kinematics::KinematicsQueryOptions(),
const kinematics::KinematicsBase::IKCostFn& cost_function = kinematics::KinematicsBase::IKCostFn());
/** \brief If the group this state corresponds to is a chain and a solver is available, then the joint values can be
set by computing inverse kinematics.
The pose is assumed to be in the reference frame of the kinematic model. Returns true on success.
@param pose The pose the \e tip link in the chain needs to achieve
@param tip The name of the link the pose is specified for
@param timeout The timeout passed to the kinematics solver on each attempt
@param constraint A state validity constraint to be required for IK solutions */
bool setFromIK(const JointModelGroup* group, const geometry_msgs::msg::Pose& pose, const std::string& tip,
double timeout = 0.0, const GroupStateValidityCallbackFn& constraint = GroupStateValidityCallbackFn(),
const kinematics::KinematicsQueryOptions& options = kinematics::KinematicsQueryOptions(),
const kinematics::KinematicsBase::IKCostFn& cost_function = kinematics::KinematicsBase::IKCostFn());
/** \brief If the group this state corresponds to is a chain and a solver is available, then the joint values can be
set by computing inverse kinematics.
The pose is assumed to be in the reference frame of the kinematic model. Returns true on success.
@param pose The pose the last link in the chain needs to achieve
@param tip The name of the link the pose is specified for
@param timeout The timeout passed to the kinematics solver on each attempt */
bool setFromIK(const JointModelGroup* group, const Eigen::Isometry3d& pose, double timeout = 0.0,
const GroupStateValidityCallbackFn& constraint = GroupStateValidityCallbackFn(),
const kinematics::KinematicsQueryOptions& options = kinematics::KinematicsQueryOptions(),
const kinematics::KinematicsBase::IKCostFn& cost_function = kinematics::KinematicsBase::IKCostFn());
/** \brief If the group this state corresponds to is a chain and a solver is available, then the joint values can be
set by computing inverse kinematics.
The pose is assumed to be in the reference frame of the kinematic model. Returns true on success.
@param pose The pose the last link in the chain needs to achieve
@param timeout The timeout passed to the kinematics solver on each attempt
@param constraint A state validity constraint to be required for IK solutions */
bool setFromIK(const JointModelGroup* group, const Eigen::Isometry3d& pose, const std::string& tip,
double timeout = 0.0, const GroupStateValidityCallbackFn& constraint = GroupStateValidityCallbackFn(),
const kinematics::KinematicsQueryOptions& options = kinematics::KinematicsQueryOptions(),
const kinematics::KinematicsBase::IKCostFn& cost_function = kinematics::KinematicsBase::IKCostFn());
/** \brief If the group this state corresponds to is a chain and a solver is available, then the joint values can be
set by computing inverse kinematics.
The pose is assumed to be in the reference frame of the kinematic model. Returns true on success.
@param pose The pose the last link in the chain needs to achieve
@param tip The name of the frame for which IK is attempted.
@param consistency_limits This specifies the desired distance between the solution and the seed state
@param timeout The timeout passed to the kinematics solver on each attempt
@param constraint A state validity constraint to be required for IK solutions */
bool setFromIK(const JointModelGroup* group, const Eigen::Isometry3d& pose, const std::string& tip,
const std::vector<double>& consistency_limits, double timeout = 0.0,