Modelling and instance-level functionality for devices
Devices are, in the Orocos/Roby plugin, the tools that allow to represent the inputs and outputs of your component network, i.e. the components that are tied to "something" (usually hardware) that is not represented in the component network.
New devices can either be created with device_model.new_submodel if the source should not be registered in the system model, or Orocos::RobyPlugin::SystemModel#device_type if it should be registered
Enumerates the MasterDeviceInstance and/or SlaveDeviceInstance objects that are mapped to this task context
It yields the data service and the device model
See also #each_device_name
# File lib/orocos/roby/data_sources.rb, line 882 def each_device if !block_given? return enum_for(:each_device) end each_master_device do |srv, device| yield(srv, device) device.each_slave do |_, slave| yield(slave.service, slave) end end end
Enumerates the devices that are mapped to this component
It yields the data service and the device model
# File lib/orocos/roby/data_sources.rb, line 857 def each_device_name if !block_given? return enum_for(:each_device_name) end seen = Set.new model.each_master_device do |srv| # Slave devices have the same name than the master device, # so no need to list them next if !srv.master? device_name = arguments["#{srv.name}_name"] if device_name && !seen.include?(device_name) seen << device_name yield(srv, device_name) end end end
Enumerates the MasterDeviceInstance objects associated with this task context
It yields the data service and the device model
See also #each_device_name
# File lib/orocos/roby/data_sources.rb, line 902 def each_master_device if !block_given? return enum_for(:each_master_device) end each_device_name do |service, device_name| if !(device = robot.devices[device_name]) raise SpecError, "#{self} attaches device #{device_name} to #{service.full_name}, but #{device_name} is not a known device" end yield(service, device) end end
Enumerates the devices that are slaves to the service called
master_service_name
# File lib/orocos/roby/data_sources.rb, line 918 def each_slave_device(master_service_name, expected_device_model = nil) # :yield:slave_service_name, slave_device srv = model.find_data_service(master_service_name) if !srv raise ArgumentError, "#{model.short_name} has no service called #{master_service_name}" end master_device_name = arguments["#{srv.name}_name"] if master_device_name if !(master_device = robot.devices[master_device_name]) raise SpecError, "#{self} attaches device #{device_name} to #{service.full_name}, but #{device_name} is not a known device" end master_device.each_slave do |slave_name, slave_device| if !expected_device_model || slave_device.device_model.fullfills?(expected_device_model) yield("#{srv.name}.#{slave_name}", slave_device) end end end end
Returns either the MasterDeviceInstance or SlaveDeviceInstance that represents the device tied to this component.
If subname is given, it has to be the corresponding data
service name. It is optional only if there is only one device attached to
this component
# File lib/orocos/roby/data_sources.rb, line 944 def robot_device(subname = nil) devices = each_master_device.to_a if !subname if devices.empty? raise ArgumentError, "#{self} is not attached to any device" elsif devices.size > 1 raise ArgumentError, "#{self} handles more than one device, you must specify one explicitely" end else devices = devices.find_all { |srv, _| srv.full_name == subname } if devices.empty? raise ArgumentError, "there is no data service called #{subname} on #{self}" end end service, device_instance = devices.first device_instance end