scripts
properties.py
Go to the documentation of this file.
1
#! /usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
from
moveit.task_constructor
import
core, stages
5
from
geometry_msgs.msg
import
PoseStamped
6
import
time
7
8
from
py_binding_tools
import
roscpp_init
9
10
roscpp_init(
"mtc_tutorial"
)
11
12
# [propertyTut1]
13
# Create a property
14
p = core.Property()
15
16
# Set a descriptive string to describe the properties function
17
p.setDescription(
"Foo Property"
)
18
# [propertyTut1]
19
20
# Set the current and the default value
21
p.setValue(
"Bar"
)
22
23
# [propertyTut2]
24
# Check if the property is defined
25
assert
p.defined()
26
# [propertyTut2]
27
28
# [propertyTut3]
29
# Retrieve the stored value
30
print(p.value())
31
32
# Retrieve the default value
33
print(p.defaultValue())
34
35
# Retrieve the description
36
print(p.description())
37
# [propertyTut3]
38
39
# [propertyTut4]
40
# Create a property map
41
pm = core.PropertyMap()
42
props = {
"prop1"
:
"test"
,
"prop2"
: 21,
"prop3"
: PoseStamped(),
"prop4"
: 5.4}
43
pm.update(props)
44
# [propertyTut4]
45
46
# [propertyTut5]
47
# Add a property to the property map using the pythonic way
48
pm[
"prop5"
] = 2
49
# [propertyTut5]
50
51
# [propertyTut6]
52
# Return the value of a property
53
print(pm[
"prop5"
])
54
# [propertyTut6]
55
56
# [propertyTut7]
57
# Return the underlying property object
58
p2 = pm.property(
"prop5"
)
59
# [propertyTut7]
60
61
# [propertyTut8]
62
# Iterate through all the values in the property map
63
print(
"\n"
)
64
for
i
in
pm:
65
print(i,
"\t\t"
, pm[i])
66
print(
"\n"
)
67
# [propertyTut8]
68
69
# [propertyTut9]
70
# A new property map can also be configured using an existing one
71
# You can also only use a subset of the properties that should be configured.
72
pm2 = core.PropertyMap()
73
pm.exposeTo(pm2, [
"prop2"
,
"prop4"
])
74
# [propertyTut9]
75
76
# Lets test that by printing out our properties
77
for
i
in
pm2:
78
print(i,
"\t\t"
, pm2[i])
79
print(
"\n"
)
80
81
# [propertyTut10]
82
# Create a stage
83
stage = stages.CurrentState(
"Current State"
)
84
# Access the property map of the stage
85
props = stage.properties
86
# [propertyTut10]
moveit::task_constructor
demo
Author(s): Robert Haschke
, Simon Goldstein
, Henning Kayser
autogenerated on Sat May 3 2025 02:40:30