<commit_before>import logging; logger = logging.getLogger("robot." + __name__)
logger.setLevel(logging.DEBUG)

from robots.exception import RobotError

from robots.action import *
from robots.helpers import position
from robots.helpers.cb import nop

from robots.actions.configuration import setpose


#TODO HACK: I create here a new action performer for background "tracking"
# actions to avoid pypoco multithreading issues
actionPerformerForTracking = None

###############################################################################
###############################################################################

@tested("13/03/2012")
@action
def look_at(robot, place, callback = None):
    """ Orders the robot to look at a given place of object.

    Uses look_at_xyz underneath.

    :param place: any valid pyrobots place (spark id, ROS frame, [x,y,z],...)
    """

    place = robot.poses.get(place)

    pan = 30
    tilt = 30
    actions = [
        genom_request("platine",
            "CmdPosPan",
            ["PLATINE_DEG",
            "PLATINE_ABSOLUTE",
            tilt,
            "PLATINE_FALSE",
            0],
            wait_for_completion = False,
            callback = nop),
        genom_request("platine",
            "CmdPosPan",
            ["PLATINE_DEG",
            "PLATINE_ABSOLUTE",
            pan,
            "PLATINE_FALSE",
            0],
            wait_for_completion = False if callback else True,
            callback = callback)
        ]
    return actions
###############################################################################

@tested("13/03/2012")
@action
def look_at_xyz(robot, x,y,z, frame = "map", callback = None):
    """ Look at via pr2SoftMotion.
    
    :param x: the x coordinate
    :param y: the y coordinate
    :param z: the z coordinate
    :param frame: the frame in which coordinates are interpreted. By default, '/map'
    """
    logger.debug("Looking at " + str([x,y,z]) + " in " + frame)<commit_msg>Made action 'look_at' support 'platine'<commit_after>import logging; logger = logging.getLogger("robot." + __name__)
logger.setLevel(logging.DEBUG)

from robots.exception import RobotError

from robots.action import *
from robots.helpers import position
from robots.helpers.cb import nop

from robots.actions.configuration import setpose


#TODO HACK: I create here a new action performer for background "tracking"
# actions to avoid pypoco multithreading issues
actionPerformerForTracking = None

###############################################################################
###############################################################################

@tested("13/03/2012")
@action
def look_at(robot, place, callback = None):
    """ Orders the robot to look at a given place of object.

    If available, uses pr2SoftMotion::moveHead. Else tries with the platine-genom
    module.

    :param place: any valid pyrobots place (spark id, ROS frame, [x,y,z],...)
    """

    if robot.hasmodule("pr2SoftMotion"):
        return look_at_xyz_with_moveHead(robot, place['x'], place['y'], place['z'], place['frame'], callback)

    elif robot.hasmodule("platine"):

        raw = robot.execute([genom_request("spark", "GetJointAbsPose", [place, "HeadX"])])
        
        ok, res = raw
        if not ok:
            # Object probably does not exist
            return []
        yaw, pitch, roll, x, y, z = [float(x) for x in res]

        actions = [
            genom_request("platine",
                "AimAtTargetPoint",
                [0.0, 0.0, 0.0, 
                0.0, 0.0, 0.0,
                "POM_FRAME_ORIGIN",
                0,
                x,
                y,
                z
                ],
                wait_for_completion = False if callback else True,
                callback = callback)
            ]
        return actions

    else:
        logger.warning("No module available to execute a 'look_at'. Skipping this action.")
        return []

###############################################################################

@tested("13/03/2012")
@action
def look_at_xyz(robot, x,y,z, frame = "map", callback = None):
    """ Look at via pr2SoftMotion.
    
    :param x: the x coordinate
    :param y: the y coordinate
    :param z: the z coordinate
    :param frame: the frame in which coordinates are interpreted. By default, '/map'
    """
    logger.debug("Looking at " + str([x,y,z]) + " in " + frame)
{'fraction_non_alphanumeric': 0.2035158891142664, 'fraction_numerical': 0.012395762902862295, 'mean_word_length': 2.7738095238095237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3284124', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1210, 'n_words': 364}