Example #1
0
File: env.py Project: ZJUMark/kUn
class Env(gym.Env):
    def __init__(self):
        self.low_action = np.array([-1, -1, -1])
        self.high_action = np.array([1, 1, 1])
        self.action_space = spaces.Box(low=self.low_action,
                                       high=self.high_action,
                                       dtype=np.float32)
        self.observation_space = spaces.Box(low=-np.inf,
                                            high=np.inf,
                                            shape=(6, ),
                                            dtype=np.float32)
        self.am = ActionModule()
        self.vm = VisionModule()
        self.gm = GameModule()
        self.am.reset()
        time.sleep(0.1)

    def step(self, action=[0, 0, 0]):
        self.gm.sendCommand(action, self.vm.me_angle)
        feedback = self.vm.get_feedback(action)
        return feedback

    def reset(self):
        self.vm.reset()
        self.am.reset()
        time.sleep(0.1)
        self.am.reset()
        return self.vm.get_feedback([0, 0, 0])
Example #2
0
File: env.py Project: ZJUMark/kUn
class Env(gym.Env):
    _feedback = None
    target_pos_x = 0
    target_pos_y = 0

    def __init__(self):
        self.low_action = np.array([-1, -1, -1])
        self.high_action = np.array([1, 1, 1])
        self.action_space = spaces.Box(low=self.low_action,
                                       high=self.high_action,
                                       dtype=np.float32)
        self.observation_space = spaces.Box(low=-np.inf,
                                            high=np.inf,
                                            shape=(14, ),
                                            dtype=np.float32)
        self.am = ActionModule()
        self.vm = VisionModule()
        self.gm = GameModule()
        self.dm = DebugModule()
        self.am.reset()
        time.sleep(0.1)

    def step(self, action=[0, 0, 0]):
        self.gm.sendCommand([action[0], 0, 0], self.vm.me_angle,
                            self._feedback)
        self._feedback = self.vm.get_feedback(
            [self.target_pos_x, self.target_pos_y], action)
        return self._feedback

    def reset(self):
        self.target_pos_x = random2axis(random.random())
        self.target_pos_y = random2axis(random.random())
        target = [self.target_pos_x, self.target_pos_y]
        self.vm.reset()
        self.am.reset()
        time.sleep(0.1)
        self.am.reset()
        self.dm.gui_debug_x(target)
        self.dm.send()
        time.sleep(0.1)
        self._feedback = self.vm.get_feedback(target, [0, 0, 0])
        return self._feedback[0]
Example #3
0
    :return: None
    """
    # start = time.clock()  # This is for debug. We will see how much time will
    # pass for our python module to read a set of data from GrSim.
    vision.get_info()
    global ob
    ob = vision.other_robots[:, :-1]  # Dessert the orientation of other robots
    # Restart the timer
    # print("Elapsed Time: "+str(time.clock()-start))


if __name__ == "__main__":
    vision = VisionModule(VISION_PORT)
    sender = ActionModule('127.0.0.1', 20011)
    debug = DebugModule()
    sender.reset(robot_num=0)

    # Initialize the initial situation of our robot and other robots:
    vision.get_info()
    pos = vision.robot_info
    goal = np.array([4.8, 0])
    ob = vision.other_robots[:, :-1]  # Dessert the orientation of other robots
    min_u = np.zeros(3)
    config = Config()
    traj = np.array(pos)
    path = None  # For now, there is no global path

    count = 0  # This will be a flag in the running loop

    # Initialize the debug module
    debug.dwa_msg_init()