コード例 #1
0
    def __init__(self, host):
        self.host = host

        self.id = random_id()
        self.ping_msg = construct_action(self.id)
        self.robot_sock = make_push_socket(host)
        self.robot_sock.send_string(self.ping_msg)

        self.cam = SubCameraMaster(host)
コード例 #2
0
    def step(self, action, with_observation=True):
        assert len(action) == 2
        msg = construct_action(self.id, action=action)

        # run action on robot
        self.robot_sock.send_string(msg)
        print("sent action:", msg)

        # return last known camera image #FIXME: this must be non-blocking and re-send ping if necessary
        if with_observation:
            return self.cam.get_img_blocking()
        else:
            return None
コード例 #3
0
    def step(self, action, with_observation=True):
        assert len(action) == 2 or len(action) == 5
        msg = construct_action(self.id, action=action)

        # before we send an action, we zero the last
        # observation to prevent caching errors
        self.cam.empty_cache()

        # run action on robot
        self.robot_sock.send_string(msg)
        # print("sent action:", msg)

        # return last known camera image #FIXME: this must be non-blocking and re-send ping if necessary
        if with_observation:
            return self._failsafe_observe(msg)
        else:
            return None
コード例 #4
0
    def __init__(self, host, silent=False):
        self.host = host
        self.silent = silent

        # Create a somewhat random ID for this connection.
        # The randomness isn't super important since there
        # will only ever be 1-2 clients connected to the same
        # server
        self.id = random_id()

        # Construct a "hello world" messag
        self.ping_msg = construct_action(self.id)

        # Initialize the PUSH socket
        self.robot_sock = make_push_socket(host)

        self.cam = SubCameraMaster(host, silent=self.silent)

        # We have to wait for the thread to launch
        self.cam.wait_until_ready()

        # say hi to the robot
        self._ping()
import time
import numpy as np
from duckietown_slimremote.helpers import random_id, timer
from duckietown_slimremote.networking import get_ip, construct_action, make_push_socket

robot_sock = make_push_socket("quacksparrow.local")

own_id = random_id()
own_ip = get_ip()
msg = construct_action(own_id, own_ip)

# print("sending init", msg)
# robot_sock.send_string(msg)

timings = []
start = time.time()

while True:
    action = np.random.uniform(-1, 1, 2)
    msg = construct_action(own_id, own_ip, action)
    robot_sock.send_string(msg)
    timings, start = timer(timings, start, prefix="action")
    time.sleep(0.01)  # not necessary anymore

# msg = construct_action(own_id, own_ip, (0.5,-0.5))
# robot_sock.send_string(msg)
コード例 #6
0
 def reset(self):
     msg = construct_action(self.id, action=RESET)
     self.robot_sock.send_string(msg)
     obs, _, _, _ = self.observe()
     return obs
コード例 #7
0
 def reset(self):
     msg = construct_action(self.id, action=RESET)
     self.robot_sock.send_string(msg)
     print("sent reset")