Module GyroSensor
[frames] | no frames]

Source Code for Module GyroSensor

 1  # GyroSensor.py 
 2   
 3  ''' 
 4   This software is part of the EV3BrickPi library. 
 5   It is Open Source Free Software, so you may 
 6   - run the code for any purpose 
 7   - study how the code works and adapt it to your needs 
 8   - integrate all or parts of the code in your own programs 
 9   - redistribute copies of the code 
10   - improve the code and release your improvements to the public 
11   However the use of the code is entirely your responsibility. 
12  ''' 
13   
14  from GenericSensor import GenericSensor 
15  import brickpi3 
16  import time 
17  from Tools import * 
18   
19 -class GyroSensor(GenericSensor):
20 - def __init__(self, port):
21 GenericSensor.__init__(self, port) 22 self.bp.set_sensor_type(self._getPort(), self.bp.SENSOR_TYPE.EV3_GYRO_ABS_DPS) 23 time.sleep(2) # wait until setup is complete
24
25 - def getValue(self):
26 ''' 27 Returns list of [angle, rotation speed] values or None, if detection fails. 28 ''' 29 try: 30 value = self.bp.get_sensor(self._getPort()) 31 except brickpi3.SensorError as error: 32 return None 33 Tools.debug("GyroSensor.getValue() returned: " + str(value)) 34 return value
35
36 - def getAngle(self):
37 ''' 38 Returns the angle position (in degrees) or None, if detection fails. 39 ''' 40 v = self.getValue() 41 if v == None: 42 return None 43 else: 44 return v[0] 45
46 - def getRate(self):
47 ''' 48 Returns the rotation speed (degrees per seconds) or None, if detection fails. 49 ''' 50 v = self.getValue() 51 if v == None: 52 return None 53 else: 54 return v[1] 55