Commit 52ccacc4 authored by Johannes Barthel's avatar Johannes Barthel
Browse files

adjust scripts to handle maize, start fixing models

parent 951596eb
...@@ -53,3 +53,5 @@ CATKIN_IGNORE ...@@ -53,3 +53,5 @@ CATKIN_IGNORE
# generated files # generated files
generated.world generated.world
.ipynb_checkpoints .ipynb_checkpoints
**__pycache__**
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -24,7 +24,7 @@ if __name__ == "__main__": ...@@ -24,7 +24,7 @@ if __name__ == "__main__":
pk = Pumpkin2DGenerator(**args) pk = Pumpkin2DGenerator(**args)
# generate the template and write it to a file # generate the template and write it to a file
pkg_path = rospkg.RosPack().get_path('dschubba_gazebo') pkg_path = rospkg.RosPack().get_path('kamaro_world')
template_path = os.path.join(pkg_path, "scripts/pumpkin.world.template") template_path = os.path.join(pkg_path, "scripts/pumpkin.world.template")
template = open(template_path).read() template = open(template_path).read()
generated_sdf = pk.render_to_template(template) generated_sdf = pk.render_to_template(template)
......
...@@ -3,6 +3,9 @@ import numpy as np ...@@ -3,6 +3,9 @@ import numpy as np
import os import os
import rospkg import rospkg
AVAILABLE_TYPES = ["pumpkin_01", "pumpkin_02", "pumpkin_03", "cylinder", "maize_01", "maize_02", "beans_01"]
class Pumpkin2DGenerator(): class Pumpkin2DGenerator():
def __init__(self, def __init__(self,
pumpkin_radius = .15, pumpkin_radius = .15,
...@@ -15,7 +18,8 @@ class Pumpkin2DGenerator(): ...@@ -15,7 +18,8 @@ class Pumpkin2DGenerator():
pumpkin_height = 0.3, pumpkin_height = 0.3,
pumpkin_mass = 5.0, pumpkin_mass = 5.0,
radius_noise_range = 0.05, radius_noise_range = 0.05,
seed = None): seed = None,
types=",".join(AVAILABLE_TYPES)):
for k,v in locals().items(): for k,v in locals().items():
self.__setattr__(k,v) self.__setattr__(k,v)
...@@ -78,7 +82,12 @@ class Pumpkin2DGenerator(): ...@@ -78,7 +82,12 @@ class Pumpkin2DGenerator():
def render_to_template(self, template): def render_to_template(self, template):
def into_dict(xy, radius, height, mass, index): def into_dict(xy, radius, height, mass, index):
types = ["pumpkin_01", "pumpkin_02", "pumpkin_03", "pumpkin_04", "cylinder"] types = []
for t in self.types.split(","):
if t in AVAILABLE_TYPES:
types.append(t)
else:
print("Error: model type", t, "is not available.")
coordinate = dict() coordinate = dict()
coordinate["type"] = np.random.choice(types) coordinate["type"] = np.random.choice(types)
inertia = dict() inertia = dict()
...@@ -93,7 +102,8 @@ class Pumpkin2DGenerator(): ...@@ -93,7 +102,8 @@ class Pumpkin2DGenerator():
if coordinate["type"] == "cylinder": if coordinate["type"] == "cylinder":
coordinate["height"] = height coordinate["height"] = height
coordinate["name"] = "{}_{:04d}".format(coordinate["type"], index) coordinate["name"] = "{}_{:04d}".format(coordinate["type"], index)
coordinate["yaw"] = np.random.rand() * 2.0 * np.pi
return coordinate return coordinate
coordinates = [into_dict(row,self.pumpkin_radius, self.pumpkin_height, self.pumpkin_mass, i) for i, row in enumerate(self.pumpkins.T[:,:-1])] coordinates = [into_dict(row,self.pumpkin_radius, self.pumpkin_height, self.pumpkin_mass, i) for i, row in enumerate(self.pumpkins.T[:,:-1])]
template = jinja2.Template(template) template = jinja2.Template(template)
return template.render(coordinates=coordinates, package_path=rospkg.RosPack().get_path('dschubba_gazebo')) return template.render(coordinates=coordinates, package_path=rospkg.RosPack().get_path('kamaro_world'))
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment