def __init__(self, pub): global self_motor self_motor = self self.psm = PiStorms() self.speed = 0 self.pub = pub self.pendulum_state = None self.time = 0.0 self.led_flag = True
def __init__(self): global self_motor self_motor = self self.psm = PiStorms() self.angle = 0 self.isReady = False self.pub = mqtt.Client(client_id="motor_pub", transport="TCP") self.pub.connect(MQTT_SERVER, 1883, 60) self.sub = mqtt.Client(client_id="motor_sub", transport="TCP") self.sub.on_connect = self.on_connect self.sub.on_message = self.on_message self.sub.connect(MQTT_SERVER, 1883, 60) thread = threading.Thread(target=self.__sub, args=(self.sub, )) thread.daemon = True thread.start()
# # History: # Date Author Comments # July 7, 2016 Yug Rao Initial Authoring from picamera.array import PiRGBArray from picamera import PiCamera import os,sys,inspect,time#thread from subprocess import call import cv2 import imutils currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms psm = PiStorms() try: picam = PiCamera() except: m = ["PopHeads", "Camera not enabled.", "Run raspi-config and enable camera"] psm.screen.askQuestion(m,["OK"]) exit() exitNow = 0 time.sleep(.2) # Create the haar cascade haar_path=currentdir+"/haarcascade_frontalface_default.xml" faceCascade = cv2.CascadeClassifier(haar_path) #psm.screen.fillRect(95, 145, 110, 160) #psm.screen.fillRect(100, 150, 100, 150, fill=(0,0,0)) while not exitNow:
#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 # July 2015 Henry Initial Authoring from SensorShield import SensorShield import os,sys,inspect,time currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintAt(2, "PiStorms ") psm.screen.termPrintAt(3, "GO button test:") exit = False print "Running Button Test" print "press anywhere in PiStorms Screen to exit" psm.screen.termPrintAt(8, "Touch Display to Exit") psm.screen.termPrintln(" ") while(not exit): pass 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)):
mindsensors_i2c.__init__(self, color_address >> 1) def get_colornum(self): try: return (self.readIntegerBE(self.Color_COMMAND)) except: print("Error: Could not read color") return "" HC = HiTechnicColorV2() # END CLASSES # # CONSTANTS # PSM = PiStorms() SCREEN = PSM.screen M1 = PSM.BAM1 M2 = PSM.BAM2 AM = (M1, M2) M3 = PSM.BBM1 M4 = PSM.BBM2 BM = (M3, M4) ML = AM + BM S1 = PSM.BAS1 S2 = PSM.BAS2
#!python """ DiffDrive robot example """ from PiStorms import PiStorms import bot import requests import time psm = PiStorms() desc = bot.DiffDescription( psm.BAM1, psm.BBM1, axel_radius=20.47875/100/2, wheel_radius=3.6/100/2, reverse_forward=True ) driver = bot.DiffDriver(desc) #locator = bot.DiffLocator(desc) locator = bot.RemoteLocator() path_follower = bot.PathFollower(driver, locator) def path_changed_handler(path, voxels): path_follower.path = path path_finder = bot.RemotePathFinder(path_changed_handler)
from PiStorms import PiStorms from HiTechnicColorV2 import HiTechnicColorV2 from time import sleep from threading import Thread, Event from pid import PIDController import math print "running program" FOLLOW_SPEED = 15 SEARCH_SPEED = 70 WHEEL_DIAMETER = 2.25 # in ROBOT_WIDTH = 6.5 # in psm = PiStorms() hc = HiTechnicColorV2() psm.BBS2.activateCustomSensorI2C() angle_pid = PIDController(-25, 25, 590.0, 0.12, 0.0, 0.0) exit = False victims = 0 ''' def turnDegs(degrees): theta = int(abs(2.0 * ROBOT_WIDTH * degrees / WHEEL_DIAMETER)) print theta if degrees > 0: psm.BBM2.runDegs(theta, SEARCH_SPEED, True, False) else: psm.BBM1.runDegs(theta, SEARCH_SPEED, True, False) sleep(2) '''
# 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 # 04/18/17 Seth Tenembaum Initial development. # # This program introduces the process of continually updating a graph. from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Please wait a moment") psm.screen.termPrintln("as matplotlib loads...") psm.screen.termPrintAt(3, "Press GO to quit.") import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt import numpy as np import tempfile plt.figure(figsize=(4, 3), dpi=80) plt.xlabel('time') plt.ylabel('Voltage (V)') plt.title('Battery Voltage') plt.grid(True)
# 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 # 04/18/16 Deepak Initial development. # from PiStorms import PiStorms print "running program" psm = PiStorms() m = ["EV3ColorSensor-Demo", "Connect EV3 Color sensor to BAS1", "and Press OK to continue.", "Then move colored objects in front", "of Color sensor"] psm.screen.askQuestion(m,["OK"]) doExit = False old_colorValue = True colorValue = True ambientMode = False #main loop while(not doExit): #save the previous value
from PiStorms import PiStorms from time import sleep import sys psm = PiStorms() # PiStorms object exit = False # break loop while (not exit): if (psm.isPressed() == True): #exit psm.BBM1.brakeSync() psm.led(1,0,0,0) psm.screen.clearScreen() psm.screen.termPrintln("") psm.screen.termPrintln("Exiting to menu") sleep(0.5) exit = True
from PiStorms import PiStorms from time import sleep import sys psm = PiStorms() # PiStorms object exit = False # break loop while (not exit): light = psm.BBS1.lightSensorNXT(True) # 520 error = 540 - light #if within 40 on edge, if negative on line, if positive in white # psm.BBM1.setSpeedSync(30) # if (abs(error) < 20): #on edge # psm.BBM1.setSpeedSync(30) # psm.led(1,0,255,0) #green if (error < 0): #on line, turn to right, left wheel accelerate psm.BBM1.setSpeed(25) psm.BBM2.setSpeed(-50) psm.led(1,0,0,255)#blue elif (error > 0): #on white, turn to left, right wheel accelerate psm.BBM2.setSpeed(25) psm.BBM1.setSpeed(-50) psm.led(1,255,0,0)#Red sleep(0.1) if (psm.isKeyPressed()): #exit psm.BBM1.brakeSync() psm.led(1,0,0,0) psm.screen.clearScreen() psm.screen.termPrintln("") psm.screen.termPrintln("Exiting to menu")
#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 # 04/18/17 Seth Tenembaum Initial development. # # This program demonstrates how to create a live-updating graph, but only displaying # the latest n values on screen. It also explicitly sets the y-axis range. # Don't hold the button too long, or you'll turn off the PiStorms! # Tap the touchscreen to exit. from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Please wait a moment") psm.screen.termPrintln("as matplotlib loads...") psm.screen.termPrintAt(3, "Tap and hold the screen to quit.") import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt import numpy as np import tempfile plt.figure(figsize=(4,3), dpi=80) plt.xlabel('time') plt.ylabel('GO button state') plt.title('GO Button') plt.grid(True)
from PiStorms import PiStorms from time import sleep print "running program" psm = PiStorms() for x in range(0, 255): psm.led(1, x, 0, 0) sleep(0.05) sleep(1.0) psm.led(1, 0, 0, 0)
# #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 # 04/18/17 Seth Tenembaum Initial development. # # This program demonstrates using a sensor and displaying multiple lines # (overlapping data series). Here we plot the three axes of tilt from the # AbsoluteIMU sensor. from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Please wait a moment") psm.screen.termPrintln("as matplotlib loads...") psm.screen.termPrintAt(3, "Press GO to quit.") import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt import numpy as np import tempfile from mindsensors import ABSIMU import time plt.figure(figsize=(4,3), dpi=80) plt.xlabel('time') plt.ylabel('tilt')
# 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/ import os,sys,inspect,time,thread,random currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) from PiStorms import PiStorms psm = PiStorms() color = (255, 255, 255) while True: if psm.isKeyPressed(): break if psm.isF1Pressed(): color = (255, 0, 0) if psm.isF2Pressed(): color = (255, 255, 0) if psm.isF3Pressed(): color = (0, 255, 0) if psm.isF4Pressed(): color = (0, 0, 255)
import socket,fcntl,struct currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms from PiStormsInput import PiStormsInput from wireless import Wireless from wifi import Cell import re, subprocess # Globals config_file = "/etc/wpa_supplicant/wpa_supplicant.conf" # Config file for Wi-Fi wifi = None wlan_inteface = "wlan0" psm = PiStorms() # Check if a wifi adapter is available try: wifi = Wireless() wlan_interface = wifi.interfaces()[0] except Exception as e: psm.screen.fillRect(0, 0, 320, 240, fill = (0,0,0), display = False) psm.screen.drawAutoText("No Wi-Fi adapter", 35, 20, fill = (255,0,0), size = 25, display = False) psm.screen.drawAutoText("available!", 35, 50, fill = (255,0,0), size = 25, display = False) psm.screen.drawButton(35, 160, width = 250, height = 40, text="Continue", display=False) psm.screen.fillRect(0, 0, 1, 1, fill = (0,0,0), display = True) while True: cont = psm.screen.checkButton(35, 160, 250, 40) if cont: sys.exit(0)
#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/ # Tic Tac Toe import random import os,sys,inspect,time,thread import socket,fcntl,struct currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms psm = PiStorms() psm.led(1,0,0,0) psm.led(2,0,0,0) def drawLines(): #210x210, 55px side border, 15px vertical border, 70px squares psm.screen.fillRect(124,15, 2,210) psm.screen.fillRect(196,15, 2,210) psm.screen.fillRect(55,84, 210,2) psm.screen.fillRect(55,154, 210,2) def drawBoard(board): # This function prints out the board that it was passed. # "board" is a list of 10 strings representing the board (ignore index 0)
from PiStorms import PiStorms from time import sleep from HiTechnicColorV2 import HiTechnicColorV2 from datetime import datetime print "running program" psm = PiStorms() hc = HiTechnicColorV2() psm.BBS1.activateCustomSensorI2C() blue = 2 red = 9 red2 = 8 counter = 0 last_time = datetime.now() exit = False botDiam = 17.5 wheelDiam = 6.5 target=90 translate=target*botDiam/(wheelDiam) psm.BAM1.resetPos() initialEncoderValue = psm.BAM1.pos() while(psm.BAM1.pos()< translate+initialEncoderValue): psm.BAM1.setSpeed(50) psm.BAM2.setSpeed(-50) psm.led(1, 255, 255, 255) sleep(1)
import time from PiStorms import PiStorms psm = PiStorms() import PID def setSpeed(speed): if speed > 100: speed = 100 elif speed < -100: speed = -100 psm.BAM1.setSpeedSync(-speed) if speed == 0: psm.BAM1.brakeSync() def getDistanceToGoal(): return psm.BAS2.distanceUSEV3() - 400 controller = PID.PIDController(1,0,0.05, getDistanceToGoal, 0.1, 0.5) while not psm.isKeyPressed(): tm = time.time() setSpeed(controller.tick()) sleept = 0.1 - (time.time() - tm) if sleept < 0: sleept = 0 time.sleep(sleept) setSpeed(0)
from PiStorms import PiStorms from time import sleep print "running program" psm = PiStorms() DISTANCE_THRESHOLD = 700 WHITE_THRESHOLD = 400 BLACK_THRESHOLD = 900 WHITE = [12,13,14] ALTERNATOR = -0.1 # Used if I f****d up the motor orientation and -1 is actually how we move forward INV_ALTERNATOR = 0 - ALTERNATOR def distance(): return psm.BBS1.distanceUSEV3() def seeing_other_robot(): return distance() < DISTANCE_THRESHOLD def near_edge(): return psm.BAS2.lightSensorNXT(True) > WHITE_THRESHOLD and psm.BAS2.lightSensorNXT(True) < BLACK_THRESHOLD or psm.BAS1.colorSensorNXT() in WHITE def gtfo(): def turn_180(): psm.BBM1.setSpeed(ALTERNATOR * 100) psm.BBM2.setSpeed(INV_ALTERNATOR * 100) sleep(0.6) psm.BBM1.brake() psm.BBM2.brake() sleep(0.01)
# Date Author Comments # Jan 2016 Nitin Initial Authoring from picamera.array import PiRGBArray from picamera import PiCamera import os, sys, inspect, time #thread import cv2 import imutils import configparser cfg_file = '/usr/local/mindsensors/conf/msdev.cfg' currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from PiStorms import PiStorms psm = PiStorms() config = configparser.RawConfigParser() config.read(cfg_file) homefolder = config.get('msdev', 'homefolder') psm.screen.termPrintln(" ") # Create the haar cascade haar_path = currentdir + "/haarcascade_frontalface_default.xml" faceCascade = cv2.CascadeClassifier(haar_path) # initialize the camera and grab a reference to the raw camera capture try: camera = PiCamera()
# 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/ from PiStorms import PiStorms import MsDevices import time doExit = False psm = PiStorms() buttons = [[255,5,'blob'], [255,45,'movie'], [255,85,'c-mov'], [255,125,'face'], [255,205,'pict'], [5,205,'qrcode'], [70,205,'line'], [135,205,'eye'] ] mode = 1 func = None
# 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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xPC9maWVsZD48dmFsdWUgbmFtZT0iU1BFRUQiPjxzaGFkb3cgdHlwZT0ibWF0aF9udW1iZXIiIGlkPSJQLnlFLTh7NnV5bzEock5saHNlNSI+PGZpZWxkIG5hbWU9Ik5VTSI+MDwvZmllbGQ+PC9zaGFkb3c+PC92YWx1ZT48bmV4dD48YmxvY2sgdHlwZT0ic3lzdGVtX3NsZWVwIiBpZD0iY2BAP0ZjWHUre2xnbW8rX0p7enciPjx2YWx1ZSBuYW1lPSJUSU1FIj48c2hhZG93IHR5cGU9Im1hdGhfbnVtYmVyIiBpZD0iSC5Ed2UqYVleKUBCbzIlVXpUKVoiPjxmaWVsZCBuYW1lPSJOVU0iPjE8L2ZpZWxkPjwvc2hhZG93PjwvdmFsdWU+PC9ibG9jaz48L25leHQ+PC9ibG9jaz48L25leHQ+PC9ibG9jaz48L25leHQ+PC9ibG9jaz48L3N0YXRlbWVudD48L2Jsb2NrPjwveG1sPg== 184e880526960bd774d2be11aadd04c103d1c18b1cfb9bf66e80c527d4a8051e --END BLOCKS-- """ from PiStorms import PiStorms import time psm = PiStorms() while not bool(psm.isKeyPressed()): psm.BAM1.setSpeed(50) time.sleep(1) psm.BAM1.setSpeed(0) time.sleep(1)
#initial setup code import os, sys, inspect, time, thread, random from mindsensors_i2c import mindsensors_i2c from PiStorms import PiStorms from mindsensors import ABSIMU currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) #starts an instance of PiStorms imu = ABSIMU() psm = PiStorms() #exit variable will be used later to exit the program and return to PiStormsMaster exit = False #clears the screen of any unwanted text by displaying a white rectangle #psm.screen.fillRect(0, 0, 320, 240) psm.screen.termPrintln("Custom I2C test program") psm.screen.termPrintln("connect mindsensors.com's ") psm.screen.termPrintln("AbsImu on port BBS1 ") psm.led(1, 0, 0, 0) psm.led(2, 0, 0, 0) psm.BBS1.activateCustomSensorI2C() #Connect the I2C sensor on the port BBS1 #main loop # This test program will print IMU data on Terminal # Compass heading is represented on Red LED on BANKB
import socket, fcntl, struct currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from PiStorms import PiStorms import datetime, subprocess # Globals config_file = "/etc/wpa_supplicant/wpa_supplicant.conf~bk" config_file_actual = "/etc/wpa_supplicant/wpa_supplicant.conf" # Config file for Wi-Fi opt = [] entries = [] error = False psm = PiStorms() try: with open(config_file, "r") as f: dat = f.read() entries = dat.split("\n\n---------------------------\n")[1::] lt = "" for i in entries: tim = datetime.datetime.fromtimestamp(int( i.split("\n")[0])).strftime('%Y-%m-%d %H:%M:%S') if lt != tim: opt.append([tim, i.split("\n", 1)[1], int(i.split("\n")[0])]) lt = tim opt = opt[::-1] except Exception as e: error = True
#Learn more product option visit us @ http://www.mindsensors.com/ # # History: # Date Author Comments # Oct 2015 Michael Initial Authoring import os,sys,inspect,time,thread import socket,fcntl,struct,ms_explorerlib currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms print "running program" psm = PiStorms() psm.screen.termPrintln("Connect I2C device(s) to BAS1") psm.screen.termPrintln("and click Explore") psm.screen.drawButton(75, 95, width = 85, height = 40, text="Explore", display=True) exit = False lastled = 0 def explore(): time.sleep(3) psm.screen.termPrintAt(8, " ") addr = 0x00 # DO NOT change this address!!! i2c = ms_explorerlib.Explorer(addr) found = i2c.ping(0x00) print ">>00 found: " + str(found) # Checks for connection on all I2C addresses until connection is found
# 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 # 04-11-16 Deepak Troubleshooting program import time from PiStorms import PiStorms print "" print "Running program 5 times, press Ctrl-C to terminate" print "" psm = PiStorms() exit = False a = 0 while (a < 5): voltVal = psm.battVoltage() print "PiStorms voltage: " + str(voltVal) time.sleep(2) a = a + 1
#initial setup code import os,sys,inspect,time,thread, random from mindsensors_i2c import mindsensors_i2c from PiStorms import PiStorms from mindsensors import ABSIMU currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) #starts an instance of PiStorms imu=ABSIMU() psm = PiStorms() #exit variable will be used later to exit the program and return to PiStormsMaster doExit = False psm.screen.termPrintln("AbsIMU test") psm.screen.termPrintln("connect mindsensors.com's ") psm.screen.termPrintln("AbsImu to BAS1 sensor Port") psm.led(1, 0,0,0) psm.led(2, 0,0,0) psm.BAS1.activateCustomSensorI2C() #Connect the I2C sensor on the port BBS1 time.sleep(.1) #main loop # This test program will print IMU data on Terminal # Compass heading is represented on Red LED on BANKB # Program will exit when someone touch the screen or Go Button
# # 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 # 04/18/17 Seth Tenembaum Initial development. # from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Please wait a moment") psm.screen.termPrintln("as matplotlib loads...") psm.screen.termPrintAt(3, "Press GO to quit.") import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt import numpy as np import tempfile from mindsensors import ABSIMU import threading, time plt.figure(figsize=(4,3), dpi=80) plt.xlabel('time') plt.ylabel('acceleration')
import time from PiStorms import PiStorms from Projects.Camera import cameraModule psm = PiStorms() exit = False psm.screen.clearScreen() psm.screen.termPrintln("") psm.screen.termPrintln("Photo Test x3") count = 0 while not exit and count < 3: psm.screen.clearScreen() psm.screen.termPrintln("Taking Photo " + str(count + 1)) cameraModule.take_photo('/home/pi/PiStormsprograms/images/', 'image01.png') psm.screen.clearScreen() psm.screen.fillBmp(30, 0, 240, 240, path='/home/pi/PiStormsprograms/images/image01.png') count += 1 time.sleep(5) if psm.isKeyPressed(): psm.screen.clearScreen() psm.screen.termPrintln("") psm.screen.termPrintln("Exiting to menu")
# History: # Date Author Comments # March 2016 Roman Bohuk Initial Authoring # Setup (to be present in all programs) import os,sys,inspect,time,thread import socket,fcntl,struct currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms import socket # Globals psm = PiStorms() # Checks if internet is available def available(): try: socket.setdefaulttimeout(5) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("8.8.8.8", 53)) return True except Exception as e: pass return False psm.screen.fillRect(0, 0, 320, 240, fill = (0,0,0), display = False) psm.screen.drawAutoText("Testing internet connection", 20, 30, fill = (255,255,255), size = 23, display = False) psm.screen.fillRect(20, 80, 320, 240, fill = (0,0,0), display = False) psm.screen.fillBmp(110, 110, 100, 100, path = currentdir+'/'+'load.png', display = False) psm.screen.fillRect(0, 0, 1, 1, fill = (0,0,0), display = True)
import time from PiStorms import PiStorms psm = PiStorms() import sys from collections import deque MESSAGE = "P: {}\nI: {}\nD: {}\nKP: {}\nKI: {}\nKD: {}\nSpeed: {}" STEP_SEC = 0.1 FOLLOW_DIST = 250 OUTOFRANGE = 450 SPINTIME = 1 SPINTIME_ADD = 0.5 SPINSPEED = 25 print("DOING") if len(sys.argv) >= 4: Kp = float(sys.argv[1]) Kd = float(sys.argv[2]) Ki = float(sys.argv[3]) print("PARSED K") else: Kp = 1 Kd = 0.05 Ki = 0 if len(sys.argv) >= 5: SCALAR = float(sys.argv[4])
# Date Author Comments # March 2016 Roman Bohuk Initial Authoring # Setup (to be present in all programs) import os, sys, inspect, time, thread import socket, fcntl, struct currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from PiStorms import PiStorms import socket # Globals psm = PiStorms() # Checks if internet is available def available(): try: socket.setdefaulttimeout(5) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect( ("8.8.8.8", 53)) return True except Exception as e: pass return False psm.screen.fillRect(0, 0, 320, 240, fill=(0, 0, 0), display=False)
# 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.termPrintAt(3, "Press GO to quit.") 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)
# 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 # 07/11/16 Yug Rao Initial development. # from PiStorms import PiStorms from LegoDevices import * import time psm = PiStorms() m = ["EV3InfraredSensor-Demo", "Connect EV3 IR sensor", "to BAS1, and Press OK to continue"] psm.screen.askQuestion(m,["OK"]) doExit = False oldValue = True value = True count = 0 # # Instantiate IR object # IR = EV3InfraredSensor("BAS1") psm.screen.termPrintAt(7, "Touch screen to change mode") psm.screen.termPrintAt(8, "Press Go to stop program")
# 10/18/15 Deepak UI improvements and messenger integration from PiStorms import PiStorms from mindsensors_i2c import mindsensors_i2c import sys, os, time, json PROGRAM_DIRECTORY = "/home/pi/PiStormsprograms" json_file = '/var/tmp/ps_data.json' rotation = 3 if(os.getenv("PSREVERSE","0")=="1"): rotation = 3 #print os.getcwd() try: bootmode = mindsensors_i2c(0xEA>>1) bootmode.readbyte() psm = PiStorms("PiStorms",rotation) psm.screen.termPrintAt(4,"PiStorms in fw upgrade mode") except: psm = PiStorms("PiStorms",rotation) def listPrograms(directory): files = os.listdir( directory) #files = os.listdir("./" + directory) x = 0 while(x<len(files)): if(not files[x].endswith(".py")) or (not files[x][0].isdigit()): del files[x] else:
from PiStorms import PiStorms from time import sleep from HiTechnicColorV2 import HiTechnicColorV2 from threading import Thread from datetime import datetime import Queue print "running program" psm = PiStorms() #exit variable will be used later to exit the program and return to PiStorms exit = False def linefollow(): while(not exit): light = psm.BAS1.lightSensorNXT(True) if (light <= 550): psm.BAM2.brake() psm.BAM1.setSpeed(-100) else: psm.BAM1.setSpeed(50) psm.BAM2.setSpeed(-100) if (psm.isKeyPressed()): psm.BAM1.brake() psm.BAM2.brake() exit = True psm.BAM1.brake() psm.BAM2.brake()
import socket, fcntl, struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa( fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]))[20:24]) from PiStorms import PiStorms print "running psm-info.py" psm = PiStorms() print " Version : " + str(psm.GetFirmwareVersion())[:5] print " Vendor : " + str(psm.GetVendorName()) print " Device : " + str(psm.GetDeviceId()) print " HostName : " + socket.gethostname() try: print " eth0 : " + get_ip_address('eth0') except: print " eth0 : not present" try: print " wlan0 : " + get_ip_address('wlan0') except: print " wlan0 : not present"
#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 # July 2015 Henry Initial Authoring from SensorShield import SensorShield import os,sys,inspect,time currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("PiStorms ") psm.screen.termPrintln("GO button test:") psm.screen.termPrintln(" ") exit = False print "Running Button Test" print "press anywhere in PiStorms Screen to exit" psm.screen.termPrintln("Touch Display to Exit") psm.screen.termPrintln(" ") while(not exit): pass psm.screen.termReplaceLastLine("Go Button is = " +str(psm.isKeyPressed())) if (psm.screen.checkButton(0,0,320,320)):
--BLOCKLY FILE-- --START BLOCKS-- PHhtbCB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRtbCI+PGJsb2NrIHR5cGU9InZhcmlhYmxlc19zZXQiIGlkPSJhQW0lfkhpZ1MqdWNrKHR4X11JRyIgeD0iMCIgeT0iMCI+PGZpZWxkIG5hbWU9IlZBUiI+c3Vtb3NlbnNvcjwvZmllbGQ+PGNvbW1lbnQgcGlubmVkPSJ0cnVlIiBoPSI4NSIgdz0iMzQzIj5BdHRhY2ggYSBOWFRTdW1vRXllcyB0byBQb3J0IEJBUzEgb2YgUGlTdG9ybXMuClN0YXJ0IHRoZSBwcm9ncmFtIGZyb20gUGlTdG9ybXMgb24gU2NyZWVuIEJyb3dzZXIgYW5kIHByZXNzIEdPIGJ1dHRvbiB0byB0ZXJtaW5hdGUuPC9jb21tZW50Pjx2YWx1ZSBuYW1lPSJWQUxVRSI+PGJsb2NrIHR5cGU9InNlbnNvcnNfc3Vtb2V5ZXMiIGlkPSJSXz9UMCN+eV80OlBWZE5lSS9BJSI+PGZpZWxkIG5hbWU9InNlbnNvcl9zZWxlY3RvciI+QkFTMTwvZmllbGQ+PC9ibG9jaz48L3ZhbHVlPjxuZXh0PjxibG9jayB0eXBlPSJzZW5zb3JzX3N1bW9leWVzc2V0bW9kZSIgaWQ9IiFAIW1UdXhPYShocz9+VWBKMUhaIj48ZmllbGQgbmFtZT0ibW9kZV9zZWxlY3RvciI+TE9OR19SQU5HRTwvZmll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KmF9IWM/LC9jIXAiPjxmaWVsZCBuYW1lPSJURVhUIj5IZWxsbyBXb3JsZDwvZmllbGQ+PC9zaGFkb3c+PGJsb2NrIHR5cGU9InZhcmlhYmxlc19nZXQiIGlkPSIqUCNAL1Fiaj01a2hDXS5aMWMoTCI+PGZpZWxkIG5hbWU9IlZBUiI+c3RyMTwvZmllbGQ+PC9ibG9jaz48L3ZhbHVlPjx2YWx1ZSBuYW1lPSJ4Ij48c2hhZG93IHR5cGU9Im1hdGhfbnVtYmVyIiBpZD0iRkhpMERXZmszeUZxa2IvaFVSLnMiPjxmaWVsZCBuYW1lPSJOVU0iPjQwPC9maWVsZD48L3NoYWRvdz48L3ZhbHVlPjx2YWx1ZSBuYW1lPSJ5Ij48c2hhZG93IHR5cGU9Im1hdGhfbnVtYmVyIiBpZD0iIVNvVVA3RG5tKFJiUjR7dV5JdDYiPjxmaWVsZCBuYW1lPSJOVU0iPjQwPC9maWVsZD48L3NoYWRvdz48L3ZhbHVlPjx2YWx1ZSBuYW1lPSJzaXplIj48c2hhZG93IHR5cGU9Im1hdGhfbnVtYmVyIiBpZD0iVXpkZk5fP10uVHBsemdKUXBCVUkiPjxmaWVsZCBuYW1lPSJOVU0iPjUwPC9maWVsZD48L3NoYWRvdz48L3ZhbHVlPjwvYmxvY2s+PC9uZXh0PjwvYmxvY2s+PC9zdGF0ZW1lbnQ+PC9ibG9jaz48L25leHQ+PC9ibG9jaz48L25leHQ+PC9ibG9jaz48L3N0YXRlbWVudD48L2Jsb2NrPjwvbmV4dD48L2Jsb2NrPjwvbmV4dD48L2Jsb2NrPjwveG1sPg== e193a87b5d9d2a5cb558efa27c0a1d36f2f2a11d44da1aff62bfbcb2e1712fed --END BLOCKS-- """ from PiStorms import PiStorms import MsDevices sumosensor = None old_zone = None str1 = None psm = PiStorms() sumoeyes_BAS1 = MsDevices.SumoEyes(psm.BAS1) # Attach a NXTSumoEyes to Port BAS1 of PiStorms. # Start the program from PiStorms on Screen # Browser and press GO button to terminate. sumosensor = sumoeyes_BAS1 sumosensor.setRange(sumosensor.LONG_RANGE) while not bool(psm.isKeyPressed()): old_zone = str1 str1 = sumosensor.detectObstactleZone(True) if str1 != old_zone: psm.screen.clearScreen(True) psm.screen.drawAutoText(str1, 40, 40, fill = (255, 0, 0), size = 50, display = True)
# History: # Date Author Comments # 08/11/15 Andrew Initial Authoring # 10/14/15 Nitin performance imporvements # #Demo Code for the PiStorms and Raspberry Pi # initial setup code import os, sys, inspect, time, thread, random currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) from PiStorms import PiStorms # starts an instance of PiStorms psm = PiStorms() ### setup variables ### # exit is used to eventually exit the main running loop # score will keep track of the player's current score # dispScore tracks the displayed score exit = False score = 1 dispScore = -1 # turns the leds off from any previous program psm.led(1, 0, 0, 0) psm.led(2, 0, 0, 0) # sets screen to a white background psm.screen.fillRect(0, 0, 320, 240)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa( fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]))[20:24]) currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from PiStorms import PiStorms print "running program" psm = PiStorms() psm.screen.termPrintln(" About Me") psm.screen.termPrintln(" ") exit = False lastled = 0 psm.screen.termPrintAt(2, " Version : " + str(psm.GetFirmwareVersion())[:5]) psm.screen.termPrintAt(3, " Vendor : " + str(psm.GetVendorName())) psm.screen.termPrintAt(4, " Device : " + str(psm.GetDeviceId())) psm.screen.termPrintAt(6, " HostName : " + socket.gethostname()) while (not exit): try: psm.screen.termPrintAt(7, " eth0 : " + get_ip_address('eth0')) except:
from PiStorms import PiStorms import time, datetime, math, random, numpy from pixy import * from ctypes import * psm = PiStorms() SHOULDRUN = True class Finder(object): def __init__(self, camera, driver, grabber): self.camera = camera self.driver = driver self.grabber = grabber self.xCenter = 160 self.targetHeight = 100 def Step(self): red_block = self.camera.findSpecificBlock(1) print red_block.signature if red_block == None: print "The block does not exist." else: if red_block.x > self.xCenter: driver.leftTurn() elif red_block.x < self.xCenter:
from PiStorms import PiStorms from time import sleep print "running program" psm=PiStorms() #exit variable will be used later to exit the program and return to PiStorms exit=False black=700 white=400 leftinit=(-50) #motor value when see black leftrange=(-50) #motor value + init when see black rightinit=(-25) rightrange=(75) average=(black+white)/2 width=(black-white)/2*1.1 while(not exit): light=psm.BAS1.lightSensorNXT(True) proportions=(light-average)/width psm.BAM1.setSpeed(rightinit+proportions*rightrange) psm.BAM2.setSpeed(leftspeed+proportions*leftrange) psm.led(1,255,0,255) sleep(0.1) if(psm.isKeyPressed()): # if the GO button is pressed psm.screen.clearScreen()
#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 # July 2015 Henry Initial Authoring from SensorShield import SensorShield import os, sys, inspect, time currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("PiStorms ") psm.screen.termPrintln("GO button test:") psm.screen.termPrintln(" ") exit = False print "Running Button Test" print "press anywhere in PiStorms Screen to exit" psm.screen.termPrintln("Touch Display to Exit") psm.screen.termPrintln(" ") while (not exit): pass psm.screen.termReplaceLastLine("Go Button is = " + str(psm.isKeyPressed())) if (psm.screen.checkButton(0, 0, 320, 320)):
from PiStorms import PiStorms from time import sleep print "running program" psm = PiStorms() #exit variable will be used later to exit the program and return to PiStorms exit = False while(not exit): #put your cool code here # I will turn a light on psm.led(1,0,255,0) sleep(0.25) if(psm.isKeyPressed() == True): # if the GO button is pressed psm.screen.clearScreen() psm.screen.termPrintln("") psm.screen.termPrintln("Exiting to menu") psm.led(1,0,0,0) sleep(0.5) exit = True
# July 7, 2016 Yug Rao Initial Authoring from picamera.array import PiRGBArray from picamera import PiCamera import os, sys, inspect, time #thread from subprocess import call import numpy as np from PIL import Image import cv2 import imutils currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from PiStorms import PiStorms psm = PiStorms() try: picam = PiCamera() except: m = [ "PopHeads", "Camera not enabled.", "Run raspi-config and enable camera" ] psm.screen.askQuestion(m, ["OK"]) exit() exitNow = 0 time.sleep(.2) haar_path = currentdir + "/haarcascade_frontalface_default.xml" faceCascade = cv2.CascadeClassifier(haar_path) #psm.screen.fillRect(95, 145, 110, 160) #psm.screen.fillRect(100, 150, 100, 150, fill=(0,0,0))
import os,sys,inspect,time,thread import socket,fcntl,struct currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms import datetime, subprocess # Globals config_file = "/etc/wpa_supplicant/wpa_supplicant.conf~bk" config_file_actual = "/etc/wpa_supplicant/wpa_supplicant.conf" # Config file for Wi-Fi opt = [] entries = [] error = False psm = PiStorms() try: with open(config_file, "r") as f: dat = f.read() entries = dat.split("\n\n---------------------------\n")[1::] lt = "" for i in entries: tim = datetime.datetime.fromtimestamp(int(i.split("\n")[0])).strftime('%Y-%m-%d %H:%M:%S') if lt != tim: opt.append([tim,i.split("\n",1)[1],int(i.split("\n")[0])]) lt = tim opt = opt[::-1] except Exception as e: error = True with open(config_file, "w+") as f:
# # History: # Date Author Comments # Jan 2016 Nitin Initial Authoring # Jun 2016 Yug Rao modified to show stream and circle overlay. from picamera.array import PiRGBArray from picamera import PiCamera import os,sys,inspect,time#thread import cv2 import imutils currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln(" ") # # To exit this program, press & hold GO button and touch the screen # psm.screen.termPrintAt(1, "To Exit: press & hold GO button") psm.screen.termPrintAt(2, "and touch the screen.") time.sleep(2) # Get user supplied values #cascPath = sys.argv[1]
def init(): global psm writeDebug("===Starting on " + datetime.datetime.now().strftime("%D %I:%M %p")) psm = PiStorms()
# 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 # 04/15/16 Deepak Initial development. # from PiStorms import PiStorms print "running program" psm = PiStorms() m = [ "Motor-Demo", "Connect motor to Bank A M1.", "Motor will turn 360 degrees, and stop", "with brake and hold.", "Click OK to continue" ] psm.screen.askQuestion(m, ["OK"]) # run motor for 360 degrees, and at the completion, # brake while stopping and hold position while stopped psm.BAM1.runDegs(360, 75, True, True) m = [ "Motor-Demo", "Motor should have turned 360 degrees", "and stop with brake and hold.", "click EXIT to exit program"
# 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 # 04/18/17 Seth Tenembaum Initial development. # # This program introduces the process of continually updating a graph. from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Please wait a moment") psm.screen.termPrintln("as matplotlib loads...") psm.screen.termPrintAt(3, "Press GO to quit.") import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt import numpy as np import tempfile plt.figure(figsize=(4,3), dpi=80) plt.xlabel('time') plt.ylabel('Voltage (V)') plt.title('Battery Voltage') plt.grid(True)
# # 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 # 04/18/16 Deepak Initial development. # from PiStorms import PiStorms psm = PiStorms() m = [ "NXTTouchSensor-Demo", "Connect NXT Touch sensor", "to BAS1, and Press OK to continue" ] psm.screen.askQuestion(m, ["OK"]) doExit = False old_touch = True touch = True old_touch_count = 0 touch_count = 0 #main loop
# #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 # July 2015 Henry Initial Authoring from SensorShield import SensorShield import os,sys,inspect,time,thread currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0,parentdir) from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Battery Voltage") psm.screen.termPrintln(" ") psm.BBS1.resetTouchesEV3() exit = False lastled = 0 while(not exit): voltVal = psm.battVoltage() psm.screen.termReplaceLastLine(str(voltVal) + "V") if(voltVal >= 8and lastled != 1): psm.led(1,0,255,0) psm.led(2,0,255,0) lastled = 1
# 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/ import os, socket import ConfigParser from PiStorms import PiStorms psm = PiStorms() config = ConfigParser.RawConfigParser() config.read("/usr/local/mindsensors/conf/msdev.cfg") homefolder = config.get("msdev", "homefolder") try: with open(os.path.join(homefolder, ".version"), "r") as f: version_no = f.readline().strip() except IOError: version_no = "unknown" psm.screen.drawDisplay("About Me") psm.screen.termPrintln("Device: {}".format(psm.GetDeviceId().rstrip("\0"))) psm.screen.termPrintln("Feature: {}".format( psm.psc.GetDeviceFeatures().rstrip("\0"))) psm.screen.termPrintln("f/w version: {}".format(
from PiStorms import PiStorms from HiTechnicColorV2 import HiTechnicColorV2 from time import sleep from threading import Thread, Event from pid import PIDController import math print 'running program' exit = False psm = PiStorms() ''' if not psm.BAS2.presenceUSEV3(): psm.screen.termPrintln('no ultrasonic sensor') print 'no ultrasonic sensor' exit = True ''' EDGE_LIGHT = 650 RAMP_DIST = 45 RUSH_DIST = 40 RAMP_UP = -115 # actually 120, but with some leeway RAMP_MID = -60 # approximately RAMP_DOWN = 0 # also, negative is up SPEED = 45 WHEEL_DIAMETER = 2.25 # in ROBOT_WIDTH = 4.0 # in def turnDegs(degrees, left=True): theta = int(ROBOT_WIDTH * degrees / WHEEL_DIAMETER) print theta
# #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 # 04/18/17 Seth Tenembaum Initial development. # # This program demonstrates how to create and display a basic, static graph # on the PiStorms screen. # It is heavily based on https://matplotlib.org/examples/pylab_examples/simple_plot.html from PiStorms import PiStorms psm = PiStorms() psm.screen.termPrintln("Please wait a moment") psm.screen.termPrintln("as matplotlib loads...") psm.screen.termPrintAt(3, "Press GO to quit.") import matplotlib matplotlib.use("AGG") import matplotlib.pyplot as plt import numpy as np # setup figure plt.figure(figsize=(4, 3), dpi=80) plt.xlabel('time (s)') plt.ylabel('voltage (mV)') plt.title('About as simple as it gets, folks') plt.grid(True)
# 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/ # SETUP PiStorms and joystick from PiStorms import PiStorms # initialize PiStorms object psm = PiStorms() m = ["Instructions", "Use the left and right joysticks", "to move the left and right motors.", "Press GO to Exit."] psm.screen.showMessage(m) import pygame pygame.init() joystick = pygame.joystick.Joystick(0) joystick.init() # LOOP while GO is not pressed while not psm.isKeyPressed(): # let Pygame update, check the joystick, etc.