Example #1
0
    def get_observations(self):
        # Position on z axis, third (2) element of the getPosition vector
        cartPosition = normalizeToRange(self.robot.getPosition()[2], -0.4, 0.4,
                                        -1.0, 1.0)
        # Linear velocity on z axis
        cartVelocity = normalizeToRange(self.robot.getVelocity()[2],
                                        -0.2,
                                        0.2,
                                        -1.0,
                                        1.0,
                                        clip=True)
        # Angular velocity x of endpoint
        endPointVelocity = normalizeToRange(self.poleEndpoint.getVelocity()[3],
                                            -1.5,
                                            1.5,
                                            -1.0,
                                            1.0,
                                            clip=True)

        self.messageReceived = self.handle_receiver()
        if self.messageReceived is not None:
            poleAngle = normalizeToRange(float(self.messageReceived[0]),
                                         -0.23,
                                         0.23,
                                         -1.0,
                                         1.0,
                                         clip=True)
        else:
            # Method is called before self.messageReceived is initialized
            poleAngle = 0.0
        return [cartPosition, cartVelocity, poleAngle, endPointVelocity]
    def get_observations(self):
        # Position on z axis
        cartPosition = normalizeToRange(self.robot.getPosition()[2], -0.4, 0.4,
                                        -1.0, 1.0)
        # Linear velocity on z axis
        cartVelocity = normalizeToRange(self.robot.getVelocity()[2],
                                        -0.2,
                                        0.2,
                                        -1.0,
                                        1.0,
                                        clip=True)
        # Pole angle off vertical
        poleAngle = normalizeToRange(self.positionSensor.getValue(),
                                     -0.23,
                                     0.23,
                                     -1.0,
                                     1.0,
                                     clip=True)
        # Angular velocity x of endpoint
        endpointVelocity = normalizeToRange(self.poleEndpoint.getVelocity()[3],
                                            -1.5,
                                            1.5,
                                            -1.0,
                                            1.0,
                                            clip=True)

        return [cartPosition, cartVelocity, poleAngle, endpointVelocity]
    def get_observations(self):
        """
        This get_observation implementation builds the required observation for the CartPole problem.
        All values apart from pole angle are gathered here from the robot and poleEndpoint objects.
        The pole angle value is taken from the message sent by the robot.
        All values are normalized appropriately to [-1, 1], according to their original ranges.

        :return: Observation: [cartPosition, cartVelocity, poleAngle, poleTipVelocity]
        :rtype: list
        """
        # Position on z axis
        cartPosition = normalizeToRange(self.robot.getPosition()[2], -0.4, 0.4,
                                        -1.0, 1.0)
        # Linear velocity on z axis
        cartVelocity = normalizeToRange(self.robot.getVelocity()[2],
                                        -0.2,
                                        0.2,
                                        -1.0,
                                        1.0,
                                        clip=True)

        self.messageReceived = self.handle_receiver(
        )  # update message received from robot, which contains pole angle
        if self.messageReceived is not None:
            poleAngle = normalizeToRange(float(self.messageReceived[0]),
                                         -0.23,
                                         0.23,
                                         -1.0,
                                         1.0,
                                         clip=True)
        else:
            # method is called before messageReceived is initialized
            poleAngle = 0.0

        # Angular velocity x of endpoint
        endpointVelocity = normalizeToRange(self.poleEndpoint.getVelocity()[3],
                                            -1.5,
                                            1.5,
                                            -1.0,
                                            1.0,
                                            clip=True)

        return [cartPosition, cartVelocity, poleAngle, endpointVelocity]
    def get_observations(self):
        """
        Observation gets the message sent by the robot through the receiver.
        The values are extracted from the message, converted to float, normalized and clipped appropriately.
        If no message is received, it returns a zero vector. The supervisor doesn't need to add any
        external information; the observation vector is built entirely out of the robot's sensors.

        :return: Observation: [gyro x, gyro y, gyro z, accelerometer x, accelerometer y, accelerometer z]
        :rtype: list
        """
        messageReceived = self.handle_receiver()
        if messageReceived is not None:
            return [
                normalizeToRange(float(messageReceived[i]),
                                 -5.0,
                                 5.0,
                                 -1.0,
                                 1.0,
                                 clip=True)
                for i in range(len(messageReceived))
            ]
        else:
            return [0.0 for _ in range(self.observationSpace)]