Module SharedConstants
[hide private]
[frames] | no frames]

Source Code for Module SharedConstants

  1  # SharedConstants.py 
  2  # For Py2Go (full model) 
  3   
  4  ''' 
  5  Constants and defaults for the RaspiBrick libray based on Pi2Go (full version) from 4tronix. 
  6   
  7   This software is part of the raspibrick module. 
  8   It is Open Source Free Software, so you may 
  9   - run the code for any purpose 
 10   - study how the code works and adapt it to your needs 
 11   - integrate all or parts of the code in your own programs 
 12   - redistribute copies of the code 
 13   - improve the code and release your improvements to the public 
 14   However the use of the code is entirely your responsibility. 
 15  ''' 
 16   
 17  ''' 
 18  General remarks: 
 19  - Pin definitions start with P_ 
 20  ''' 
 21   
 22  ''' 
 23  History: 
 24   
 25  V1.15 - Sep 2015: - First public release 
 26  V1.16 - Oct 2015: - Added: Sensor events 
 27  V1.17 - Oct 2015: - Modified: Timeout to receive echo in ultrasonic sensor 
 28  V1.18 - Oct 2015: - Fixed: Gear.leftArc(), rightArc() now work with changing radius 
 29  V1.19 - Oct 2015: - Added: Led.setColor(), setColorAll() with X11-color string 
 30  V1.20 - Oct 2015: - Modifications to RaspiJLib 
 31  V1.21 - Oct 2015: - Added: ButtonListener with long press event 
 32  V1.22 - Nov 2015: - Added: Class DgTell, Button click and double-click events 
 33  V1.23 - Dec 2015: - Added: Selecting up to 9 autonomous Python programs 
 34  V1.24 - Dec 2015: - Modified: Shutdown confirmation with button press event 
 35  V1.25 - Dec 2015: - Modified: Decimal point display for DgTell 
 36  V1.26 - Jan 2016: - Added: tcpcom.py Event driven socket library 
 37  V1.28 - Feb 2016: - Fixed: Inhibit repeat same text in Display 
 38  V1.29 - Mar 2016: - Added: Escape into SELF/AUTO mode 
 39  V1.30 - Mar 2016: - Changed SELF mode to use buzzer/led to show IP 
 40  V1.31 - Apr 2016: - Fixed: startApp now checks standalone or Pi2Go mode 
 41                    - Fixed: Error in Ultrasonic.py reporting too large distance 
 42  V1.32 - May 2016: - New Linux installations: SoX, DHT driver from Adafruit, 1-Wire driver (kernel) 
 43  V1.33 - May 2016: - Patched Scratch image to avoid popup dialog when remote sensor is enabled, 
 44                    - Screen blanking for console disabled 
 45                    - Login shell over serial disabled (in raspi-config) 
 46                    - OLED driver Adafruit_Python_SSD1306 
 47  V1.34 - Jun 2016: - startApp modified to accept fully qualified path to script 
 48  V1.35 - Oct 2016: - Geany, PyQT4 installed, new sudirectory rpi-tutorial,  
 49                      in Pictures: einstein.ppm 
 50  V1.36 - Apr 2017: - Updates: RaspiBrick libraries, TigerJython 
 51                    - Morse announcement removed in Pi2Go startup 
 52                    - Support for OLED display in Pi2Go mode 
 53                    - Bluetooth server no longer started at boot time 
 54                    - Adapted to new NOOPs release 
 55   
 56  ''' 
 57   
 58  VERSION = "1.36 - Apr 2017" 
 59  DISPLAYED_VERSION = "136"  # displayed n.nn 
 60   
 61  DEBUG = False 
 62   
 63  BLINK_CONNECT_DISCONNECT = True 
 64   
 65  # -------------------- Start of pin definitions ------------------ 
 66  # Motor pins 
 67  P_LEFT_FORWARD = 26 
 68  P_LEFT_BACKWARD = 24 
 69  P_RIGHT_FORWARD = 19 
 70  P_RIGHT_BACKWARD = 21 
 71   
 72  # Infrared sensor pins 
 73  P_FRONT_CENTER = 13 
 74  P_FRONT_LEFT = 11 
 75  P_FRONT_RIGHT = 7 
 76  P_LINE_LEFT = 12 
 77  P_LINE_RIGHT = 15 
 78   
 79  # Pushbutton pin 
 80  P_BUTTON = 16 
 81   
 82  # Ultrasonic pin 
 83  P_TRIG_ECHO = 8 
 84   
 85  # Battery monitor pin 
 86  P_BATTERY_MONITOR = 18 
 87  # -------------------- End of pin definitions -------------------- 
 88   
 89  # Motor constants 
 90  MOTOR_PWM_FREQ = 30  # PWM frequency (Hz) 
 91  LEFT_MOTOR_PWM = [0] * 2  # PWMs 
 92  RIGHT_MOTOR_PWM = [0] * 2 # PWMs 
 93   
 94  # Motor IDs 
 95  MOTOR_LEFT = 0 
 96  MOTOR_RIGHT = 1 
 97   
 98  # Infrared IDs 
 99  IR_CENTER = 0 
100  IR_LEFT = 1 
101  IR_RIGHT = 2 
102  IR_LINE_LEFT = 3 
103  IR_LINE_RIGHT = 4 
104   
105  # LED IDs 
106  LED_FRONT = 0 
107  LED_LEFT = 1 
108  LED_REAR = 2 
109  LED_RIGHT = 3 
110   
111  # LED and Servo PWM frequency 
112  PWM_I2C_ADDRESS = 0x40 
113  # LED and Servo PWM frequency 
114  PWM_FREQ = 50 
115   
116  # ADC I2C address 
117  ADC_I2C_ADDRESS = 0x48 
118   
119  # Light sensor IDs 
120  LS_FRONT_LEFT = 0 
121  LS_FRONT_RIGHT = 1 
122  LS_REAR_LEFT = 2 
123  LS_REAR_RIGHT = 3 
124   
125  # Servo constants 
126  SERVO_0 = 12  # PCA9685 port, S12 header 
127  SERVO_1 = 13  # PCA9685 port, S13 header 
128  SERVO_2 = 14  # PCA9685 port, S14 header 
129  SERVO_3 = 15  # PCA9685 port, S15 header 
130   
131  # Default speed 
132  MOTOR_DEFAULT_SPEED = 40 
133   
134  # Length of axes used in Gear.leftArc(), Gear.rightArc() 
135  GEAR_AXE_LENGTH = 0.05 
136  # Default speed 
137  GEAR_DEFAULT_SPEED = 30 
138  # Difference between left and right motor in Gear() due to different mechanics 
139  # diff = leftSpeed - rightSpeed 
140  GEAR_FORWARD_SPEED_DIFF = 0.5 
141  GEAR_BACKWARD_SPEED_DIFF = 0.5 
142   
143  # Button event constants 
144  BUTTON_PRESSED = 1 
145  BUTTON_RELEASED = 2 
146  BUTTON_LONGPRESSED = 3 
147  BUTTON_CLICKED = 4 
148  BUTTON_DOUBLECLICKED = 5 
149  BUTTON_LONGPRESS_DURATION = 2 # time (in s) the button must be pressed to be a long press 
150  BUTTON_DOUBLECLICK_TIME = 1 # default time (in s) to wait for a double click event 
151   
152  # Character to binary value mapping for 4 digit 7 segment display 
153  PATTERN = {' ': 0, '!': 134, '"': 34, '#': 0, '$': 0, '%': 0, '&': 0, '\'':  2, '(': 0, ')': 0, 
154             '*': 0, '+': 0, ',': 4, '-': 64, '.': 128, '/': 82, '0': 63, '1': 6, '2': 91, '3': 79, 
155             '4': 102, '5': 109, '6': 125, '7': 7, '8': 127, '9': 111, ':': 0, ';': 0, '<': 0, 
156             '=': 72, '>': 0, '?': 0, '@': 93, 'A': 119, 'B': 124, 'C': 88, 'D': 94, 'E': 121, 
157             'F': 113, 'G': 61, 'H': 118, 'I': 48, 'J': 14, 'K': 112, 'L': 56, 'M': 85, 'N': 84, 
158             'O': 63, 'P': 115, 'Q': 103, 'R': 80, 'S': 45, 'T': 120, 'U': 62, 'V': 54, 'W': 106, 
159             'X': 73, 'Y': 110, 'Z': 27, '[': 57, '\\':  100, ']': 15, '^': 35, '_': 8, '`': 32, 
160             'a': 119, 'b': 124, 'c': 88, 'd': 94, 'e': 121, 'f': 113, 'g': 61, 'h': 116, 'i': 16, 
161             'j': 12, 'k': 112, 'l': 48, 'm': 85, 'n': 84, 'o': 92, 'p': 115, 'q': 103, 'r': 80, 's': 45, 
162             't': 120, 'u': 28, 'v': 54, 'w': 106, 'x': 73, 'y': 110, 'z': 27, '{': 0, '|': 48, '}': 0, '~': 65} 
163   
164  # Config file to store last program name 
165  CONFIG_FILE = "/home/pi/scripts/raspibrick.cfg" 
166  # Path of execution app 
167  APP_PATH = "/home/pi/scripts/MyApp" 
168   
169  # Event poll delay (ms) 
170  POLL_DELAY = 50 
171   
172  ABOUT = "2003-2016 Aegidius Pluess\n" + \ 
173           "OpenSource Free Software\n" + \ 
174           "http://www.aplu.ch\n" + \ 
175           "All rights reserved" 
176