/usr/lib/python3/dist-packages/morse/services/communication_services.py is in python3-morse-simulator 1.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import logging; logger = logging.getLogger("morse." + __name__)
logger.setLevel(logging.DEBUG)
from morse.core.abstractobject import AbstractObject
from morse.core.exceptions import MorseRPCInvokationError
from morse.core.services import service
from morse.core import status, blenderapi
import morse.helpers.transformation
def _robot_exists(robot):
try:
for obj, robot_instance in blenderapi.persistantstorage().robotDict.items():
if obj.name == robot:
return robot_instance
except KeyError:
try:
for obj, robot_instance in blenderapi.persistantstorage().externalRobotDict.items():
if obj.name == robot:
return robot_instance
except KeyError:
return None
class Communication(AbstractObject):
def __init__(self):
AbstractObject.__init__(self)
def name(self):
return "communication"
@service
def distance_and_view(self, robot1, robot2):
""" Return the distance between the two robots, and a boolean which
described if one can view the other.
"""
r1 = _robot_exists(robot1)
r2 = _robot_exists(robot2)
if not r1:
raise MorseRPCInvokationError(robot1 + " does not exist in the simulation ")
if not r2:
raise MorseRPCInvokationError(robot2 + " does not exist in the simulation ")
dist = r1.position_3d.distance(r2.position_3d)
closest_obj = r1.bge_object.rayCastTo(r2.bge_object)
return dist, closest_obj == r2.bge_object
def action(self):
pass
|