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.

Configuration parameters for Collision

You can set these properties in your scripts with <component>.properties(<property1>=..., <property2>=...).

  • only_objects_with_property (string, default: "")

    Only report collision with objects that have this property, default “” (all objects)

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!)

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

Examples

The following examples show how to use this component in a Builder script:

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 <script>`!
# This is a sample *client* code that uses pymorse to count the
# collisions. Copy this code to a different script, start it with
# `python3 <script>`, and move the robot in the simulator with the
# arrow keys: when you collide with an object, it is printed on the
# console.

import pymorse

nb_collisions = 0

def counter(data):
    global nb_collisions

    if data["collision"]:
        nb_collisions += 1
        print("Collision with %s! In total, %d collisions occured" % (data["objects"], nb_collisions))


with pymorse.Morse() as morse:

    morse.robot.collision.subscribe(counter)

    print("Press ctrl+C to stop")
    while True:
        morse.sleep(10)

Other sources of examples

(This page has been auto-generated from MORSE module morse.sensors.collision.)

Table Of Contents

Previous topic

Clock

Next topic

Compound Sensor

This Page