Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plugin Parsing] Updates the plugin parsing of the scenery builder to support the new "Plugin.json" metamodel, and the new floorplan_model folder structure #9

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

LucaKro
Copy link
Collaborator

@LucaKro LucaKro commented Sep 5, 2024

Plugins

Mandatory Plugins

Initial Plugin

Every door should always have an instance of the initial state plugin. “@id” will usually be chosen from a predefined set of plugin configurations.
Currently, there exist three different configurations:

  • full-opened
  • partially-opened
  • fully-closed

If these are not suitable for your specific case, you may also create new plugin configuration. We will get to how to add your own plugins and configurations a bit later.

The following is an example illustrates how to add a initial plugin with the configuration “partially-opened”, to the graph for the door-instance-1:

{  
	"@id": "door:door-instance-1",  
	"@type": "ObjectInstance",  
	"frame": "geom:frame-location-door-1",  
	"of-object": "door:door",  
	"world": "floorplan:frontiers_brsu_building_c",  
	"plugins": [  
		{  
			"@id": "pl:door-partially-opened-init-plugin"  
		}
	]  
} 

Optional Plugins

Dynamic Plugin

The dynamic plugin currently only has one ID in use. Since JSON-LD does allow for dynamic variable passing, and the URI will be a link to a file containing the keyframes at which the door should open/close, it is not predefined in some config, but needs to be set manually as shown in the example:

{  
    "@id": "pl:door-dynamic-plugin",  
    "uri": "testURI"  
}

Adversarial Plugin

The adversarial plugin utilizes transitions from a start-state, to a end-state. Currently, there exist three different states:

  • opened
  • closed
  • partially

each combination of these states has its own transition.
In addition to that, we also need to set a “distance” parameter here, which is the distance at which the distance at which the robot will trigger the transition from start-state to the end-state

So in general an adversarial plugin will always look as follows:

{  
    "@id": "pl:door-{start-state}-to-{end-state}-adversarial-plugin",  
    "distance": distance_to_trigger_transition
}

This is a specific example for start-state “opened”, and end-state “closed”, which triggers if the robots distance to the door is 90cm:

{  
    "@id": "pl:door-opened-to-closed-adversarial-plugin",  
    "distance": "0.9"  
}

Adding New Plugins and Configurations

If you want to create a plugin of a new type, you must first create a new file new-plugin-states.sjon using the following template:

{
    "@context": [
        {
            "pl": "https://secorolab.github.io/metamodels/plugin#",
		    "door": "https://secorolab.github.io/models/door#"
        },
        "https://comp-rob2b.github.io/metamodels/geometry/spatial-relations.json",
        "https://comp-rob2b.github.io/metamodels/geometry/structural-entities.json",
        "https://comp-rob2b.github.io/metamodels/geometry/coordinates.json",
        "https://comp-rob2b.github.io/metamodels/kinematic-chain/structural-entities.json",
        "https://secorolab.github.io/metamodels/floor-plan/object.json",
        "https://secorolab.github.io/metamodels/geometry/polytope.json",
        "https://secorolab.github.io/metamodels/floor-plan/state.json",
        "http://localhost:8000/floor-plan/plugin.json",
        "https://comp-rob2b.github.io/metamodels/qudt.json",
        "https://secorolab.github.io/metamodels/geometry/coordinate-extension.json"
    ],
    "@graph": [
        {
            "@id": "pl:door-state_of_plugin-new_type-plugin",
            "@type": "PluginConfiguration",
            "plugin-type": "new_type",
            "state": "state_of_plugin"
        }
    ]
}   

If your plugin benefits from having a dynamic parameter similar to the uri parameter from the dynamic plugin, or the distance parameter from the adversarial plugin, then you must add a new parameter to metamodels/floor-plan/plugin.json, using the following template:

"new_parameter": {
            "@id": "pl:new_parameter",
            "@type": "PluginConfiguration"
        }

Adding the New Plugin to the Template

First we need to access all parameters needed for our plugin. This is done inside scenery_builder/src/fpm/transformations/objects.py, inside the get_object_instance function.
Locate the if-elif blocks at Line ~180, and append a new elif. Here is an example for the adversarial joint plugin:

elif plugin_type == "adversarial":  
    if ST["Transition"] in g.value(state, RDF.type):  
        start_value = get_joint_state_value(g.value(state, ST["start-state"]))  
        end_value = get_joint_state_value(g.value(state, ST["end-state"]))  
        distance = float(g.value(plugin, PL["distance"]))  
        plugins.append({  
            "plugin_type": plugin_type,  
            "joint": joint_name,  
            "position_before": start_value,  
            "distance_to_trigger": distance,  
            "position_after": end_value  
        })

In this case, we first make sure that the state is of type ST["Transition"], since we rely on its start-state and end-state is. Also notice that, in order to retrieve the distance parameter, we need to access plugin, not state.
Inside the appended dictionary, make sure to keep the “plugin_type” keyword, but other than that you may use any number of unique keywords you need for your plugin.

Afterwards, inside the file scenery_builder/src/fpm/templates/gazebo/world.sdf.jinja, you will find a for-loop used to iterate through all plugins of the current instance around Line 34. Append a new elif statement at the end. Here is an example for the adversarial joint plugin:

{%- elif plugin_config.plugin_type == 'adversarial' %}  
<plugin name="adversarial_joint_plugin" filename="libadversarial_joint_plugin.so">  
  <joint>{{plugin_config.joint}}</joint>  
  <x>{{plugin_config.position_before}}</x>  
  <near>{{plugin_config.distance_to_trigger}}</near>  
  <y>{{plugin_config.position_after}}</y>  
</plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant