def oscillator_nw(position_vector, max_time=20.0, fitness_option=6): # Internal state variables of the pacemaker oscillator used as global variables global u1_1, u2_1, v1_1, v2_1, y1_1, y2_1, o_1, gain_1, bias_1 home_dir = os.path.expanduser('~') log('[OSC] Running oscillator_5.oscillator_nw') # Extract the elements from the position vector kf = position_vector[0] GAIN1 = position_vector[1] GAIN2 = position_vector[2] GAIN3 = position_vector[3] GAIN4 = position_vector[4] GAIN5 = position_vector[5] GAIN6 = position_vector[6] BIAS1 = position_vector[7] BIAS2 = position_vector[8] BIAS3 = position_vector[9] BIAS4 = position_vector[10] log('[OSC] Printing chromosome') log('[OSC] kf:{0} GAIN1:{1} GAIN2:{2} GAIN3:{3} GAIN4:{4} GAIN5:{5} GAIN6:{6} BIAS1:{7} BIAS2:{8} BIAS3:{9} BIAS4:{10}' .format(kf, GAIN1, GAIN2, GAIN3, GAIN4, GAIN5, GAIN6, BIAS1, BIAS2, BIAS3, BIAS4)) log('[OSC] {0}'.format(position_vector)) # Try to connect to VREP try_counter = 0 try_max = 5 robot_handle = None while robot_handle is None: try: log('[OSC] Trying to create robot handle (attempt: {0} of {1})'. format(try_counter, try_max)) try_counter += 1 robot_handle = Nico( sync_sleep_time=0.1, motor_config=os.path.join( home_dir, 'computing/repositories/hierarchical_bipedal_controller/motor_configs/nico_humanoid_full_v1.json' ), vrep=True, vrep_host='127.0.0.1', vrep_port=19997, vrep_scene=os.path.join( home_dir, 'computing/repositories/hierarchical_bipedal_controller/vrep_scenes/NICO-Simplified-July2017_standing_Foot_sensors_v4_no_graphs.ttt' )) except Exception, e: log('[OSC] Could not connect to VREP') log('[OSC] Error: {0}'.format(e.message)) time.sleep(1.0) if try_counter > try_max: log('[OSC] Unable to create robot handle after {0} tries'.format( try_max)) exit(1)
def oscillator_nw(position_vector, max_time=20.0, fitness_option=6, gain_l=1.0, gain_r=1.0): home_dir = os.path.expanduser('~') # log('[OSC] Running oscillator_3.oscillator_nw') # Extract the elements from the position vector kf = position_vector[0] GAIN1 = position_vector[1] GAIN2 = position_vector[2] GAIN3 = position_vector[3] GAIN4 = position_vector[4] GAIN5 = position_vector[5] GAIN6 = position_vector[6] BIAS1 = position_vector[7] BIAS2 = position_vector[8] BIAS3 = position_vector[9] BIAS4 = position_vector[10] k = position_vector[11] # log('[OSC] Printing chromosome') # log('[OSC] kf:{0} GAIN1:{1} GAIN2:{2} GAIN3:{3} GAIN4:{4} GAIN5:{5} GAIN6:{6} BIAS1:{7} BIAS2:{8} BIAS3:{9} BIAS4:{10} k:{11}'. # format(kf, GAIN1, GAIN2, GAIN3, GAIN4, GAIN5, GAIN6, BIAS1, BIAS2, BIAS3, BIAS4, k)) # Try to connect to VREP try_counter = 0 try_max = 5 robot_handle = None while robot_handle is None: try: # log('[OSC] Trying to create robot handle (attempt: {0} of {1})'.format(try_counter, try_max)) try_counter += 1 robot_handle = Nico(sync_sleep_time=0.1, motor_config=os.path.join(home_dir, 'computing/repositories/hierarchical_bipedal_controller/motor_configs/nico_humanoid_full_v1.json'), vrep=True, vrep_host='127.0.0.1', vrep_port=19997, vrep_scene=os.path.join(home_dir, 'computing/repositories/hierarchical_bipedal_controller/vrep_scenes/NICO_static_test.ttt') ) except Exception, e: # log('[OSC] Could not connect to VREP') # log('[OSC] Error: {0}'.format(e.message)) time.sleep(1.0) if try_counter > try_max: # log('[OSC] Unable to create robot handle after {0} tries'.format(try_max)) exit(1)
import os from matsuoka_walk.robots import Nico home_dir = os.path.expanduser('~') robot_handle = Nico(sync_sleep_time=0.1, motor_config=os.path.join(home_dir,'computing/repositories/hierarchical_bipedal_controller/motor_configs/nico_humanoid_full_v1.json'), vrep=True, vrep_host='127.0.0.1', vrep_port=19997, vrep_scene=os.path.join(home_dir,'computing/repositories/hierarchical_bipedal_controller/vrep_scenes/NICO-Simplified-July2017_standing.ttt') ) target_angles = {'l_shoulder_y': -0.6, 'r_shoulder_y':0.6} robot_handle.set_angles_slow(target_angles, 5.0)
def matsuoka_init(self): # Set the home directory self.home_dir = os.path.expanduser('~') log('[ENV] matsuoka_init called') # Max time to walk (in seconds) self.max_walk_time = 20 # Variables from the best chromosome position_vector = [ 0.7461913734531209, 0.8422944031253159, 0.07043758116681641, 0.14236621222553963, 0.48893497409925746, 0.5980055418720059, 0.740811806645801, -0.11618361090424223, 0.492832184960149, -0.2949145038394889, 0.175450703085948, -0.3419733470484183 ] self.kf = position_vector[0] self.GAIN1 = position_vector[1] self.GAIN2 = position_vector[2] self.GAIN3 = position_vector[3] self.GAIN4 = position_vector[4] self.GAIN5 = position_vector[5] self.GAIN6 = position_vector[6] self.BIAS1 = position_vector[7] self.BIAS2 = position_vector[8] self.BIAS3 = position_vector[9] self.BIAS4 = position_vector[10] self.k = position_vector[11] # Create the robot handle # Try to connect to VREP try_counter = 0 try_max = 5 self.robot_handle = None while self.robot_handle is None: # Close existing connections if any pypot.vrep.close_all_connections() try: log('[ENV] Trying to create robot handle (attempt: {0} of {1})' .format(try_counter, try_max)) try_counter += 1 self.robot_handle = Nico( sync_sleep_time=0.1, motor_config=os.path.join( self.home_dir, 'computing/repositories/hierarchical_bipedal_controller/motor_configs/nico_humanoid_full_v1.json' ), vrep=True, vrep_host='127.0.0.1', vrep_port=19997, vrep_scene=os.path.join( self.home_dir, 'computing/repositories/hierarchical_bipedal_controller/vrep_scenes/NICO-Simplified-July2017_standing_Foot_sensors_v4_no_graphs.ttt' )) except Exception, e: log('[ENV] Could not connect to VREP') log('[ENV] Error: {0}'.format(e.message)) time.sleep(1.0) if try_counter > try_max: log('[ENV] Unable to create robot handle after {0} tries'. format(try_max)) exit(1)
def __init__(self): # Call init of superclass threading.Thread.__init__(self) # Set the home directory self.home_dir = os.path.expanduser('~') # Set the name of the VREP object self.vrep_body_object = 'torso_11_respondable' # This is the lowest possible gain that can be set, the highest possible gain in 1.0 (no change) self.lowest_possible_gain = LOWEST_POSSIBLE_GAIN # Initially the 2 gain factors are set to 1.0 (no change) # These gain factors will be set by the RL algorithm (using the action method) self.gain_factor_l_hip_y = 1.0 self.gain_factor_r_hip_y = 1.0 # Variable to indicate if terminal state has been reached self.terminal = False # Variable to stop the thread self.stop_thread = False # Max time to walk (in seconds) self.max_walk_time = MAX_WALK_TIME # Variables from the best chromosome position_vector = BEST_CHROMOSOME self.kf = position_vector[0] self.GAIN1 = position_vector[1] self.GAIN2 = position_vector[2] self.GAIN3 = position_vector[3] self.GAIN4 = position_vector[4] self.GAIN5 = position_vector[5] self.GAIN6 = position_vector[6] self.BIAS1 = position_vector[7] self.BIAS2 = position_vector[8] self.BIAS3 = position_vector[9] self.BIAS4 = position_vector[10] self.k = position_vector[11] # Create the robot handle # Try to connect to VREP try_counter = 0 try_max = 5 self.robot_handle = None while self.robot_handle is None: # Close existing connections if any pypot.vrep.close_all_connections() try: log('[OSC] Trying to create robot handle (attempt: {0} of {1})' .format(try_counter, try_max)) try_counter += 1 self.robot_handle = Nico( sync_sleep_time=0.1, motor_config=os.path.join( self.home_dir, 'computing/repositories/hierarchical_bipedal_controller/motor_configs/nico_humanoid_full_v1.json' ), vrep=True, vrep_host='127.0.0.1', vrep_port=19997, vrep_scene=os.path.join( self.home_dir, 'computing/repositories/hierarchical_bipedal_controller/vrep_scenes/NICO-Simplified-July2017_standing_Foot_sensors_v4_no_graphs_with_path.ttt' )) except Exception, e: log('[OSC] Could not connect to VREP') log('[OSC] Error: {0}'.format(e.message)) time.sleep(1.0) if try_counter > try_max: log('[OSC] Unable to create robot handle after {0} tries'. format(try_max)) exit(1)