コード例 #1
0
ファイル: environment.py プロジェクト: DanielLSM/IROS2016
    def __init__(self,
                 m_mins,
                 m_maxs,
                 s_mins,
                 s_maxs,
                 length,
                 type,
                 handle_tol,
                 handle_noise,
                 rest_state,
                 perturbation=None):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.length = length
        self.type = type
        self.handle_tol = handle_tol
        self.handle_tol_sq = handle_tol * handle_tol
        self.handle_noise = handle_noise
        self.rest_state = rest_state
        self.perturbation = perturbation

        if self.perturbation == "BrokenTool1":
            self.length_breakpoint = 0.5
            self.angle_breakpoint = np.pi * 0.5

        self.reset()
コード例 #2
0
    def __init__(self,
                 m_mins,
                 m_maxs,
                 s_mins,
                 s_maxs,
                 lengths,
                 angle_shift,
                 rest_state,
                 n_dmps=3,
                 n_bfs=6,
                 timesteps=50,
                 gui=False):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.lengths = lengths
        self.angle_shift = angle_shift
        self.rest_state = rest_state
        self.reset()
        self.gui = gui

        # DMP PARAMETERS
        self.n_dmps = n_dmps
        self.n_bfs = n_bfs
        self.timesteps = timesteps
        self.max_params = np.array([300.] * self.n_bfs * self.n_dmps +
                                   [1.] * self.n_dmps)
        self.motor_dmp = MyDMP(n_dmps=self.n_dmps,
                               n_bfs=self.n_bfs,
                               timesteps=self.timesteps,
                               max_params=self.max_params)
コード例 #3
0
ファイル: diva.py プロジェクト: tgll/explauto
    def __init__(self,
                 synth,
                 m_mins,
                 m_maxs,
                 s_mins,
                 s_maxs,
                 m_used,
                 s_used,
                 n_dmps,
                 n_bfs,
                 dmp_move_steps,
                 dmp_max_param,
                 sensory_traj_samples,
                 audio,
                 diva_path=None):

        self.m_mins = m_mins
        self.m_maxs = m_maxs
        self.s_mins = s_mins
        self.s_maxs = s_maxs
        self.m_used = m_used
        self.s_used = s_used
        self.n_dmps = n_dmps
        self.n_bfs = n_bfs
        self.dmp_move_steps = dmp_move_steps
        self.dmp_max_param = dmp_max_param
        self.samples = array(linspace(-1, self.dmp_move_steps - 1,
                                      sensory_traj_samples + 1),
                             dtype=int)[1:]
        self.audio = audio

        self.f0 = 1.
        self.pressure = 1.
        self.voicing = 1.

        if self.audio:
            import pyaudio
            self.pa = pyaudio.PyAudio()
            self.stream = self.pa.open(format=pyaudio.paFloat32,
                                       channels=1,
                                       rate=11025,
                                       output=True)
        if synth == "octave":
            self.synth = DivaOctaveSynth(diva_path)
        elif synth == "matlab":
            self.synth = DivaMatlabSynth()
        else:
            raise NotImplementedError

        self.art = array(
            [0.] * 10 + [self.f0, self.pressure, self.voicing]
        )  # 13 articulators is a constant from diva_synth.m in the diva source code
        self.max_params = array([1.] * self.n_dmps + [self.dmp_max_param] *
                                self.n_bfs * self.n_dmps + [1.] * self.n_dmps)

        self.dmp = DmpPrimitive(dmps=self.n_dmps,
                                bfs=self.n_bfs,
                                timesteps=self.dmp_move_steps)
        Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins,
                             self.s_maxs)
コード例 #4
0
ファイル: ik.py プロジェクト: pierre-rouanet/ik-learning
    def __init__(self, robot, motors, move_duration,
                 m_mins, m_maxs, s_mins, s_maxs):
        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.robot = robot
        self.motors = [m.name for m in getattr(self.robot, motors)]
        self.move_duration = move_duration
コード例 #5
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        # DMP PARAMETERS
        self.n_dmps = 4
        self.n_bfs = 7
        self.timesteps = 25
        self.max_params = np.array([300.] * self.n_bfs * self.n_dmps +
                                   [1.] * self.n_dmps)
        self.motor_dmp = MyDMP(n_dmps=self.n_dmps,
                               n_bfs=self.n_bfs,
                               timesteps=self.timesteps,
                               max_params=self.max_params)

        # SPACES
        self.hand = 30 * [0.]
        self.joystick1 = 20 * [0.]
        self.joystick2 = 20 * [0.]
        self.ergo = 20 * [0.]
        self.ball = 20 * [0.]
        self.light = 10 * [0.]
        self.sound = 10 * [0.]

        # CONTEXT
        self.ergo_theta = 0.
        self.ball_theta = 0.
        self.current_context = [self.ergo_theta, self.ball_theta]
コード例 #6
0
    def __init__(self, env, context_mode):
        self.context_mode = context_mode
        self.env = env

        if self.context_mode["mode"] == 'mdmsds':
            Environment.__init__(
                self,
                np.hstack(
                    (self.env.conf.m_mins, self.context_mode['dm_bounds'][0])),
                np.hstack(
                    (self.env.conf.m_maxs, self.context_mode['dm_bounds'][1])),
                np.hstack(
                    (self.env.conf.s_mins, self.context_mode['ds_bounds'][0])),
                np.hstack(
                    (self.env.conf.s_maxs, self.context_mode['ds_bounds'][1])))
        elif self.context_mode["mode"] == 'mcs':
            Environment.__init__(
                self, self.env.conf.m_mins, self.env.conf.m_maxs,
                np.hstack((self.context_mode['context_sensory_bounds'][0],
                           self.env.conf.s_mins)),
                np.hstack((self.context_mode['context_sensory_bounds'][1],
                           self.env.conf.s_maxs)))
        else:
            raise NotImplementedError

        self.current_motor_position = None
        self.current_sensori_position = None
        self.reset()
コード例 #7
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs,
                 object_shape, rest_state):
        
        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.object_shape = object_shape
        self.rest_state = rest_state
        self.reset()
コード例 #8
0
 def __init__(self, m_mins, m_maxs, s_mins, s_maxs, box_m_mins, box_m_maxs):
     
     Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)
     
     self.box_m_mins = box_m_mins
     self.box_m_maxs = box_m_maxs
     self.center = (np.array(self.box_m_mins) + np.array(self.box_m_maxs)) / 2.
     self.reset()
コード例 #9
0
ファイル: environment.py プロジェクト: DanielLSM/IROS2016
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, object_tol2,
                 rest_state):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.object_tol2_sq = object_tol2 * object_tol2
        self.rest_state = rest_state
        self.reset()
コード例 #10
0
ファイル: environment.py プロジェクト: DanielLSM/IROS2016
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, object_shape,
                 rest_state):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.object_shape = object_shape
        self.rest_state = rest_state
        self.reset()
コード例 #11
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs,
                 object_tol2, rest_state):
        
        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.object_tol2_sq = object_tol2 * object_tol2
        self.rest_state = rest_state
        self.reset()
コード例 #12
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, lengths, angle_shift, rest_state):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.lengths = lengths
        self.angle_shift = angle_shift
        self.rest_state = rest_state
        self.reset()
コード例 #13
0
    def __init__(self,
                 env_cls,
                 env_cfg,
                 m_mins,
                 m_maxs,
                 s_mins,
                 s_maxs,
                 n_bfs,
                 move_steps,
                 n_dynamic_motor_dims,
                 n_dynamic_sensori_dims,
                 max_params,
                 n_sensori_traj_points=None,
                 motor_traj_type="DMP",
                 sensori_traj_type="samples",
                 optim_initial_position=False,
                 optim_end_position=False,
                 default_motor_initial_position=None,
                 default_motor_end_position=None,
                 default_sensori_initial_position=None,
                 default_sensori_end_position=None):

        self.env = env_cls(**env_cfg)

        self.n_bfs = n_bfs
        self.n_motor_traj_points = self.n_bfs + optim_initial_position + optim_end_position
        self.n_sensori_traj_points = n_sensori_traj_points or self.n_bfs
        self.move_steps = move_steps
        self.n_dynamic_motor_dims = n_dynamic_motor_dims
        self.n_dynamic_sensori_dims = n_dynamic_sensori_dims
        self.max_params = max_params
        self.motor_traj_type = motor_traj_type
        self.sensori_traj_type = sensori_traj_type
        self.optim_initial_position = optim_initial_position
        self.optim_end_position = optim_end_position

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)
        self.s_traj = None

        if self.motor_traj_type == "DMP":
            self.init_motor_DMP(optim_initial_position, optim_end_position,
                                default_motor_initial_position,
                                default_motor_end_position)
        else:
            raise NotImplementedError

        if self.sensori_traj_type == "DMP":
            self.init_sensori_DMP(optim_initial_position, optim_end_position,
                                  default_sensori_initial_position,
                                  default_sensori_end_position)
        elif self.sensori_traj_type == "samples":
            self.samples = np.array(np.linspace(
                -1, self.move_steps - 1, self.n_sensori_traj_points + 1),
                                    dtype=int)[1:]
        elif self.sensori_traj_type == "end_point":
            self.end_point = self.move_steps - 1
        else:
            raise NotImplementedError
コード例 #14
0
ファイル: environment.py プロジェクト: DanielLSM/IROS2016
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, species, noise,
                 rest_state):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.species = species
        self.noise = noise
        self.rest_state = rest_state
        self.reset()
コード例 #15
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs,
                 object_tol_hand, object_tol_tool, bounds):
        
        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.object_tol_hand_sq = object_tol_hand * object_tol_hand
        self.object_tol_tool_sq = object_tol_tool * object_tol_tool
        self.bounds = bounds
        self.reset()
コード例 #16
0
ファイル: environment.py プロジェクト: DanielLSM/IROS2016
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, box_m_mins, box_m_maxs):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.box_m_mins = box_m_mins
        self.box_m_maxs = box_m_maxs
        self.center = (np.array(self.box_m_mins) +
                       np.array(self.box_m_maxs)) / 2.
        self.reset()
コード例 #17
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, lengths, angle_shift,
                 rest_state):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.lengths = lengths
        self.angle_shift = angle_shift
        self.rest_state = rest_state
        self.reset()
コード例 #18
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs,
                 species, noise, rest_state):
        
        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.species = species
        self.noise = noise
        self.rest_state = rest_state
        self.reset()
コード例 #19
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, length, handle_tol,
                 rest_state):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.length = length
        self.handle_tol = handle_tol
        self.handle_tol_sq = handle_tol * handle_tol
        self.rest_state = rest_state

        self.reset()
コード例 #20
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs,
                 length, handle_tol, rest_state):
        
        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.length = length
        self.handle_tol = handle_tol
        self.handle_tol_sq = handle_tol * handle_tol
        self.rest_state = rest_state
        
        self.reset()
 def __init__(self, env_cls, env_conf, context_mode):
     self.rest_position = context_mode['rest_position']
     self.context_mode = context_mode        
     self.env = env_cls(**env_conf)          
     
     Environment.__init__(self, 
                         np.hstack((self.env.conf.m_mins, self.context_mode['dm_bounds'][0])), 
                         np.hstack((self.env.conf.m_maxs, self.context_mode['dm_bounds'][1])),
                         np.hstack((self.env.conf.s_mins, self.context_mode['ds_bounds'][0])),
                         np.hstack((self.env.conf.s_maxs, self.context_mode['ds_bounds'][1])))                                            
     self.reset()
コード例 #22
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs,
                 size, initial_position, ball_type="magnetic", color='y', random_ball_noise=0.2):
        
        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.ball_type = ball_type
        self.size = size
        self.size_sq = size * size
        self.color = color
        self.initial_position = initial_position
        self.random_ball_noise = random_ball_noise
        self.reset()
コード例 #23
0
 def __init__(self, s_mins, s_maxs, envs_cls, envs_cfg, combined_s):
     
     self.envs = [cls(**cfg) for cls,cfg in zip(envs_cls, envs_cfg)]
     self.n_envs = len(self.envs)
     self.n_params_envs = [len(env.conf.m_dims) for env in self.envs]
     self.n_params_envs_cumsum = np.cumsum([0] + self.n_params_envs)
     self.combined_s = combined_s
 
     config = dict(m_mins=[dim for env in self.envs for dim in env.conf.m_mins],
                   m_maxs=[dim for env in self.envs for dim in env.conf.m_maxs],
                   s_mins=s_mins,
                   s_maxs=s_maxs)
     
     Environment.__init__(self, **config)
コード例 #24
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, arm_lengths,
                 arm_angle_shift, arm_rest_state, ball_size,
                 ball_initial_position):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.arm_lengths = arm_lengths
        self.arm_angle_shift = arm_angle_shift
        self.arm_rest_state = arm_rest_state
        self.ball_size = ball_size
        self.size_sq = ball_size * ball_size
        self.ball_initial_position = ball_initial_position
        self.trajectory = list()
        self.reset()
コード例 #25
0
ファイル: diva.py プロジェクト: flowersteam/explauto
    def __init__(self, 
                synth,
                m_mins, m_maxs, s_mins, s_maxs,
                m_used,
                s_used,
                n_dmps,
                n_bfs,
                dmp_move_steps,
                dmp_max_param,
                sensory_traj_samples,
                audio,
                diva_path=None):
        
        self.m_mins = m_mins
        self.m_maxs = m_maxs 
        self.s_mins = s_mins
        self.s_maxs = s_maxs
        self.m_used = m_used
        self.s_used = s_used
        self.n_dmps = n_dmps
        self.n_bfs = n_bfs
        self.dmp_move_steps = dmp_move_steps
        self.dmp_max_param = dmp_max_param
        self.samples = array(linspace(-1, self.dmp_move_steps-1, sensory_traj_samples + 1), dtype=int)[1:]
        self.audio = audio
    
        self.f0 = 1.
        self.pressure = 1.
        self.voicing = 1.
        
        if self.audio:     
            import pyaudio       
            self.pa = pyaudio.PyAudio()
            self.stream = self.pa.open(format=pyaudio.paFloat32,
                                        channels=1,
                                        rate=11025,
                                        output=True)
        if synth == "octave":
            self.synth = DivaOctaveSynth(diva_path)
        elif synth == "matlab":
            self.synth = DivaMatlabSynth()
        else:
            raise NotImplementedError

        self.art = array([0.]*10 + [self.f0, self.pressure, self.voicing])   # 13 articulators is a constant from diva_synth.m in the diva source code
        self.max_params = array([1.] * self.n_dmps + [self.dmp_max_param] * self.n_bfs * self.n_dmps + [1.] * self.n_dmps)
        
        self.dmp = DmpPrimitive(dmps=self.n_dmps, bfs=self.n_bfs, timesteps=self.dmp_move_steps)
        Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins, self.s_maxs)
コード例 #26
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, arm_lengths,
                 arm_angle_shift, arm_rest_state, arrow_size,
                 arrow_initial_pose):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.arm_lengths = arm_lengths
        self.arm_angle_shift = arm_angle_shift
        self.arm_rest_state = arm_rest_state
        self.arrow_size = arrow_size
        self.size_sq = arrow_size * arrow_size
        self.arrow_initial_pose = arrow_initial_pose
        self.initial_pose = arrow_initial_pose
        self.trajectory = list()
        self.reset()
コード例 #27
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, length, handle_tol, handle_noise, rest_state, perturbation=None):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.length = length
        self.handle_tol = handle_tol
        self.handle_tol_sq = handle_tol * handle_tol
        self.handle_noise = handle_noise
        self.rest_state = rest_state
        self.perturbation = perturbation

        if self.perturbation == "BrokenTool1":
            self.length_breakpoint = 0.5
            self.angle_breakpoint = np.pi * 0.5

        self.reset()
コード例 #28
0
 def __init__(self, env_cls, env_cfg, 
              m_mins, m_maxs, s_mins, s_maxs,
              n_bfs, n_motor_traj_points, n_sensori_traj_points, move_steps, 
              n_dynamic_motor_dims, n_dynamic_sensori_dims, max_params,
              motor_traj_type="DMP", sensori_traj_type="DMP", 
              optim_initial_position=True, optim_end_position=True, default_motor_initial_position=None, default_motor_end_position=None,
              default_sensori_initial_position=None, default_sensori_end_position=None,
              gui=False):
     
     self.env = env_cls(**env_cfg)
     
     self.n_bfs = n_bfs
     self.n_motor_traj_points = n_motor_traj_points
     self.n_sensori_traj_points = n_sensori_traj_points 
     self.move_steps = move_steps
     self.n_dynamic_motor_dims = n_dynamic_motor_dims
     self.n_dynamic_sensori_dims = n_dynamic_sensori_dims
     self.max_params = max_params
     self.motor_traj_type = motor_traj_type 
     self.sensori_traj_type = sensori_traj_type 
     self.optim_initial_position = optim_initial_position
     self.optim_end_position = optim_end_position
     self.gui = gui
     self.n_mvt = 1
     if self.gui:
         plt.ion()
         self.ax = plt.subplot()
         plt.gcf().set_size_inches(12., 12., forward=True)
         plt.gca().set_aspect('equal')
         #plt.show(block=False)
         plt.draw()
     
     Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)
     self.s_traj = None
             
     if self.motor_traj_type == "DMP":
         self.init_motor_DMP(optim_initial_position, optim_end_position, default_motor_initial_position, default_motor_end_position)
     else:
         raise NotImplementedError
         
     if self.sensori_traj_type == "DMP":
         self.init_sensori_DMP(optim_initial_position, optim_end_position, default_sensori_initial_position, default_sensori_end_position)
     elif self.sensori_traj_type == "samples":
         self.samples = np.array(np.linspace(-1, self.move_steps-1, self.n_sensori_traj_points + 1), dtype=int)[1:]
     else:
         raise NotImplementedError
コード例 #29
0
    def update(self, mov, audio=True):
        s = Environment.update(self, mov)

        if self.audio and audio:
            sound = self.sound_wave(self.art_traj)
            self.stream.write(sound.astype(float32).tostring())
            #time.sleep(1)
            #print "Sound sent", sound, len(sound)
        return s
コード例 #30
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, top_env_cls, lower_env_cls, top_env_cfg, lower_env_cfg, fun_m_lower, fun_s_lower, fun_s_top):
        
        self.top_env = top_env_cls(**top_env_cfg)
        self.lower_env = lower_env_cls(**lower_env_cfg)

        self.n_params_lower_env = len(self.lower_env.conf.m_dims)

        self.fun_m_lower = fun_m_lower
        self.fun_s_lower = fun_s_lower
        self.fun_s_top = fun_s_top
        
        
        config = dict(m_mins=m_mins,
                      m_maxs=m_maxs,
                      s_mins=s_mins,
                      s_maxs=s_maxs)
        
        Environment.__init__(self, **config)
コード例 #31
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, arm_lengths,
                 arm_angle_shift, arm_rest_state, ball_size,
                 ball_initial_position, tool_length, tool_initial_pose):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.arm_lengths = arm_lengths
        self.arm_angle_shift = arm_angle_shift
        self.arm_rest_state = arm_rest_state
        self.ball_size = ball_size
        self.size_sq = ball_size * ball_size
        self.ball_initial_position = ball_initial_position
        self.tool_length = tool_length
        self.tool_initial_pose = tool_initial_pose
        self.initial_pose = np.concatenate(
            [ball_initial_position, tool_initial_pose]).tolist()
        self.trajectory = list()
        self.reset()
コード例 #32
0
ファイル: diva.py プロジェクト: tgll/explauto
    def __init__(self,
                 synth,
                 m_mins,
                 m_maxs,
                 s_mins,
                 s_maxs,
                 m_used,
                 s_used,
                 audio,
                 diva_path=None):

        self.m_mins = m_mins
        self.m_maxs = m_maxs
        self.s_mins = s_mins
        self.s_maxs = s_maxs
        self.m_used = m_used
        self.s_used = s_used
        self.audio = audio

        self.f0 = 1.
        self.pressure = 1.
        self.voicing = 1.

        if self.audio:
            import pyaudio
            self.pa = pyaudio.PyAudio()
            self.stream = self.pa.open(format=pyaudio.paFloat32,
                                       channels=1,
                                       rate=11025,
                                       output=True)

        if synth == "octave":
            self.synth = DivaOctaveSynth(diva_path)
        elif synth == "matlab":
            self.synth = DivaMatlabSynth()
        else:
            raise NotImplementedError

        self.art = array(
            [0.] * 10 + [self.f0, self.pressure, self.voicing]
        )  # 13 articulators is a constant from diva_synth.m in the diva source code

        Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins,
                             self.s_maxs)
コード例 #33
0
    def __init__(self,
                 m_mins,
                 m_maxs,
                 s_mins,
                 s_maxs,
                 size,
                 initial_position,
                 ball_type="magnetic",
                 color='y',
                 random_ball_noise=0.2):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        self.ball_type = ball_type
        self.size = size
        self.size_sq = size * size
        self.color = color
        self.initial_position = initial_position
        self.random_ball_noise = random_ball_noise
        self.reset()
コード例 #34
0
    def __init__(self, robot, motors, move_duration, t_reset,
                 m_mins, m_maxs, s_mins, s_maxs):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)
        self.robot = robot
        self.motors = []
        for i_mot, mot in enumerate(getattr(self.robot, motors)):
            self.motors.append(mot.name)
            if mot.name in constraints.keys():
                m_mins[i_mot] = constraints[mot.name][0]
                m_maxs[i_mot] = constraints[mot.name][1]

        time.sleep(4)
        rest_position = []
        # angle_limits = []
        for m in self.robot.motors:
            rest_position.append(m.present_position)
        self.rest_position = array(rest_position)

        self.move_duration = move_duration
        self.t_reset = t_reset
コード例 #35
0
    def __init__(self, robot, motors, move_duration, t_reset, m_mins, m_maxs,
                 s_mins, s_maxs):

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)
        self.robot = robot
        self.motors = []
        for i_mot, mot in enumerate(getattr(self.robot, motors)):
            self.motors.append(mot.name)
            if mot.name in constraints.keys():
                m_mins[i_mot] = constraints[mot.name][0]
                m_maxs[i_mot] = constraints[mot.name][1]

        time.sleep(4)
        rest_position = []
        # angle_limits = []
        for m in self.robot.motors:
            rest_position.append(m.present_position)
        self.rest_position = array(rest_position)

        self.move_duration = move_duration
        self.t_reset = t_reset
コード例 #36
0
ファイル: diva.py プロジェクト: flowersteam/explauto
    def __init__(self, 
                synth, 
                m_mins, m_maxs, s_mins, s_maxs,
                m_used,
                s_used,
                audio,
                diva_path=None):
        
        self.m_mins = m_mins
        self.m_maxs = m_maxs 
        self.s_mins = s_mins
        self.s_maxs = s_maxs
        self.m_used = m_used
        self.s_used = s_used
        self.audio = audio
    
        self.f0 = 1.
        self.pressure = 1.
        self.voicing = 1.
        
        if self.audio:     
            import pyaudio       
            self.pa = pyaudio.PyAudio()
            self.stream = self.pa.open(format=pyaudio.paFloat32,
                                        channels=1,
                                        rate=11025,
                                        output=True)
            
        if synth == "octave":
            self.synth = DivaOctaveSynth(diva_path)
        elif synth == "matlab":
            self.synth = DivaMatlabSynth()
        else:
            raise NotImplementedError

        self.art = array([0.]*10 + [self.f0, self.pressure, self.voicing])   # 13 articulators is a constant from diva_synth.m in the diva source code
        
        Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins, self.s_maxs)
コード例 #37
0
 def __init__(self, env_cls, env_cfg, 
              m_mins, m_maxs, s_mins, s_maxs,
              n_bfs, move_steps, 
              n_dynamic_motor_dims, n_dynamic_sensori_dims, max_params,
              motor_traj_type="DMP", sensori_traj_type="samples", 
              optim_initial_position=False, optim_end_position=False, default_motor_initial_position=None, default_motor_end_position=None,
              default_sensori_initial_position=None, default_sensori_end_position=None):
     
     self.env = env_cls(**env_cfg)
     
     self.n_bfs = n_bfs
     self.n_motor_traj_points = self.n_bfs
     self.n_sensori_traj_points = self.n_bfs 
     self.move_steps = move_steps
     self.n_dynamic_motor_dims = n_dynamic_motor_dims
     self.n_dynamic_sensori_dims = n_dynamic_sensori_dims
     self.max_params = max_params
     self.motor_traj_type = motor_traj_type 
     self.sensori_traj_type = sensori_traj_type 
     self.optim_initial_position = optim_initial_position
     self.optim_end_position = optim_end_position
     
     Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)
     self.s_traj = None
             
     if self.motor_traj_type == "DMP":
         self.init_motor_DMP(optim_initial_position, optim_end_position, default_motor_initial_position, default_motor_end_position)
     else:
         raise NotImplementedError
         
     if self.sensori_traj_type == "DMP":
         self.init_sensori_DMP(optim_initial_position, optim_end_position, default_sensori_initial_position, default_sensori_end_position)
     elif self.sensori_traj_type == "samples":
         self.samples = np.array(np.linspace(-1, self.move_steps-1, self.n_sensori_traj_points + 1), dtype=int)[1:]
     elif self.sensori_traj_type == "end_point":
         self.end_point = self.move_steps-1
     else:
         raise NotImplementedError
コード例 #38
0
 def __init__(self, env_cls, env_conf, context_mode):
     self.context_mode = context_mode        
     self.env = env_cls(**env_conf)          
     
     
     if self.context_mode["mode"] == 'mdmsds':
         Environment.__init__(self, 
                             np.hstack((self.env.conf.m_mins, self.context_mode['dm_bounds'][0])), 
                             np.hstack((self.env.conf.m_maxs, self.context_mode['dm_bounds'][1])),
                             np.hstack((self.env.conf.s_mins, self.context_mode['ds_bounds'][0])),
                             np.hstack((self.env.conf.s_maxs, self.context_mode['ds_bounds'][1])))
     elif self.context_mode["mode"] == 'mcs':
         Environment.__init__(self, 
                             self.env.conf.m_mins, 
                             self.env.conf.m_maxs,
                             np.hstack((self.context_mode['context_sensory_bounds'][0], self.env.conf.s_mins)),
                             np.hstack((self.context_mode['context_sensory_bounds'][1], self.env.conf.s_maxs)))
     else:
         raise NotImplementedError
                                
     self.current_motor_position = None
     self.current_sensori_position = None
     self.reset()
コード例 #39
0
ファイル: arm_diva_env.py プロジェクト: rPortelas/CogSci2017
    def __init__(self, gui=False, audio=False):

        self.t = 0

        # ARM CONFIG

        arm_cfg = dict(m_mins=[-1.] * 3 * 7,
                       m_maxs=[1.] * 3 * 7,
                       s_mins=[-1.] * 3 * 50,
                       s_maxs=[1.] * 3 * 50,
                       lengths=[0.5, 0.3, 0.2],
                       angle_shift=0.5,
                       rest_state=[0., 0., 0.],
                       n_dmps=3,
                       n_bfs=6,
                       timesteps=50,
                       gui=gui)

        # SOUND CONFIG

        self.v_o = list(np.log2([500, 900]))
        self.v_y = list(np.log2([300, 1700]))
        self.v_u = list(np.log2([300, 800]))
        self.v_e = list(np.log2([400, 2200]))
        self.v_i = list(np.log2([300, 2300]))

        self.vowels = dict(o=self.v_o,
                           y=self.v_y,
                           u=self.v_u,
                           e=self.v_e,
                           i=self.v_i)

        # Retrieve caregiver sounds and trajectories from json
        self.rospack = RosPack()
        with open(
                join(self.rospack.get_path('pobax_playground'), 'config',
                     'human_sounds.pickle')) as f:
            self.full_human_motor_traj, self.full_human_sounds_traj = pickle.load(
                f)
        self.human_sounds = self.full_human_sounds_traj.keys()
        rospy.loginfo('Voice node using the word %s for culbuto name' %
                      self.human_sounds[0])

        def compress_sound_traj(sound):
            assert (len(sound) == 100)
            f1s = sound[:50]
            f3s = sound[50:]
            return np.append(f1s[np.array([0, 12, 24, 37, 49])],
                             f3s[np.array([0, 12, 24, 37, 49])])

        #reduce number of sounds
        self.human_sounds = ['eyu', 'oey', 'eou', 'oyi']
        #random.shuffle(self.human_sounds)

        print self.human_sounds
        self.human_sounds_traj = dict()
        self.human_sounds_traj_std = dict()
        self.best_vocal_errors = {}
        self.best_vocal_errors_evolution = []
        for hs in self.human_sounds:
            self.best_vocal_errors[hs] = 10.
            self.human_sounds_traj[hs] = compress_sound_traj(
                self.full_human_sounds_traj[hs])
            self.human_sounds_traj_std[hs] = [
                d - 8.5 for d in self.human_sounds_traj[hs][:5]
            ] + [d - 10.25 for d in self.human_sounds_traj[hs][5:]]

        self.sound_tol = 0.4

        # DIVA CONFIG

        diva_cfg = dict(
            m_mins=np.array([-1, -1, -1, -1, -1, -1, -1]),
            m_maxs=np.array([1, 1, 1, 1, 1, 1, 1]),
            s_mins=np.array([7.5, 9.25]),
            s_maxs=np.array([9.5, 11.25]),
            m_used=range(7),
            s_used=range(1, 3),
            rest_position_diva=list([0] * 7),
            audio=audio,
            diva_use_initial=True,
            diva_use_goal=True,
            used_diva=list([True] * 7),
            n_dmps_diva=7,
            n_bfs_diva=2,
            move_steps=50,
        )

        self.arm = ArmEnvironment(**arm_cfg)
        self.diva = DivaEnvironment(**diva_cfg)

        self.timesteps = 50

        # OBJECTS CONFIG

        self.caregiver_gives_obj_factor = 0.01
        self.tool_length = 0.5
        self.handle_tol = 0.2
        self.handle_tol_sq = self.handle_tol * self.handle_tol
        self.handle_noise = 0.
        self.object_tol_hand = 0.2
        self.object_tol_hand_sq = self.object_tol_hand * self.object_tol_hand
        self.object_tol_tool = 0.2
        self.object_tol_tool_sq = self.object_tol_tool * self.object_tol_tool

        self.diva_traj = None
        self.produced_sound = None

        Environment.__init__(self,
                             m_mins=[-1.] * (21 + 28),
                             m_maxs=[1.] * (21 + 28),
                             s_mins=[-1.] * 56,
                             s_maxs=[1.] * 56)

        self.current_tool = [-0.5, 0., 0.5, 0.]
        self.current_toy1 = [0.5, 0.5, 0.]
        #self.current_toy2 = [0.7, 0.7, 0.]
        #self.current_toy3 = [0.9, 0.9, 0.]
        self.current_caregiver = [0., 1.7]
        self.reset()
        self.compute_tool()

        self.purge_logs()

        if self.arm.gui:
            self.init_plot()

        self.count_diva = 0
        self.count_arm = 0
        self.count_tool = 0
        self.count_toy1_by_tool = 0
        #self.count_toy2_by_tool = 0
        #self.count_toy3_by_tool = 0
        self.count_toy1_by_hand = 0
        #self.count_toy2_by_hand = 0
        #self.count_toy3_by_hand = 0
        self.count_parent_give_label = 0
        self.count_parent_give_object = 0
        self.count_produced_sounds = {}
        for hs in self.human_sounds:
            self.count_produced_sounds[hs] = 0

        self.time_arm = 0.
        self.time_diva = 0.
        self.time_arm_per_it = 0.
        self.time_diva_per_it = 0.
コード例 #40
0
    def __init__(self, gui=False, audio=False):
        
        self.t = 0
        
        # ARM CONFIG
        
        arm_cfg = dict(
                        m_mins=[-1.] * 3 * 7, 
                        m_maxs=[1.] * 3 * 7, 
                        s_mins=[-1.] * 3 * 50,
                        s_maxs=[1.] * 3 * 50,
                        lengths=[0.5, 0.3, 0.2], 
                        angle_shift=0.5,
                        rest_state=[0., 0., 0.],
                        n_dmps=3, 
                        n_bfs=6, 
                        timesteps=50,
                        gui=gui)
        
        
        # SOUND CONFIG
        
        self.v_o = list(np.log2([500, 900]))
        self.v_y = list(np.log2([300, 1700]))
        self.v_u = list(np.log2([300, 800]))
        self.v_e = list(np.log2([400, 2200]))
        self.v_i = list(np.log2([300, 2300]))
        
        
        self.vowels = dict(o=self.v_o, y=self.v_y, u=self.v_u, e=self.v_e, i=self.v_i)
        
        self.human_sounds = ['oey', 'uye', 'iuo', 'eyu', 'eou', 'yeo']
        random.shuffle(self.human_sounds)
        print "human sounds", self.human_sounds
        
        
        def compute_s_sound(sound):
            s1 = self.vowels[sound[0]]
            s2 = [(self.vowels[sound[0]][0] + self.vowels[sound[1]][0]) / 2., (self.vowels[sound[0]][1] + self.vowels[sound[1]][1]) / 2.]
            s3 = self.vowels[sound[1]]
            s4 = [(self.vowels[sound[1]][0] + self.vowels[sound[2]][0]) / 2., (self.vowels[sound[1]][1] + self.vowels[sound[2]][1]) / 2.]
            s5 = self.vowels[sound[2]]
            rdm = 0.0 * (2.*np.random.random((1,10))[0] - 1.)
            return list(rdm + np.array([f[0] for f in [s1, s2, s3, s4, s5]] + [f[1] for f in [s1, s2, s3, s4, s5]]))
        
        
        self.human_sounds_traj = dict()
        self.human_sounds_traj_std = dict()
        self.best_vocal_errors = {}
        self.best_vocal_errors_evolution = []
        for hs in self.human_sounds:
            self.best_vocal_errors[hs] = 10.
            self.human_sounds_traj[hs] = compute_s_sound(hs)
            self.human_sounds_traj_std[hs] = [d - 8.5 for d in self.human_sounds_traj[hs][:5]] + [d - 10.25 for d in self.human_sounds_traj[hs][5:]]    
    
            
        self.sound_tol = 0.4
    

        # DIVA CONFIG
        
        diva_cfg = dict(
                        m_mins = np.array([-1, -1, -1, -1, -1, -1, -1]),
                        m_maxs = np.array([1, 1, 1, 1, 1, 1, 1]),
                        s_mins = np.array([ 7.5,  9.25]),
                        s_maxs = np.array([ 9.5 ,  11.25]),
                        m_used = range(7),
                        s_used = range(1, 3),
                        rest_position_diva = list([0]*7),
                        audio = audio,
                        diva_use_initial = True,
                        diva_use_goal = True,
                        used_diva = list([True]*7),
                        n_dmps_diva = 7,
                        n_bfs_diva = 2,
                        move_steps = 50,
                        )
        
        
        
        self.arm = ArmEnvironment(**arm_cfg)
        self.diva = DivaEnvironment(**diva_cfg)
        
        self.timesteps = 50
        
        
        # OBJECTS CONFIG
        
        self.caregiver_gives_obj_factor = 0.01
        self.tool_length = 0.5
        self.handle_tol = 0.2
        self.handle_tol_sq = self.handle_tol * self.handle_tol
        self.handle_noise = 0.
        self.object_tol_hand = 0.2
        self.object_tol_hand_sq = self.object_tol_hand * self.object_tol_hand
        self.object_tol_tool = 0.2
        self.object_tol_tool_sq = self.object_tol_tool * self.object_tol_tool
        
        self.diva_traj = None
        self.produced_sound = None
        
        Environment.__init__(self, 
                             m_mins= [-1.] * (21+28),
                             m_maxs= [1.] * (21+28),
                             s_mins= [-1.] * 80,
                             s_maxs= [1.] * 80)
        
        
        self.current_tool = [-0.5, 0., 0.5, 0.]
        self.current_toy1 = [0.5, 0.5, 0.]
        self.current_toy2 = [0.7, 0.7, 0.]
        self.current_toy3 = [0.9, 0.9, 0.]
        self.current_caregiver = [0., 1.7]
        self.reset()
        self.compute_tool()
        
        self.purge_logs()
        
        if self.arm.gui:
            self.init_plot()
            
        

        self.count_diva = 0
        self.count_arm = 0
        self.count_tool = 0
        self.count_toy1_by_tool = 0
        self.count_toy2_by_tool = 0
        self.count_toy3_by_tool = 0
        self.count_toy1_by_hand = 0
        self.count_toy2_by_hand = 0
        self.count_toy3_by_hand = 0
        self.count_parent_give_label = 0
        self.count_parent_give_object = 0
        self.count_produced_sounds = {}
        for hs in self.human_sounds:
            self.count_produced_sounds[hs] = 0
        
        self.time_arm = 0.
        self.time_diva = 0. 
        self.time_arm_per_it = 0.
        self.time_diva_per_it = 0. 
コード例 #41
0
ファイル: diva.py プロジェクト: flowersteam/explauto
 def update(self, mov, audio=True):
     s = Environment.update(self, mov)
     if self.audio and audio:
         self.play_sound(self.art_traj)
     return s    
コード例 #42
0
ファイル: diva.py プロジェクト: tgll/explauto
 def update(self, mov, audio=True):
     s = Environment.update(self, mov)
     if self.audio and audio:
         self.play_sound(self.art_traj)
     return s
コード例 #43
0
ファイル: dynamic_env.py プロジェクト: svestark/CogSci2016
 def update(self, m_ag, reset=False, log=False):
     return Environment.update(self, m_ag, reset=True, log=log)
コード例 #44
0
ファイル: dynamic_env.py プロジェクト: DanielLSM/IROS2016
    def __init__(self,
                 env_cls,
                 env_cfg,
                 m_mins,
                 m_maxs,
                 s_mins,
                 s_maxs,
                 n_bfs,
                 n_motor_traj_points,
                 n_sensori_traj_points,
                 move_steps,
                 n_dynamic_motor_dims,
                 n_dynamic_sensori_dims,
                 max_params,
                 motor_traj_type="DMP",
                 sensori_traj_type="DMP",
                 optim_initial_position=True,
                 optim_end_position=True,
                 default_motor_initial_position=None,
                 default_motor_end_position=None,
                 default_sensori_initial_position=None,
                 default_sensori_end_position=None,
                 gui=False):

        self.env = env_cls(**env_cfg)

        self.n_bfs = n_bfs
        self.n_motor_traj_points = n_motor_traj_points
        self.n_sensori_traj_points = n_sensori_traj_points
        self.move_steps = move_steps
        self.n_dynamic_motor_dims = n_dynamic_motor_dims
        self.n_dynamic_sensori_dims = n_dynamic_sensori_dims
        self.max_params = max_params
        self.motor_traj_type = motor_traj_type
        self.sensori_traj_type = sensori_traj_type
        self.optim_initial_position = optim_initial_position
        self.optim_end_position = optim_end_position
        self.gui = gui
        self.n_mvt = 0
        if self.gui:
            plt.ion()
            self.ax = plt.subplot()
            plt.gcf().set_size_inches(12., 12., forward=True)
            plt.gca().set_aspect('equal')
            #plt.show(block=False)
            plt.draw()

        Environment.__init__(self, m_mins, m_maxs, s_mins, s_maxs)

        if self.motor_traj_type == "DMP":
            self.init_motor_DMP(optim_initial_position, optim_end_position,
                                default_motor_initial_position,
                                default_motor_end_position)
        else:
            raise NotImplementedError

        if self.sensori_traj_type == "DMP":
            self.init_sensori_DMP(optim_initial_position, optim_end_position,
                                  default_sensori_initial_position,
                                  default_sensori_end_position)
        elif self.sensori_traj_type == "samples":
            self.samples = np.array(np.linspace(
                -1, self.move_steps - 1, self.n_sensori_traj_points + 1),
                                    dtype=int)[1:]
        else:
            raise NotImplementedError
コード例 #45
0
 def update(self, m_ag, reset=False, log=False):
     return Environment.update(self, m_ag, reset=True, log=log)
コード例 #46
0
    def __init__(self, m_mins, m_maxs, s_mins, s_maxs, m_used, s_used,
                 rest_position_diva, audio, diva_use_initial, diva_use_goal,
                 used_diva, n_dmps_diva, n_bfs_diva, move_steps):

        self.m_mins = m_mins
        self.m_maxs = m_maxs
        self.s_mins = s_mins
        self.s_maxs = s_maxs
        self.m_used = m_used
        self.s_used = s_used
        self.rest_position_diva = rest_position_diva
        self.audio = audio
        self.diva_use_initial = diva_use_initial
        self.diva_use_goal = diva_use_goal
        self.used_diva = used_diva
        self.n_dmps_diva = n_dmps_diva
        self.n_bfs_diva = n_bfs_diva
        self.move_steps = move_steps

        self.f0 = 1.
        self.pressure = 1.
        self.voicing = 1.

        if (os.environ.has_key('AVAKAS') and os.environ['AVAKAS']):
            self.audio = False

        if self.audio:
            self.pa = pyaudio.PyAudio()
            self.stream = self.pa.open(format=pyaudio.paFloat32,
                                       channels=1,
                                       rate=11025,
                                       output=True)

        self.synth = DivaSynth()
        self.art = array(
            [0.] * 10 + [self.f0, self.pressure, self.voicing]
        )  # 13 articulators is a constant from diva_synth.m in the diva source code

        self.max_params = []

        if self.diva_use_initial:
            self.max_params = self.max_params + [1.] * self.n_dmps_diva
            self.max_params = self.max_params + [
                300.
            ] * self.n_bfs_diva * self.n_dmps_diva
        if self.diva_use_goal:
            self.max_params = self.max_params + [1.] * self.n_dmps_diva
        self.max_params = np.array(self.max_params)

        self.dmp = MyDMP(n_dmps=self.n_dmps_diva,
                         n_bfs=self.n_bfs_diva,
                         timesteps=self.move_steps,
                         use_init=self.diva_use_initial,
                         max_params=self.max_params)

        self.default_m = zeros(self.n_dmps_diva * self.n_bfs_diva +
                               self.n_dmps_diva * self.diva_use_initial +
                               self.n_dmps_diva * self.diva_use_goal)
        self.default_m_traj = self.compute_motor_command(self.default_m)
        self.default_sound = self.synth.execute(self.art.reshape(-1, 1))[0]
        self.default_formants = None
        self.default_formants = self.compute_sensori_effect(
            self.default_m_traj)

        Environment.__init__(self, self.m_mins, self.m_maxs, self.s_mins,
                             self.s_maxs)