source: remote_control/puzzlebox_brainstorms_configuration.py @ 75

Last change on this file since 75 was 75, checked in by sc, 11 years ago

network_client_thinkgear:

  • ThinkGear? authorization support added
  • correct KeyboardInterrupt? handling
  • timeouts applied to socket communications
  • command line support added

network_client:

  • correct KeyboardInterrupt? handling
  • timeouts applied to socket communications
  • command line support added
File size: 7.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Puzzlebox - Brainstorms - Configuration
5#
6# Copyright Puzzlebox Productions, LLC (2010)
7#
8# This code is released under the GNU Pulic License (GPL) version 2
9# For more information please refer to http://www.gnu.org/copyleft/gpl.html
10#
11# Last Update: 2010.06.28
12#
13#####################################################################
14
15import os, sys
16import pygame
17
18#####################################################################
19# General configuration
20#####################################################################
21
22DEBUG = 1
23
24BRAINSTORMS_CONFIGURATION_FILE_PATH = 'puzzlebox_brainstorms_configuration.ini'
25
26BRAINSTORMS_DISCRETE_CONTROL_COMMANDS = True
27
28
29#####################################################################
30# Logging
31#####################################################################
32
33LOG_LEVEL_DEBUG = 2
34LOG_LEVEL_INFO = 1
35LOG_LEVEL_ERROR = 0
36LOG_LEVEL_DISABLE = -1
37
38DEFAULT_LOG_LEVEL = LOG_LEVEL_DEBUG
39DEFAULT_LOGFILE = 'brainstorms'
40
41LOGFILE_DIR = '/var/log/puzzlebox'
42LOGFILE_SUFFIX = '.log'
43LOGFILE_SUFFIX_DEBUG = '_debug.log'
44LOGFILE_SUFFIX_INFO = '_info.log'
45LOGFILE_SUFFIX_ERROR = '_error.log'
46
47SPLIT_LOGFILES = False
48
49
50#####################################################################
51# Network addresses
52#####################################################################
53
54BRAINSTORMS_SERVER_INTERFACE = '' # listen on all of server's network interfaces
55BRAINSTORMS_SERVER_HOST = '127.0.0.1' # localhost
56BRAINSTORMS_SERVER_PORT = 8194
57
58THINKGEAR_SERVER_HOST = '127.0.0.1'
59THINKGEAR_SERVER_PORT = 13854
60
61
62#####################################################################
63# Remote Control configuration
64#####################################################################
65
66DEFAULT_NXT_BLUETOOTH_DEVICE_WINDOWS = 'COM1'
67DEFAULT_NXT_BLUETOOTH_DEVICE_LINUX = '/dev/rfcomm0'
68
69if (sys.platform == 'win32'):
70        NXT_BLUETOOTH_DEVICE = DEFAULT_NXT_BLUETOOTH_DEVICE_WINDOWS
71else:
72        NXT_BLUETOOTH_DEVICE = DEFAULT_NXT_BLUETOOTH_DEVICE_LINUX
73
74NXT_MOTORS_MOUNTED_BACKWARDS = True
75NXT_MOTOR_PORT_RIGHT = 'a'
76NXT_MOTOR_PORT_LEFT = 'b'
77NXT_DEFAULT_RC_COMMAND = 'test_drive'
78
79
80#####################################################################
81# Server configuration
82#####################################################################
83
84BRAINSTORMS_DELIMITER = '\r'
85
86TWISTED_SERVER_MAX_COMPONENTS = 16
87
88
89#####################################################################
90# Client configuration
91#####################################################################
92
93CLIENT_NO_REPLY_WAIT = 5 # how many seconds before considering a component dead
94
95TWISTED_CLIENT_MAX_CONNECTION_ATTEMPTS = 5
96
97
98#####################################################################
99# ThinkGear Connect configuration
100#####################################################################
101
102THINKGEAR_DELIMITER = '\r'
103
104THINKGEAR_CONFIGURATION_PARAMETERS = {"enableRawOutput": False, "format": "Json"}
105
106THINKGEAR_AUTHORIZATION_ENABLED = False
107
108THINKGEAR_AUTHORIZATION_REQUEST = { \
109        "appName": "Puzzlebox Brainstorms", \
110        "appKey": "2e285d7bd5565c0ea73e7e265c73f0691d932408"
111}
112
113
114#####################################################################
115# Client Interface configuration [Qt]
116#####################################################################
117
118THINKGEAR_POWER_THRESHOLDS = { \
119       
120        'concentration': { \
121                0: 0, \
122                10: 0, \
123                20: 0, \
124                30: 0, \
125                40: 0, \
126                50: 0, \
127                60: 60, \
128                70: 70, \
129                75: 75, \
130                80: 80, \
131                90: 85, \
132                100: 90, \
133                }, \
134       
135        'relaxation': { \
136                0: 0, \
137                10: 0, \
138                20: 0, \
139                30: 0, \
140                40: 0, \
141                50: 0, \
142                60: 0, \
143                70: 0, \
144                80: 10, \
145                90: 15, \
146                100: 20, \
147                }, \
148       
149} # THINKGEAR_POWER_THRESHOLDS
150
151
152#####################################################################
153# Client Interface configuration [Pygame]
154#####################################################################
155
156CLIENT_PYGAME_DISPLAY_WINDOW_X_COORDINATE = 0
157CLIENT_PYGAME_DISPLAY_WINDOW_Y_COORDINATE = 0
158CLIENT_PYGAME_DISPLAY_WINDOW_X_DIMENSION = 254
159CLIENT_PYGAME_DISPLAY_WINDOW_Y_DIMENSION = 424
160
161#CLIENT_PYGAME_WINDOW_BACKGROUND_COLOR = (255,255,255) # white background
162#CLIENT_PYGAME_WINDOW_BACKGROUND_COLOR = (128,128,128) # grey background
163#CLIENT_PYGAME_WINDOW_BACKGROUND_COLOR = (64,64,64)    # dark grek background
164CLIENT_PYGAME_WINDOW_BACKGROUND_COLOR = (0,0,0)       # black background
165
166CLIENT_PYGAME_IMAGE_DIRECTORY = os.path.join(os.getcwd(), 'images')
167
168# Keyboard key reference at http://www.pygame.org/docs/ref/key.html#pygame.key
169CLIENT_PYGAME_BUTTON_LAYOUT = { \
170       
171        'left': { \
172                'command': 'turn_left', \
173                'active': False, \
174                'button_image': '1-upper_left-white.png', \
175                'activated_image': '1-upper_left-orange.png', \
176                'image_x': 0, \
177                'image_y': 0, \
178                'match_keys': [pygame.K_LEFT, pygame.K_a, pygame.K_q]
179                }, \
180       
181        'forward': { \
182                'command': 'drive_forward', \
183                'active': False, \
184                'button_image': '2-up-white.png', \
185                'activated_image': '2-up-orange.png', \
186                'image_x': 98, \
187                'image_y': 0, \
188                'match_keys': [pygame.K_UP, pygame.K_w]
189                }, \
190       
191        'right': { \
192                'command': 'turn_right', \
193                'active': False, \
194                'button_image': '3-upper_right-white.png', \
195                'activated_image': '3-upper_right-orange.png', \
196                'image_x': 157, \
197                'image_y': 0, \
198                'match_keys': [pygame.K_RIGHT, pygame.K_d, pygame.K_e]
199                }, \
200       
201        'reverse_left': { \
202                'command': 'turn_left_in_reverse', \
203                'active': False, \
204                'button_image': '7-lower_left-white.png', \
205                'activated_image': '7-lower_left-orange.png', \
206                'image_x': 0, \
207                'image_y': 220, \
208                'match_keys': [pygame.K_z]
209                }, \
210       
211        'reverse': { \
212                'command': 'drive_reverse', \
213                'active': False, \
214                'button_image': '8-down-white.png', \
215                'activated_image': '8-down-orange.png', \
216                'image_x': 98, \
217                'image_y': 220, \
218                'match_keys': [pygame.K_DOWN, pygame.K_s, pygame.K_x]
219                }, \
220       
221        'reverse_right': { \
222                'command': 'turn_right_in_reverse', \
223                'active': False, \
224                'button_image': '9-lower_right-white.png', \
225                'activated_image': '9-lower_right-orange.png', \
226                'image_x': 157, \
227                'image_y': 220, \
228                'match_keys': [pygame.K_PAGEDOWN, pygame.K_c]
229                }, \
230       
231} # BUTTON_LAYOUT
232
233
234#####################################################################
235# Flash socket policy handling
236#####################################################################
237
238FLASH_POLICY_FILE_REQUEST = \
239        '<policy-file-request/>%c' % 0 # NULL byte termination
240FLASH_SOCKET_POLICY_FILE = '''<?xml version="1.0"?>
241<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
242<cross-domain-policy>
243   <site-control permitted-cross-domain-policies="all" />
244   <allow-access-from domain="*" to-ports="%i" />
245</cross-domain-policy>%c''' % (THINKGEAR_SERVER_PORT, 0)
246
247
248#####################################################################
249# Configuration File Parser
250#####################################################################
251
252if os.path.exists(BRAINSTORMS_CONFIGURATION_FILE_PATH):
253       
254        file = open(BRAINSTORMS_CONFIGURATION_FILE_PATH, 'r')
255       
256        for line in file.readlines():
257                line = line.strip()
258                if len(line) == 0:
259                        continue
260                if line[0] == '#':
261                        continue
262                if line.find('=') == -1:
263                        continue
264                try:
265                        exec line
266                except:
267                        if DEBUG:
268                                print "Error recognizing Puzzlebox Brainstorms configuration option:",
269                                print line
270
Note: See TracBrowser for help on using the repository browser.