Пример #1
0
def stop_unstoped_simulation():
    """
    If not stoped normally, call this function, or copy the following three
    lines and run them.
    """
    clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5)
    vrep.simxStopSimulation(clientID, vrep.simx_opmode_blocking)
    vrep.simxFinish(clientID)
 def destroy(self):
     """
     Finish simulation and release connection to server.
     """
     vrep.simxStopSimulation(self.clientID, self._def_op_mode)
     vrep.simxFinish(self.clientID)
    def __init__(self):
        print('Program started')
        # connect to V-REP server
        vrep.simxFinish(-1)  # just in case, close all opened connections
        self.clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000,
                                       5)  # Connect to V-REP
        if self.clientID != -1:
            print('Connected to remote API server')
        else:
            print('Failed connecting to remote API server')
        # start simulate
        self._def_op_mode = vrep.simx_opmode_blocking
        self._set_joint_op_mode = vrep.simx_opmode_oneshot
        self._set_light_op_mode = vrep.simx_opmode_oneshot
        self._set_visitor_op_mode = vrep.simx_opmode_oneshot

        # To get sensor data
        #   vrep.simx_opmode_buffer: does not work, don't know why?
        #   vrep.simx_opmode_blocking: too slow
        #   vrep.simx_opmode_oneshot: works pretty good
        self._get_prox_op_mode = vrep.simx_opmode_oneshot
        self._get_light_op_mode = vrep.simx_opmode_oneshot

        vrep.simxStartSimulation(self.clientID, self._def_op_mode)

        # get object names and handles
        self._get_object_name_and_handle()

        # initialize action and observation space
        print("Initialize LAS action and observation space...")
        self.prox_sensor_num = len(self.proxSensorHandles)
        self.smas_num = len(self.jointHandles)
        self.lights_num = len(self.lightHandles)
        self.sensors_dim = self.prox_sensor_num + self.lights_num * (1 + 3)
        self.actuators_dim = self.smas_num + self.lights_num * (
            1 + 3)  # light state & color

        self.act_max = np.array([np.inf] * self.actuators_dim)
        self.act_min = -np.array([np.inf] * self.actuators_dim)
        self.obs_max = np.array([1.] * self.sensors_dim)
        self.obs_min = -np.array([1.] * self.sensors_dim)

        self.observation_space = spaces.Box(self.obs_min, self.obs_max)
        self.action_space = spaces.Box(self.act_min, self.act_max)
        print("Initialization of LAS done!")

        # initialize Visitor action and observation space
        print("Initialize Visitor action and observation space...")
        self.visitor_num = len(self.visitorHandles)
        self.visitor_action_dim = self.visitor_num * 2  # visitor's position (x,y,0)
        self.visitor_action_max = np.array(
            [7, 9] * self.visitor_num
        )  # later we should find a way to automatic get this limit
        self.visitor_action_min = np.array([-7, -9] * self.visitor_num)
        self.visitor_action_space = spaces.Box(self.visitor_action_min,
                                               self.visitor_action_max)

        # initialize Single Visitor action and observation space
        print("Initialize Visitor action and observation space...")
        self.single_visitor_action_dim = self.visitor_num * 2  # visitor's position (x,y,0)
        self.single_visitor_action_max = np.array(
            [7, 9])  # later we should find a way to automatic get this limit
        self.single_visitor_action_min = np.array([-7, -9])
        self.single_visitor_action_space = spaces.Box(
            self.single_visitor_action_min, self.single_visitor_action_max)

        print("Initialization of visitor done!")

        self.reward = 0
    # load floor tile
    floor_tile_handles, floor_tile_positions = load_model(
        clientID, 'floor_tile', location_file='floor_tile_location.csv')
    # load hallway
    hallway_handles, hallway_positions = load_model(
        clientID, 'hallway', location_file='hallway_location.csv')
    # load goal
    goal_handles, goal_positions = load_model(
        clientID, 'goal', location_file='goal_location.csv')
    # load participant
    standing_participant_handles, standing_participant_positions = load_model(
        clientID,
        'standing_participant',
        location_file='standing_participant_location.csv')


if __name__ == '__main__':
    """
    Load models into the scene
    """
    vrep.simxFinish(-1)
    clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5)
    if clientID != -1:
        print('Connected to remote API server')
    else:
        print('Failed connecting to remote API server')
    # create 4room_world scene
    creat_4room_world_scene(clientID)

    vrep.simxStopSimulation(clientID, vrep.simx_opmode_blocking)
    vrep.simxFinish(clientID)
Пример #5
0
 def destroy(self):
     vrep.simxStopSimulation(self.clientID, self._def_op_mode)
     vrep.simxFinish(self.clientID)