Skip to content

Commit

Permalink
Merge pull request #45 from seth10/dev
Browse files Browse the repository at this point in the history
Touchscreen revert and various minor improvements
  • Loading branch information
mindsensors authored Jun 27, 2017
2 parents 844a913 + 23d4ff7 commit b6d1a12
Show file tree
Hide file tree
Showing 50 changed files with 441 additions and 1,070 deletions.
42 changes: 41 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,51 @@ This document will introduce you to the repository's structure and how the PiSto
- A remote control is available, which is particularly useful on a mobile device. There is a joystick to move your robot (using motors B and C). There are also sliders to set the LED colors.
- Log files are also accessible from the web interface


## Coordinate systems

||||
| --- | :---: | --- |
| x=320 <br> y=0 | | x=0 <br> y=0 |
| | TS <br> (readings from touchscreen X/Y registers) | |
| x=320 <br> y=240 | | x=0 <br> y=240 |

||||
| --- | :---: | --- |
| x=0 <br> y=320 | | x=0 <br> y=0 |
| | Screen <br> (drawing to TFT) | |
| x=240 <br> y=320 | | x=240 <br> y=0 |

||||
| --- | :---: | --- |
| x=0 <br> y=0 | | x=320 <br> y=0 |
| | Rotation 3 <br> (right-side-up) | |
| x=0 <br> y=240 | | x=320 <br> y=240 |

||||
| --- | :---: | --- |
| x=320 <br> y=240 | | x=0 <br> y=240 |
| | Rotation 1 <br> (up-side-down) | |
| x=320 <br> y=0 | | x=0 <br> y=0 |

||||
| --- | :---: | --- |
| x=0 <br> y=320 | | x=0 <br> y=0 |
| | Rotation 0 <br> (Bank A up) | |
| x=240 <br> y=320 | | x=240 <br> y=0 |

||||
| --- | :---: | --- |
| x=240 <br> y=0 | | x=240 <br> y=320 |
| | Rotation 2 <br> (Bank B up) | |
| x=0 <br> y=0 | | x=0 <br> y=320 |


## Repository files

### setup
#### Suggestions
- When developing, hard link the source files from `/home/pi/PiStorms/...` to their destinations from `setup.sh` ([script](https://gist.github.com/seth10/e41a091ef56d0044474e82f3541755e4))
- When developing, hard link the source files from `/home/pi/PiStorms/...` to their destinations from `setup.sh`. You can wget this [script](https://gist.githubusercontent.com/seth10/e41a091ef56d0044474e82f3541755e4/raw/PiStorms_Development.sh) to `/home/pi/PiStorms/.git/hooks/post-checkout`.
```bash
b=`grep homefolder /usr/local/mindsensors/conf/msdev.cfg | cut -d"=" -f2 | cut -c 2-`
for f in 'MSDriver.py' 'MSBrowser.py' 'psm_shutdown' 'swarmserver' 'pistorms-diag.sh'; do sudo ln -f $b/sys/$f /usr/local/bin/$f; done
Expand Down
Empty file modified artwork/artwork-for-images.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified artwork/river-bank.jpg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion programs/00-About_Me.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_ip_address(ifname):
except:
psm.screen.termPrintAt(7," wlan0 : not present")

if( psm.isKeyPressed() == True or psm.screen.checkButton(0,0,320,320)):
if( psm.isKeyPressed() == True or psm.screen.isTouched()):
psm.screen.termPrintln("")
psm.screen.termPrintln("Exiting to menu")
exit = True
66 changes: 66 additions & 0 deletions programs/30-DataVisualization/02-Polar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
#
# Copyright (c) 2017 mindsensors.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#mindsensors.com invests time and resources providing this open source code,
#please support mindsensors.com by purchasing products from mindsensors.com!
#Learn more product option visit us @ http://www.mindsensors.com/
#
# History:
# Date Author Comments
# 06/15/17 Seth Tenembaum Initial development
#

# This program demonstrates using a polar graph
# to show the AbsoluteIMU's compass heading.

from PiStorms import PiStorms
psm = PiStorms()
psm.screen.termPrintln("Please wait a moment")
psm.screen.termPrintln("as matplotlib loads...")
psm.screen.termPrintln("")
psm.screen.termPrintln("Press and hold GO briefly")
psm.screen.termPrintln("to stop the program running.")

import matplotlib
matplotlib.use("AGG")
import matplotlib.pyplot as plt
import numpy as np
import tempfile
from mindsensors import ABSIMU

plt.figure(figsize=(4,3), dpi=80)
plt.title('AbsoluteIMU Compass Heading')

data = np.empty(0)
sub = plt.subplot(projection='polar')
sub.set_theta_direction(-1)
sub.set_rticks([]) # hide ticks
tau = 2*np.pi

imu = ABSIMU()
psm.BAS1.activateCustomSensorI2C()
image = tempfile.NamedTemporaryFile()

while not psm.isKeyPressed():
h = imu.get_heading()
data = np.append(data, \
np.interp(h, [0,360], [0,tau]))
r = np.arange(len(data))
plt.plot(data, r, color="blue")
plt.savefig(image.name, format="png")
psm.screen.fillBmp(0,0, 320,240, image.name)

2 changes: 1 addition & 1 deletion programs/45-Utils/05-BatteryVolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
psm.led(1,255,0,0)
psm.led(2,255,0,0)
lastled = 3
if(psm.screen.checkButton(0,0,320,320)):
if(psm.screen.isTouched()):
psm.screen.termPrintln("")
psm.screen.termPrintln("Exiting to menu")
psm.led(1,0,0,0)
Expand Down
2 changes: 1 addition & 1 deletion programs/50-CameraDemos/00-TakeSelfie.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
time.sleep(1)
psm.screen.termPrintAt(9, "Touch the screen to exit")

if (psm.screen.checkButton(0,0,320,320)):
if (psm.screen.isTouched()):
psm.screen.clearScreen()
psm.screen.termPrintAt(9,"Exiting to menu")
time.sleep(0.5)
Expand Down
2 changes: 1 addition & 1 deletion programs/50-CameraDemos/03-CensorFaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
elif (len(faces)) == 1:
psm.screen.termPrintAt(8, " Found {0} face!".format(len(faces)))

if (psm.screen.checkButton(0,0,320,320)):
if (psm.screen.isTouched()):
psm.screen.clearScreen()
psm.screen.termPrintAt(9,"Exiting to menu")
time.sleep(0.5)
Expand Down
2 changes: 1 addition & 1 deletion programs/50-CameraDemos/03-IsolateFaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
elif (len(faces)) == 1:
psm.screen.termPrintAt(8, " Found {0} face!".format(len(faces)))

if (psm.screen.checkButton(0,0,320,320)):
if (psm.screen.isTouched()):
psm.screen.clearScreen()
psm.screen.termPrintAt(9,"Exiting to menu")
time.sleep(0.5)
Expand Down
2 changes: 1 addition & 1 deletion programs/50-MotorDemos/04-Motor-ShowPos.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#
# check if screen touched.
#
if(psm.screen.checkButton(0,0,320,320)):
if(psm.screen.isTouched()):
# if scren was touched,
psm.BAM1.resetPos()
time.sleep(.001)
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/01-EV3-InfraredSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
psm.screen.termPrintln("Exiting to menu")
doExit = True
change = 0
if(psm.screen.checkButton(0,0,320,320)): #Change mode if screen is tapped
if(psm.screen.isTouched()): #Change mode if screen is tapped
count = count + 1
if ( count > 2):
count = 0
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/04-EV3-ColorSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
#
# check if screen touched.
#
if(psm.screen.checkButton(0,0,320,320)):
if(psm.screen.isTouched()):
# if screen was touched,
# reset BAS1 touch count
count = count + 1
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/04-EV3-TouchSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#
# check if screen touched.
#
if(psm.screen.checkButton(0,0,320,320)):
if(psm.screen.isTouched()):
# if scren was touched,
# reset BAS1 touch count
psm.BAS1.resetTouchesEV3()
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/04-NXT-LightSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#
# check if screen touched.
#
if(psm.screen.checkButton(0,0,320,320)):
if(psm.screen.isTouched()):
# if scren was touched,
if ( reflectiveMode == False):
reflectiveMode = True
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/04-NXT-TouchSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#
# check if screen touched.
#
if(psm.screen.checkButton(0,0,320,320)):
if(psm.screen.isTouched()):
# if scren was touched,
# reset BAS1 touch count
psm.BAS1.resetTouchesNXT()
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/40-EV3ColorSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
psm.screen.termPrintln("Exiting to menu")
doExit = True
change = 0
if(psm.screen.checkButton(0,0,320,320)): #Change mode if screen is tapped
if(psm.screen.isTouched()): #Change mode if screen is tapped
count = count + 1
if ( count > 2):
count = 0
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/40-EV3Gyro.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
psm.screen.termPrintln("Exiting to menu")
doExit = True
change = 0
if(psm.screen.checkButton(0,0,320,320)): #Change mode if screen is tapped
if(psm.screen.isTouched()): #Change mode if screen is tapped
count = count + 1
if ( count > 1):
count = 0
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/40-EV3InfraredSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
psm.screen.termPrintln("Exiting to menu")
doExit = True
change = 0
if(psm.screen.checkButton(0,0,320,320)): #Change mode if screen is tapped
if(psm.screen.isTouched()): #Change mode if screen is tapped
count = count + 1
if ( count > 2):
count = 0
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/40-EV3Ultrasonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
psm.screen.termPrintln("Exiting to menu")
doExit = True
change = 0
if(psm.screen.checkButton(0,0,320,320)): #Change mode if screen is tapped
if(psm.screen.isTouched()): #Change mode if screen is tapped
count = count + 1
if ( count > 2):
count = 0
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/40-NXTLightSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
psm.screen.termPrintln("Exiting to menu")
doExit = True
change = 0
if(psm.screen.checkButton(0,0,320,320)): #Change mode if screen is tapped
if(psm.screen.isTouched()): #Change mode if screen is tapped
count = count + 1
if ( count > 1):
count = 0
Expand Down
2 changes: 1 addition & 1 deletion programs/50-SensorDemos/40-TouchSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
psm.screen.termPrintAt(4, msg2)


elif(psm.screen.checkButton(0,0,320,320)):
elif(psm.screen.isTouched()):
#
# check if screen touched.
#
Expand Down
2 changes: 1 addition & 1 deletion programs/60-Games/04-GoButton.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

psm.screen.termPrintAt(5, "GO Button is = " +str(psm.isKeyPressed()))
psm.screen.termPrintAt(6, "Press Count = " +str(psm.getKeyPressCount()))
if (psm.screen.checkButton(0,0,320,320)):
if (psm.screen.isTouched()):
psm.screen.termPrintln(" ")
psm.screen.termPrintln("Exiting .....")
exit = True
Expand Down
7 changes: 3 additions & 4 deletions programs/60-Games/04-Paint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
if psm.isF4Pressed():
color = (0, 0, 255)

tsx, tsy = psm.screen.getTouchscreenValues()
if (tsx, tsy) != (0, 0):
x = psm.screen.TS_To_ImageCoords_X(tsx,tsy)
y = psm.screen.TS_To_ImageCoords_Y(tsx,tsy)
if psm.screen.isTouched():
x = psm.screen.TS_To_ImageCoords_X(psm.screen.x, psm.screen.y)
y = psm.screen.TS_To_ImageCoords_Y(psm.screen.x, psm.screen.y)
psm.screen.fillRect(x-1, y-1, 2, 2, fill=color)
Empty file modified programs/folder.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified programs/leftarrow.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified programs/missing.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified programs/ms-logo-w320-h240.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified programs/python.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed programs/refresh.png
Binary file not shown.
Binary file added programs/refresharrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added programs/returnarrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified programs/rightarrow.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion programs/touch_sensor_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
numTouch = psm.BBS1.numTouchesEV3()
psm.screen.termReplaceLastLine(str(touch) + " " + str(numTouch))

if(psm.screen.checkButton(0,0,320,320)):
if(psm.screen.isTouched()):
psm.screen.termPrintln("")
psm.screen.termPrintln("Exiting to menu")
doExit = True
Empty file modified programs/uparrow.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b6d1a12

Please sign in to comment.