def review_progress(self, event): current_position = self.sensors.position if self._arrived(current_position, self.destination_waypoint): self.logger.info('Navigator, arrived at {:+f},{:+f}'.format( self.destination_waypoint.latitude, self.destination_waypoint.longitude)) self.exchange.publish( Event(EventName.arrived, self.destination_waypoint)) else: time_to_next_review = self._time_to_review( current_position, self.destination_waypoint) bearing = self.globe.bearing(current_position, self.destination_waypoint.position) if isNaN(bearing): self.logger.warn( 'Navigator, no information from sensors, continuing on current course' ) else: self.logger.info( 'Navigator, steering to {:+f},{:+f}, bearing {:5.1f}, distance {:.1f}m, review after {:.0f}s' .format( self.destination_waypoint.latitude, self.destination_waypoint.longitude, bearing, self._distance(current_position, self.destination_waypoint), time_to_next_review)) self.exchange.publish( Event(EventName.set_course, heading=bearing)) self.exchange.publish( Event(EventName.after, seconds=time_to_next_review, next_event=Event(EventName.navigate_review)))
def steer(self,requested_heading,heading,rate_of_turn,rudder_deflection_factor = 1): if isNaN(heading): self.logger.debug('Steerer, no valid heading, centralising rudder') self._set_rudder_angle(0) return if not self.on_course(requested_heading,heading,rate_of_turn): new_rudder_angle = self._calculate_rudder_angle(requested_heading,heading,rate_of_turn,rudder_deflection_factor) self.logger.debug( 'Steerer, steering {:.1f}, heading {:.1f}, rate of turn {:+.1f}, rudder {:+.1f}, new rudder {:+.1f}' .format(requested_heading, heading, rate_of_turn, self.rudder_angle, new_rudder_angle)) self._set_rudder_angle(new_rudder_angle)
def test_should_return_hasfix_false_and_NaN_for_values_if_gps_has_no_fix(self): self.assertEqual(self.gps_reader.hasfix, False) self.assertTrue(isNaN(self.gps_reader.position.latitude)) self.assertTrue(isNaN(self.gps_reader.position.longitude)) self.assertEqual(self.gps_reader.position.long_error, 0) self.assertEqual(self.gps_reader.position.lat_error, 0) self.assertTrue(isNaN(self.gps_reader.track)) self.assertTrue(isNaN(self.gps_reader.speed)) self.assertTrue(isNaN(self.gps_reader.time)) self.assertTrue(isNaN(self.gps_reader.speed_error)) self.assertTrue(isNaN(self.gps_reader.track_error))
def test_should_return_hasfix_false_and_NaN_for_values_if_gps_has_no_fix( self): self.assertEqual(self.gps_reader.hasfix, False) self.assertTrue(isNaN(self.gps_reader.position.latitude)) self.assertTrue(isNaN(self.gps_reader.position.longitude)) self.assertEqual(self.gps_reader.position.long_error, 0) self.assertEqual(self.gps_reader.position.lat_error, 0) self.assertTrue(isNaN(self.gps_reader.track)) self.assertTrue(isNaN(self.gps_reader.speed)) self.assertTrue(isNaN(self.gps_reader.time)) self.assertTrue(isNaN(self.gps_reader.speed_error)) self.assertTrue(isNaN(self.gps_reader.track_error))
def review_progress(self,event): current_position = self.sensors.position if self._arrived(current_position, self.destination_waypoint): self.logger.info('Navigator, arrived at {:+f},{:+f}'.format(self.destination_waypoint.latitude,self.destination_waypoint.longitude)) self.exchange.publish(Event(EventName.arrived,self.destination_waypoint)) else: time_to_next_review = self._time_to_review(current_position,self.destination_waypoint) bearing = self.globe.bearing(current_position, self.destination_waypoint.position) if isNaN(bearing): self.logger.warn('Navigator, no information from sensors, continuing on current course') else: self.logger.info('Navigator, steering to {:+f},{:+f}, bearing {:5.1f}, distance {:.1f}m, review after {:.0f}s' .format(self.destination_waypoint.latitude,self.destination_waypoint.longitude, bearing, self._distance(current_position,self.destination_waypoint),time_to_next_review)) self.exchange.publish(Event(EventName.set_course,heading=bearing)) self.exchange.publish(Event(EventName.after,seconds=time_to_next_review,next_event=Event(EventName.navigate_review)))
def _default(self, value,default): return default if isNaN(value) else value
def _default(self, value, default): return default if isNaN(value) else value