from bluesky.network.client import Client from bluesky.network.server import Server myclient = Client() myclient.connect(event_port=11000, stream_port=11001) myclient.subscribe(b'ACDATA') def on_event(eventname, eventdata, sender_id): print('Event received:', eventname) print(eventdata) print(sender_id) def on_stream(streamname, data, sender_id): print('Stream data received:', streamname) print(data['lat']) flag = True return flag flag = False myclient.event_received.connect(on_event) flag = myclient.stream_received.connect(on_stream) myclient.receive() # print(myclient.servers[myclient.host_id]['nodes'][0]) # diffnode = myclient.servers[myclient.host_id]['nodes'][1] # myclient.actnode(diffnode)
def __init__(self, **kwargs): def on_event(eventname, eventdata, sender_id): print(eventdata) print(sender_id) def on_stream(streamname, data, sender_id): print('Stream data received:', streamname) self.received_data = True self.data = data ## Enable client server interface self.NodeID = kwargs['NodeID'] self.received_data = False myclient = Client() myclient.connect(event_port=11000, stream_port=11001) myclient.receive() myclient.actnode( myclient.servers[myclient.host_id]['nodes'][self.NodeID]) myclient.subscribe(b'ACDATA') myclient.stream_received.connect(on_stream) myclient.event_received.connect(on_event) while not self.received_data: myclient.receive() self.nm = 1852 self.ep = 0 self.los = 5 * 1.05 # [nm] Horizontal separation minimum for resolution self.wpt_reached = 5 # observation is a array of 4 collums [latitude,longitude,hdg,dist_plane,dist_waypoint] Real values, so not yet normalized self.min_hdg = 0 #0 self.max_hdg = 360 #360 self.min_lat = -1 self.max_lat = 1 self.min_lon = -1 self.max_lon = 1 # max values based upon size of latlon box self.min_dist_plane = self.los * 0.95 self.max_dist_plane = 125 self.min_dist_waypoint = self.wpt_reached * 0.95 self.max_dist_waypoint = 125 # define observation bounds self.low_obs = np.array([ self.min_lat, self.min_lon, normalizer(self.min_hdg, 'HDGToNorm', self.min_hdg, self.max_hdg), normalizer(self.min_dist_plane, 'DistToNorm', self.min_dist_plane, self.max_dist_plane), normalizer(self.min_dist_waypoint, 'DistToNorm', self.min_dist_waypoint, self.max_dist_waypoint) ]) self.high_obs = np.array([ self.max_lat, self.max_lon, normalizer(self.max_hdg, 'HDGToNorm', self.min_hdg, self.max_hdg), normalizer(self.max_dist_plane, 'DistToNorm', self.min_dist_plane, self.max_dist_plane), normalizer(self.max_dist_waypoint, 'DistToNorm', self.min_dist_waypoint, self.max_dist_waypoint) ]) self.viewer = None # Initialize bluesky self.mode = 'sim-detached' self.discovery = ('--discoverable' in sys.argv or self.mode[-8:] == 'headless') # Check if alternate config file is passed or a default scenfile self.cfgfile = '' self.scnfile = '/synthetics/super/super3.scn' bs.init(self.mode, discovery=self.discovery, cfgfile=self.cfgfile, scnfile=self.scnfile) bs.sim.fastforward() self.observation_space = spaces.Box(low=self.low_obs, high=self.high_obs, dtype=np.float32) # self.action_space = spaces.Discrete(360) self.action_space = spaces.Box(low=-1, high=1, shape=(1, ), dtype=np.float32)