Coverage for /Users/fmorton/GitHub/Birdbrain-Python-Library-2/src/birdbrain_finch_input.py: 100%

41 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-21 08:37 -0400

1from birdbrain_constant import BirdbrainConstant 

2from birdbrain_device import BirdbrainDevice 

3from birdbrain_microbit_input import BirdbrainMicrobitInput 

4from birdbrain_request import BirdbrainRequest 

5from birdbrain_utility import BirdbrainUtility 

6 

7class BirdbrainFinchInput(BirdbrainRequest): 

8 @classmethod 

9 def is_moving(self, device): 

10 return BirdbrainRequest.request_status(BirdbrainRequest.response('hummingbird', 'in', 'finchIsMoving', 'static', device)) 

11 

12 @classmethod 

13 def light(self, device, side): 

14 """Read the value of the right or left light sensor ('R' or 'L').""" 

15 

16 return self.sensor_response(device, 'Light', BirdbrainRequest.calculate_left_or_right(side)) 

17 

18 @classmethod 

19 def distance(self, device): 

20 """Read the value of the distance sensor""" 

21 

22 distance_options = {} 

23 distance_options['factor'] = BirdbrainConstant.DISTANCE_FACTOR # was 0.0919 

24 distance_options['min_response'] = BirdbrainConstant.DEFAULT_UNLIMITED_MIN_RESPONSE 

25 distance_options['max_response'] = BirdbrainConstant.DEFAULT_UNLIMITED_MAX_RESPONSE 

26 

27 return self.sensor_response(device, 'Distance', 'static', distance_options) 

28 

29 @classmethod 

30 def line(self, device, side): 

31 """Read the value of the right or left line sensor ('R' or 'L'). 

32 Returns brightness as a value 0-100 where a larger number 

33 represents more reflected light.""" 

34 

35 return self.sensor_response(device, 'Line', BirdbrainRequest.calculate_left_or_right(side)) 

36 

37 @classmethod 

38 def encoder(self, device, side): 

39 """Read the value of the right or left encoder ('R' or 'L'). 

40 Values are returned in rotations.""" 

41 

42 sensor_options = {} 

43 sensor_options['min_response'] = float(BirdbrainConstant.DEFAULT_UNLIMITED_MIN_RESPONSE) 

44 sensor_options['max_response'] = float(BirdbrainConstant.DEFAULT_UNLIMITED_MAX_RESPONSE) 

45 sensor_options['type_method'] = 'float' 

46 

47 return round(self.sensor_response(device, 'Encoder', BirdbrainRequest.calculate_left_or_right(side), sensor_options), 2) 

48 

49 @classmethod 

50 def orientation(self, device): 

51 """Return the orentation of the Finch. Results found in BirdbrainConstant.FINCH_ORIENTATION_RESULTS""" 

52 return self.orientation_response(device, "finchOrientation", BirdbrainConstant.FINCH_ORIENTATIONS, 

53 BirdbrainConstant.FINCH_ORIENTATION_RESULTS, BirdbrainConstant.FINCH_ORIENTATION_IN_BETWEEN) 

54 

55 # The following methods override those within the Microbit 

56 # class to return values within the Finch reference frame. 

57 @classmethod 

58 def acceleration(self, device): 

59 """Gives the acceleration of X,Y,Z in m/sec2, relative 

60 to the Finch's position.""" 

61 

62 return BirdbrainMicrobitInput.acceleration(device, "finchAccel") 

63 

64 @classmethod 

65 def compass(self, device): 

66 """Returns values 0-359 indicating the orentation of the Earth's 

67 magnetic field, relative to the Finch's position.""" 

68 

69 return BirdbrainMicrobitInput.compass(device, "finchCompass") 

70 

71 @classmethod 

72 def magnetometer(self, device): 

73 """Return the values of X,Y,Z of a magnetommeter, relative to the Finch's position.""" 

74 

75 return BirdbrainMicrobitInput.magnetometer(device, "finchMag") 

76