def test_computation(self, name, orien, expected_reward, mock_euler, mock_orien): mock_orien.return_value = None, None orien_radians = tuple(i * np.pi / 180 for i in orien) mock_euler.return_value = orien_radians reward = rewards.UprightReward(None) reward.client = self.client self.assertEqual(reward.compute(), expected_reward)
def _init(): env_config = solo8v2vanilla.Solo8VanillaConfig() env = gym.make('solo8vanilla-v0', config=env_config, normalize_actions=False) env.obs_factory.register_observation(obs.TorsoIMU(env.robot)) env.obs_factory.register_observation(obs.MotorEncoder(env.robot)) env.reward_factory.register_reward(1, rewards.UprightReward(env.robot)) env.termination_factory.register_termination(terms.TimeBasedTermination(length)) return env
import gym import numpy as np from gym_solo.envs import solo8v2vanilla from gym_solo.core import obs from gym_solo.core import rewards from gym_solo.core import termination as terms if __name__ == '__main__': config = solo8v2vanilla.Solo8VanillaConfig() env: solo8v2vanilla.Solo8VanillaEnv = gym.make('solo8vanilla-v0', use_gui=True, realtime=True, config=config) env.obs_factory.register_observation(obs.TorsoIMU(env.robot)) env.reward_factory.register_reward(1,rewards.UprightReward(env.robot)) env.termination_factory.register_termination(terms.PerpetualTermination()) joint_params = [] num_joints = env.client.getNumJoints(env.robot) for joint in range(num_joints): joint_params.append(env.client.addUserDebugParameter( 'Joint {}'.format( env.client.getJointInfo(env.robot, joint)[1].decode('UTF-8')), -2 * np.pi, 2 * np.pi, 0)) camera_params = { 'fov': env.client.addUserDebugParameter('fov', 30, 150, 80), 'distance': env.client.addUserDebugParameter('distance', .1, 5, 1.5), 'yaw': env.client.addUserDebugParameter('yaw', -90, 90, 0),
def test_init(self): robot_id = 0 r = rewards.UprightReward(robot_id) r.client = self.client self.assertEqual(robot_id, r._robot_id)