Skip to content

Commit d51e98a

Browse files
committed
initial import
1 parent 5c768c9 commit d51e98a

File tree

6 files changed

+174
-0
lines changed

6 files changed

+174
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build
2+
dist
3+
*.egg-info
4+
*.pyc

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Utility command to dump/undump pose of objects in gazebo
2+
3+
Install
4+
-------
5+
6+
```
7+
pip install git+https://github.com/devrt/gzdump
8+
```
9+
10+
Usage
11+
-----
12+
13+
```
14+
gzdump [--base-frame world]
15+
```
16+
17+
Dump all the objects in the simulation world in [name, x, y, z, r, p, y] format (in meters, degrees).
18+
19+
```
20+
gzundump [--base-frame world] [--offset-x 0] [--offset-y 0] [--offset-z 0]
21+
```
22+
23+
Undump objects pose from stdin in [name, x, y, z, r, p, y] format (in meters, degrees).
24+
25+
Example
26+
-------
27+
28+
```
29+
gzdump > poses.txt
30+
```
31+
32+
Save current poses to the file.
33+
34+
```
35+
gzdump | gzundump --offset-z -1
36+
```
37+
38+
Add one meters offset along with Z axes to all the objects in the world.
39+
40+
License
41+
-------
42+
43+
MIT
44+
45+
Author
46+
------
47+
48+
Yosuke Matsusaka

gzdump/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from dump import dump
2+
from undump import undump

gzdump/dump.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Utility command to dump/undump pose of objects in gazebo
2+
# written by Yosuke Matsusaka
3+
# distributed under MIT License
4+
import rospy
5+
import math
6+
import argparse
7+
from tf import transformations
8+
from gazebo_msgs.srv import GetWorldProperties, GetModelState
9+
10+
def main():
11+
parser = argparse.ArgumentParser(description='Dump object pose.')
12+
parser.add_argument('--base-frame', dest='base_frame',
13+
type=str, default='world',
14+
help='base frame (default: world)')
15+
args = parser.parse_args()
16+
dump(args)
17+
18+
def dump(opts):
19+
rospy.wait_for_service('/gazebo/get_world_properties')
20+
rospy.wait_for_service('/gazebo/get_model_state')
21+
world_propertiies = rospy.ServiceProxy('/gazebo/get_world_properties', GetWorldProperties)
22+
model_state = rospy.ServiceProxy('/gazebo/get_model_state', GetModelState)
23+
24+
for name in world_propertiies().model_names:
25+
pose = model_state(name, opts.base_frame).pose
26+
quaternion = (
27+
pose.orientation.x,
28+
pose.orientation.y,
29+
pose.orientation.z,
30+
pose.orientation.w
31+
)
32+
euler = map(math.degrees, transformations.euler_from_quaternion(quaternion))
33+
print(','.join(map(str,[
34+
name,
35+
pose.position.x,
36+
pose.position.y,
37+
pose.position.z,
38+
euler[0],
39+
euler[1],
40+
euler[2]
41+
])))

gzdump/undump.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Utility command to dump/undump pose of objects in gazebo
2+
# written by Yosuke Matsusaka
3+
# distributed under MIT License
4+
import sys
5+
import rospy
6+
import math
7+
import argparse
8+
from tf import transformations
9+
from gazebo_msgs.msg import ModelState
10+
from gazebo_msgs.srv import SetModelState
11+
12+
def main():
13+
parser = argparse.ArgumentParser(description='Undump object pose.')
14+
parser.add_argument('--base-frame', dest='base_frame',
15+
type=str, default='world',
16+
help='base frame (default: world)')
17+
parser.add_argument('--offset-x', dest='offset_x',
18+
type=float, default=0,
19+
help='offset along X axis (default: 0)')
20+
parser.add_argument('--offset-y', dest='offset_y',
21+
type=float, default=0,
22+
help='offset along Y axis (default: 0)')
23+
parser.add_argument('--offset-z', dest='offset_z',
24+
type=float, default=0,
25+
help='offset along Z axis (default: 0)')
26+
args = parser.parse_args()
27+
undump(args)
28+
29+
def undump(opts):
30+
rospy.wait_for_service('/gazebo/set_model_state')
31+
set_model_state = rospy.ServiceProxy('/gazebo/set_model_state', SetModelState)
32+
33+
for line in sys.stdin:
34+
(name, x, y, z, r, p, ay) = line.split(',')
35+
(x, y, z) = map(float, [x, y, z])
36+
(r, p, ay) = map(math.radians, map(float, [r, p, ay]))
37+
x += opts.offset_x
38+
y += opts.offset_y
39+
z += opts.offset_z
40+
quaternion = transformations.quaternion_from_euler(r, p, ay)
41+
model_state = ModelState()
42+
model_state.model_name = name
43+
model_state.reference_frame = opts.base_frame
44+
model_state.pose.position.x = x
45+
model_state.pose.position.y = y
46+
model_state.pose.position.z = z
47+
model_state.pose.orientation.x = quaternion[0]
48+
model_state.pose.orientation.y = quaternion[1]
49+
model_state.pose.orientation.z = quaternion[2]
50+
model_state.pose.orientation.w = quaternion[3]
51+
set_model_state(model_state)

setup.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import setuptools
2+
3+
with open("README.md", "r") as fh:
4+
long_description = fh.read()
5+
6+
if __name__ == "__main__":
7+
setuptools.setup(
8+
name='gzdump',
9+
version='0.0.1',
10+
author="Yosuke Matsusaka",
11+
author_email="[email protected]",
12+
description="Utility command to dump pose of objects in gazebo",
13+
long_description=long_description,
14+
long_description_content_type="text/markdown",
15+
url="https://github.com/devrt/gzdump",
16+
packages=setuptools.find_packages(),
17+
classifiers=[
18+
"Programming Language :: Python :: 2",
19+
"License :: OSI Approved :: MIT License",
20+
"Operating System :: OS Independent",
21+
],
22+
entry_points={
23+
'console_scripts': [
24+
'gzdump = gzdump.dump:main',
25+
'gzundump = gzdump.undump:main'
26+
]
27+
}
28+
)

0 commit comments

Comments
 (0)