def update(self, pitch, roll, send=True): # No, I didn't get the trigonometry right on the first try... # Todo: Numpify # Artificial Horizon right_y = -pitch / 90 - math.tan(-roll / 180*math.pi) left_y = -pitch / 90 + math.tan(-roll / 180*math.pi) self.patch_source.data["x"] = [[-1, 1, 1, -1], [-1, 1, 1, -1]] self.patch_source.data["y"] = [[1, 1, right_y, left_y], [left_y, right_y, -1,-1]] xs = [] ys = [] widths = [] rot = lambda x,y,sin_a,cos_a: (x*cos_a-y*sin_a, y*cos_a+x*sin_a) sin_a = math.sin(roll / 180*math.pi) cos_a = math.cos(roll / 180*math.pi) # White Lines x1,y1 = rot(-3, -pitch/90, sin_a, cos_a) x2,y2 = rot(3, -pitch/90, sin_a, cos_a) xs.append([x1,x2]) ys.append([y1,y2]) widths.append(5) for i in range(0,4): x1,y1 = rot(-0.5,(i+1)*20 / 90 - pitch/90, sin_a, cos_a) x2,y2 = rot(0.5,(i+1)*20 / 90 -pitch/90, sin_a, cos_a) xs.append([x1,x2]) ys.append([y1,y2]) widths.append(2) x1,y1 = rot(-0.5,-(i+1)*20 / 90 - pitch/90, sin_a, cos_a) x2,y2 = rot(0.5,-(i+1)*20 / 90 - pitch/90, sin_a, cos_a) xs.append([x1,x2]) ys.append([y1,y2]) widths.append(2) self.line_source.data["x"]=xs self.line_source.data["y"]=ys self.line_source.data["width"]=widths replace_bokeh_data_source(self.line_source) replace_bokeh_data_source(self.patch_source)
def update(self, airspeed, groundspeed, altitude, transmit=True): ts_airspeed = airspeed.get_timeseries() ts_groundspeed = groundspeed.get_timeseries() minute_delta = pd.Timedelta("1 minute") b = ts_airspeed.index[-1] a = b - self.minutes_back*minute_delta ts_airspeed = ts_airspeed[a:b] ts_groundspeed = ts_groundspeed[a:b] self.airspeed_source.data["time"] = timedelta_to_seconds(ts_airspeed) self.airspeed_source.data["airspeed"] = ts_airspeed.values self.groundspeed_source.data["time"] = timedelta_to_seconds(ts_groundspeed) self.groundspeed_source.data["groundspeed"] = ts_groundspeed.values ts_altitude = altitude.get_timeseries()[a:b] self.altitude_source.data['time'] = timedelta_to_seconds(ts_altitude) self.altitude_source.data['altitude'] = ts_altitude.values if transmit: replace_bokeh_data_source(self.airspeed_source) replace_bokeh_data_source(self.groundspeed_source) replace_bokeh_data_source(self.altitude_source)