
Python GPS2system. 2/25/2017 Overview The GPS system was designed to play audio clips along the route of the New Hope Valley Railroad. The initial impedes was to play sound effects during the Halloween train rides. At a specified latitude and longitude the device would play a specific sound effect. After the system is powered up, it may take the GPS receiver a couple of minutes to lock on to enough satellites to retrieve valid data. The system then runs autonomously. On start up, the LED indicator will come on after the linux system loads and the python application has been launched. This takes less than a minute. The indicator will begin to flash when the GPS receiver is locked and is sending valid data to the system. This could take several minutes, depending on the atmospheric conditions. In normal operation the LED will flash approximately once per second. The LED will remain on when an audio track is being played and when the system is capturing and storing positional data. Details All of the files are located in the /home/pi/gps2 folder. To begin the process we have to know the latitude and longitude of the locations that will play the audio clip. In the first iteration of this system, a Parallax BS2 stamp chip was used. This system was used for a couple of years. The limitation of this original system, which was chosen because it used a BASIC programming language, was the finite memory of the Parallax chip. Since the route of the railway was NE a compromise was made to use only the latitude data. This was carried over to the Raspberry Pi system. Now I have added the ongitudinal data of the locations. To overcome the memory limitations of the original Parallax system, the Raspberry Pi was selected. The Raspberry Pi uses Python as its programming language. Version 2.7 was used for this project. Next you need to know the file names of the audio clips that are to be played. The file in which this information is assembled is named: gps_data2.csv. This is a spreadsheet file, saved in the .csv format (Comma Separated Values). The Python library has a module to read .csv files. This data in this .csv file is read into the system by the program load_csv_data2.py. In earlier versions this data was assembled in three text files and each was imported into the python program. The gps2_data.csv contains six fields: Latitude Longitude Location Audio track Volume level Example of a gps2_data_csv file When the csv file is loaded into the system it adds another field the location number. In this case it would be 0 to 21. This can be used to play the audio clips in a yet to be designed audio player utility program. Note: There cannot be an empty row at the top of this spreadsheet. If there is, the load_csv_data2.py program will crash. The the man program that operates when the train is running is named gps2.py. The program that loads the data from the spreadsheet is, as stated above, load_csv_data2.py. This program is run by the import command in the main program. The audio files are stored in the folder /home/pi/gps2/audio_tracks. The names each audio track is in the form name_name_length.mp3. The length is four digits and is the duration of the clip seconds. For example: There is an audio clip of a “demented man walking” that is 16 seconds in duration. The file name is: demented_man_walking_0016.mp3. This format was selected so that the audio clips can be easily sorted by length. When the system is running, and an audio clip is played, the program records the location number, the direction of travel ( n or s), date and time, audio file name, location and the file name of the gps program file. This information is stored in the logfile.txt file. It can easily be imported into a spreadsheet. There is a utility file which will make it easy to preview the audio clips, off line, that will be played along the route. The file is play_mp3s.py. There is another utility that will play one audio file at a time. The file is play_file.py. To use this utility, enter python play_file.py x . where x is the location number. You MUST enter a number or the program will crash, ie python play_file.py 4. This will play the file 4. You can then play another file by entering the number or z to exit this program. There is a also mode built into the system to record the latitude and longitude of the position along the route. This data can be entered into the gps2_data.csv file. A keyboard in required for this operation. I monitor is not necessary, but may also be used. In order to log the position of a location that you wish to have an audio file play, press the ctrl-c keys. The LED will stay on. Type in the name of this location and press enter. The LED will begin to flash. The data is saved in the file datafile.txt. This file can be opened by a spreadsheet program and used in the gps2_data.csv file. I summary: The following files need to be in the operational directory: gps2.py gps2_data.csv load_csv_data2.py play_mp3s.py play_file.py gpssock.sh (see below) The following files will be created: logfile.txt datafile.txt As stated above, the audio clips used are stored in a separate folder. In the /home/pi/gps2 directory, create a folder audio_tracks Place the audio files, in mp3 format, into this folder, /home/pi/gps2/audio_tracks. In order to have the system run automatically when power is applied the file: .desktop must be in the folder /home/pi/.config/autostart. [Desktop Entry] Type = Application Exec = lxterminal -e “sudo python /home/pi/gps2/gps2.py” The .config folder exists in the /home/pi folder. Create the autostart folder In the .config folder. Then create the .desktop file in the autostart folder. This will run the program in a lxterminal. You could automatically run the program by inserting a line in the /etc/.rclocal file. But, the program runs in the background and does not show any information in the monitor. You can also run the program by inserting a line in the /etc/profile file. This works fine with a Raspberry Pi 2, but with the 2B and the 3 it plays the audio files twice with an echo effect. This file is needed when running the system using a Raspberry Pi 2B or Pi 3B: gpssock.sh The line /home/pi/gps2/./gpssock.sh & must be added to the bottom of the file: /etc/profile The gpssock.sh is a linux script that is executable. To run an executable file it must be preceded by a ./ Adding this line to the /etc/profile file, it runs the gpssock.sh file during startup. The & is important. If it is not there the Raspberry Pi will not boot into the GUI. If this happens, press the ctrl-alt-F4, log in and edit the /etc/profile file. The file gpssock.sh contains the following three lines: sudo killall gpsd sudo gpsl /dev/ttyUSB0 -F /var/run/gpsd.sock sudo service ntp restart The software needed to read the GPS receiver can be installed from this link: http://www.danmandle.com/blog/getting-gpsd-to-work-with-python/ There is another procedure that I used to install the GPS receiver from this link: http://www.instantsupportsite.com/self-help/raspberry-pi/raspberry-globalsat-353s4-install/ This worked when the initial installation was performed on both the 2 and the 2B systems. However I tried it recently and found that the /lib/udev/gpsd.hotplug file does not exist and I was unable to read the data from the receiver. The SD chip used on the Rapsberry Pi 2B works on the 3B If a Raspberry Pi 2B or 3B are used the time and date are correct If a Raspberry Pi 2 is used the time will be correct, but the date is off by 7168 days! Once this is installed, the system is functional and can be used. _____________________________________________________________________________ Notes: The system can play a different audio track at a location depending in the direction of the train. There are times that you may not want to play a track in one direction. In the folder audio_clips there is a file named silent.mp3 for this purpose. The system to date only monitors the latitude data. When the train proceeds past Bonsal Crossing Rd., the train’ heading is approximately north-west. In warm weather, the announcer usually sits in north end of car 101. In cold weather he sits in the caboose. He offset between these two positions is .7 times the distance between these two points. Or 150 ft. Times .7 or 105 ft. This translates into .00027degrees. The GPS receiver chosen is the Globecast BU353. It is a sealed weather proof unit with a USB interface and costs about $35. The Parallax system used an RS-232 receiver that was not weather proof. Installing the BU353 GPS receiver in the Raspberry Pi http://www.instantsupportsite.com/self-help/raspberry-pi/raspberry-globalsat-353s4-install/ Note: This installation worked fine when it was originally used in August 2016. It is not working at this time. There are also problems with it on the RaspPi-2B. The RaspPi-2 works fine. See anomalies section for details and solution The program uses python code developed by Dan Mandle.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-