Source code for pyrltr.worlds.ArmSimulation

import numpy as np
import math
from BaseWorld import BaseWorld


[docs]class SingleDoF(BaseWorld): def __init__(self): BaseWorld.__init__(self, maxEpisodeLength=10 ) def _validatePosition(self, position): result = np.where(position > -math.pi, position, -math.pi) # FIXME 2014-06-11: This is not supposed to be a closed interval!! result = np.where(position <= math.pi, result, math.pi) return result
[docs] def calculateDistanceToTarget(self, position, goalPosition): """Calculates the angular distance to the target.""" return abs(goalPosition - position)
[docs] def getStateQuality(self, state): return -self.calculateDistanceToTarget(state[1], self.goalPosition)
[docs] def getSensors(self): sensorOutput = np.array([self.agentPosition, self.goalPosition]).flatten() return sensorOutput
[docs] def targetReached(self, distance): return distance < (math.pi / 8)
def _getInitialAgentPosition(self): return self.getRandomPosition() def _getInitialGoalPosition(self): return self.getRandomPosition()
[docs] def getRandomPosition(self): """Returns a random position in the interval [-pi, pi).""" return self.randomState.uniform(-math.pi, math.pi)