Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bindings/ruby/bin/rock-gazebo
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if update_models
Rock::Gazebo.update_existing_models
end

Rock::Gazebo.download_missing_models(scene)
Rock::Gazebo.download_missing_models(scene, loader: SDF::ERBLoader.new)

if parse_sdf_only
args.each do |path|
Expand Down Expand Up @@ -135,4 +135,3 @@ ensure
end
end
end

12 changes: 6 additions & 6 deletions bindings/ruby/lib/rock/gazebo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def self.compute_spawn_arguments(cmd, *cmdline)
# @param [SDF::Root,String] sdf the preloaded SDF world, or a string that
# describes a SDF file (either a path, or a model:// URI)
# @return [SDF::Root]
def self.process_sdf_file(sdf)
sdf = SDF::Root.load(sdf) if sdf.respond_to?(:to_str)
def self.process_sdf_file(sdf, loader: SDF::Loader.new)
sdf = SDF::Root.load(sdf, loader: loader) if sdf.respond_to?(:to_str)
sdf
end

Expand All @@ -153,8 +153,8 @@ def self.create_rtt_loader
# describes a SDF file (either a path, or a model:// URI)
# @return [SDF::Root]
# @see process_sdf_file
def self.process_gazebo_file(sdf, loader: create_rtt_loader)
sdf = process_sdf_file(sdf)
def self.process_gazebo_file(sdf, loader: create_rtt_loader, model_loader: SDF::Loader.new)
sdf = process_sdf_file(sdf, loader: model_loader)

# post-process the rock_components info
sdf.each_world { |w| process_gazebo_world(w, loader: loader) }
Expand Down Expand Up @@ -279,8 +279,8 @@ def self.download_path=(path)
@download_path = File.expand_path(path)
end

def self.download_missing_models(world_path)
SDF::Root.load(world_path)
def self.download_missing_models(world_path, loader: SDF::Loader.new)
SDF::Root.load(world_path, loader: loader)
rescue SDF::XML::NoSuchModel => missing_model
model_name = missing_model.model_name
if !SDF::XML.model_path.include?(download_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module ConfigurationExtension
end

# Load a SDF world into the Syskit instance
def use_sdf_world(*path, world_name: nil)
def use_sdf_world(*path, world_name: nil, loader: ::SDF::Loader.new)
if Conf.sdf.world_file_path
raise LoadError, "use_sdf_world already called"
elsif Conf.sdf.has_profile_loaded?
Expand All @@ -39,7 +39,7 @@ def use_sdf_world(*path, world_name: nil)
setup_gazebo_model_path
full_path = resolve_world_path(*path)
Robot.info "loading world from #{full_path}"
Conf.sdf.load_sdf(full_path, world_name: world_name)
Conf.sdf.load_sdf(full_path, world_name: world_name, loader: loader)
end

# Add all models/sdf folders in our dependent bundles
Expand Down Expand Up @@ -97,9 +97,9 @@ def self.normalize_read_only(
def use_gazebo_world(
*path, world_name: nil, localhost: Conf.gazebo.localhost?,
read_only: false, read_only_task_models: [], logger_name: nil,
period: 0.1
period: 0.1, loader: ::SDF::Loader.new
)
world = use_sdf_world(*path, world_name: world_name)
world = use_sdf_world(*path, world_name: world_name, loader: loader)
Rock::Gazebo.process_gazebo_world(world)
deployment_model =
ConfigurationExtension.world_to_orogen(world, period: period)
Expand Down
13 changes: 7 additions & 6 deletions bindings/ruby/lib/rock_gazebo/syskit/profile_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def sdf_adapt_transformer_configuration_to_main_model(transformer)
#
# @return [SDF::Root] the root. The method already validates that
# this root has exactly one Model child
def resolve_sdf_model(*path)
def resolve_sdf_model(*path, loader: ::SDF::Loader.new)
if path.size == 1 && !path.first.respond_to?(:to_str)
# Assume this is a SDF::Model object
return path.first
Expand All @@ -74,7 +74,7 @@ def resolve_sdf_model(*path)
end
end

sdf = ::SDF::Root.load(full_path, flatten: false)
sdf = ::SDF::Root.load(full_path, flatten: false, loader: loader)
models = sdf.each_model.to_a
if models.size > 1
raise ArgumentError,
Expand All @@ -93,7 +93,7 @@ class AlreadyLoaded < ArgumentError; end
# Setup the transformer based on the given model
#
# @return [Model]
def use_sdf_model(*path, filter: nil, as: nil)
def use_sdf_model(*path, filter: nil, as: nil, loader: ::SDF::Loader.new)
if @sdf
raise AlreadyLoaded,
"SDF model already loaded, " \
Expand All @@ -107,7 +107,7 @@ def use_sdf_model(*path, filter: nil, as: nil)
# won't be configured properly
Conf.sdf.has_profile_loaded = true

@sdf = resolve_sdf_model(*path)
@sdf = resolve_sdf_model(*path, loader: loader)
@sdf_model = @sdf.each_model.first
@sdf_model.name = as if as
transformer.parse_sdf_model(@sdf_model, filter: filter)
Expand Down Expand Up @@ -173,9 +173,10 @@ def use_gazebo_model(
*path,
filter: nil, as: nil, reuse: nil,
use_world: RockGazebo::Syskit.use_gazebo_model_calls_use_gazebo_world,
prefix_device_with_name: RockGazebo::Syskit.prefix_device_with_name
prefix_device_with_name: RockGazebo::Syskit.prefix_device_with_name,
loader: ::SDF::Loader.new
)
use_sdf_model(*path, as: as, filter: filter)
use_sdf_model(*path, as: as, filter: filter, loader: loader)

model_in_world = resolve_model_in_world

Expand Down
9 changes: 4 additions & 5 deletions bindings/ruby/lib/rock_gazebo/syskit/sdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def initialize
# a world of the given name in the loaded file. Otherwise, the loaded
# file must have a single world
# @return [SDF::World]
def load_sdf(*path, world_name: nil)
def load_sdf(*path, world_name: nil, loader: ::SDF::Loader.new)
path = File.join(*path)
_, resolved_paths =
Rock::Gazebo.resolve_worldfiles_and_models_arguments([path])
full_path = resolved_paths.first
full_path = autodetect_sdf_file_path(full_path)
::SDF::XML.model_path = Rock::Gazebo.model_path
world = sdf_world_from_path(full_path, world_name: world_name)
world = sdf_world_from_path(full_path, world_name: world_name, loader: loader)
use_sdf_world(world, path: full_path)
end

Expand Down Expand Up @@ -82,9 +82,8 @@ def autodetect_sdf_file_path(path)
# world_name is not set
# @raise ArgumentError if the SDF file has more than one world and
# none match the name provided as world_name
def sdf_world_from_path(path, world_name: nil)
sdf = ::SDF::Root.load(path, flatten: false)
Rock::Gazebo.process_sdf_file(sdf)
def sdf_world_from_path(path, world_name: nil, loader: ::SDF::Loader.new)
sdf = ::SDF::Root.load(path, flatten: false, loader: loader)
worlds = sdf.each_world.to_a
if world_name
world = worlds.find { |w| w.name == world_name }
Expand Down
8 changes: 8 additions & 0 deletions bindings/ruby/test/worlds/simple_model_erb.world
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<sdf version="1.6">
<world name="test">
<include>
<name>included_model</name>
<uri>model://simple_model_erb</uri>
</include>
</world>
</sdf>