def decide(self, img_arr): st = self.gamepad._state if int(st[2]) == 1: self.throttle = -0.095 - st[4] / 255. elif int(st[2]) == 2: self.throttle = 0.095 + st[4] / 255. else: self.throttle = 0 self.throttle -= (float(st[12]) - 128.0) / 128.0 self.yaw = (float(st[10]) - 128.0) / 128.0 return methods.yaw_to_angle(self.yaw), self.throttle
def decide(self, img_arr): st = self.gamepad._state direction = int(st[2]) if direction == 1: # forward self.throttle = -0.095 - st[4] / 255. elif direction == 2: # reverse self.throttle = 0.095 + st[4] / 255. else: self.throttle = 0 #self.throttle -= (float(st[12]) - 128.0) / 128.0 self.yaw = (float(st[10]) - 128.0) / 128.0 return methods.yaw_to_angle(self.yaw), self.throttle
def decide(self, img_arr): st = self.gamepad._state direction = int(st[8]) #se ha sustituido st[2] por st[8] if direction == 1: # forward ; se han cambiado los valores de 1 por 255 self.throttle = -0.130 - st[4] / 255. elif direction == -1: # reverse ; se han cambiado los valores de 2 por 0 self.throttle = 0.250 + st[4] / 255. else: self.throttle = 0 self.throttle = -( float(st[8]) - 128.0 ) / 128.0 #se ha descomentado y sustituido -= por =- ; también st12 por st8 self.yaw = (float(st[10]) - 128.0) / 128.0 return methods.yaw_to_angle(self.yaw), self.throttle
async def decide(self): if float(self.rcin.read(config.rc.arm_channel)) > 1490: if not self.calibrated: await self.calibrate_rc(self.rcin) rc_pos_throttle = float(self.rcin.read(config.rc.throttle_channel)) rc_pos_yaw = float(self.rcin.read(config.rc.yaw_channel)) throttle = (rc_pos_throttle - self.throttle_center) / 500.0 yaw = (rc_pos_yaw - self.yaw_center) / 500.0 else: throttle = 0 yaw = 0 self.calibrated = False return methods.yaw_to_angle(yaw), throttle, time.time()
def decide(self, img_arr): if float(self.rcin.read(config.ARM_CHANNEL)) > 1490: if not self.calibrated: self.calibrate_rc(self.rcin) rc_pos_throttle = float(self.rcin.read(config.THROTTLE_CHANNEL)) rc_pos_yaw = float(self.rcin.read(config.YAW_CHANNEL)) throttle = (rc_pos_throttle - self.throttle_center) / 500.0 yaw = (rc_pos_yaw - self.yaw_center) / 500.0 else: throttle = 0 yaw = 0 self.calibrated = False return methods.yaw_to_angle(yaw), throttle
def decide(self, img_arr): img_arr = np.interp(img_arr, config.CAMERA_OUTPUT_RANGE, config.MODEL_INPUT_RANGE) img_arr = np.expand_dims(img_arr, axis=0) prediction = self.model.predict(img_arr) if len(prediction) == 2: yaw_binned = prediction[0] throttle = prediction[1][0][0] else: yaw_binned = prediction throttle = 0 yaw_certainty = max(yaw_binned[0]) yaw_unbinned = methods.unbin_Y(yaw_binned) yaw = yaw_unbinned[0] avf = config.KERAS_AVERAGE_FACTOR yaw = avf * self.yaw + (1.0 - avf) * yaw self.yaw = yaw return methods.yaw_to_angle(yaw), throttle * 0.15
def decide(self, img_arr): if config.camera.crop_top or config.camera.crop_bottom: h, w, _ = img_arr.shape t = config.camera.crop_top l = h - config.camera.crop_bottom img_arr = img_arr[t:l, :] img_arr = np.interp(img_arr, config.camera.output_range, config.model.input_range) img_arr = np.expand_dims(img_arr, axis=0) prediction = self.model.predict(img_arr) if len(prediction) == 2: yaw = methods.angle_to_yaw(prediction[0][0]) throttle = prediction[1][0] else: yaw = methods.angle_to_yaw(prediction[0][0]) throttle = 0 avf = config.model.yaw_average_factor yaw = avf * self.yaw + (1.0 - avf) * yaw self.yaw = yaw return methods.yaw_to_angle(yaw), throttle
def decide(self, img_arr): if config.camera.crop_top or config.camera.crop_bottom: h, w, _ = img_arr.shape t = config.camera.crop_top l = h - config.camera.crop_bottom img_arr = img_arr[t:l, :] img_arr = np.interp(img_arr, config.camera.output_range, config.model.input_range) img_arr = np.expand_dims(img_arr, axis=0) prediction = self.model.predict(img_arr) if len(prediction) == 2: yaw_binned = prediction[0] else: yaw_binned = prediction yaw = methods.from_one_hot(yaw_binned) yaw_step = config.model.yaw_step if abs(yaw - self.yaw) < yaw_step: self.yaw = yaw elif yaw < self.yaw: yaw = self.yaw - yaw_step elif yaw > self.yaw: yaw = self.yaw + yaw_step self.yaw = yaw if len(prediction) == 2: throttle = prediction[1][0] else: throttle = (0.07 + np.amax(yaw_binned) * (1 - abs(yaw)) * config.model.throttle_mult) avf_t = config.model.throttle_average_factor throttle = avf_t * self.throttle + (1.0 - avf_t) * throttle self.throttle = throttle return methods.yaw_to_angle(yaw), throttle * -1
async def decide(self): return methods.yaw_to_angle(self.yaw), self.throttle, self.frame_time
def test_angle_conversion(self): for yaw in np.arange(-1, 1, 0.1): test_yaw = yaw_to_angle(angle_to_yaw(yaw)) self.assertAlmostEqual(yaw, test_yaw, places=8)