Collision ========= **Detect objects colliding with the current object.** Sensor to detect objects colliding with the current object. It allows to select which objects are sensed for collision by setting the property ``only_objects_with_property`` (see the Examples section for an example). This sensor is a wrapper around Blender's own `Collision `_ sensor. .. cssclass:: properties morse-section Configuration parameters for Collision -------------------------------------- You can set these properties in your scripts with ``.properties(=..., =...)``. - ``only_objects_with_property`` (string, default: ``""``) Only report collision with objects that have this property, default "" (all objects) .. cssclass:: fields morse-section Data fields ----------- This sensor exports these datafields at each simulation step: - ``timestamp`` (float, initial value: ``0.0``) number of seconds in simulated time - ``collision`` (bool, initial value: ``False``) objects colliding with the current object - ``objects`` (string, initial value: ````) A list of colliding objects. *Interface support:* (attention, no interface support!) .. cssclass:: services morse-section Services for Collision ---------------------- - ``get_properties()`` (blocking) Returns the properties of a component. - Return value a dictionary of the current component's properties - ``get_local_data()`` (blocking) Returns the current data stored in the sensor. - Return value a dictionary of the current sensor's data - ``set_property(prop_name, prop_val)`` (blocking) Modify one property on a component - Parameters - ``prop_name``: the name of the property to modify (as shown the documentation) - ``prop_val``: the new value of the property. Note that there is no checking about the type of the value so be careful - Return value nothing - ``get_configurations()`` (blocking) Returns the configurations of a component (parsed from the properties). - Return value a dictionary of the current component's configurations .. cssclass:: examples morse-section Examples -------- The following examples show how to use this component in a *Builder* script: .. code-block:: python from morse.builder import * # adds a default robot (the MORSE mascott!) robot = Morsy() # create and add a Collision sensor collision = Collision() # place it on the front side of the robot collision.translate(0.43,0,0.3) # only detect collision with objects which have the property 'Object'. # see the documentation of `Passive Objects` for details: # http://www.openrobots.org/morse/doc/latest/user/others/passive_objects.html collision.properties(only_objects_with_property="Object") robot.append(collision) # for this example, we use the socket interface collision.add_interface("socket") # we also add a keyboard actuator to be able to move # around our robot to test collisions keyboard = Keyboard() robot.append(keyboard) # the 'sandbox' test environment offers plenty of objects to test # collisions. These objects have all the property 'Object' already set. env = Environment('sandbox') # Copy this code to a script, and run it with `morse run