Esempio n. 1
0
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)
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 psm.getKeyPressCount() < 1:
    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)
Esempio n. 2
0
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')
plt.title('AbsoluteIMU Pendulum')
plt.grid(True)

imu = ABSIMU()
psm.BAS1.activateCustomSensorI2C()  # see example in 50-SensorDemos

data = np.empty(
    0, dtype="int_")  # data starts completely empty (signed integer data type)

# We could take the same approach as the previous examples, but unfortunately
# the process of generating the graph image, saving it, and drawing it to the screen
# takes roughly 1 second (for 76,800 pixels in a roughly 15kb file). Taking
# readings this slowly would not be very useful, so instead we'll constantly read
# the sensor's value, and just update the graph as fast as we can.
# We use threads to accomplish this. The method below, captureData(), will be
# running on a separate thread. It will take a reading from the AbsoluteIMU about
# one hundred times per second, which should be plenty for this experiment.
# It stores these values in the data variable. Meanwile (further down) a loop
# will continue to re-plot the data as it is updated and show it on the screen.
#Demo Code for the PiStorms and Raspberry Pi


#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
Esempio n. 4
0
#Demo Code for the PiStorms and Raspberry Pi

#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
Esempio n. 5
0
import time

plt.figure(figsize=(4,3), dpi=80)
plt.xlabel('time')
plt.ylabel('tilt')
plt.title('3-Axis AbsoluteIMU Tilt')
plt.grid(True)
plt.ylim((-130, 130))

# this time data will be a 3 by 10 array, storing the latest ten values for each axis
data = np.zeros([3,10])
plt.plot(data.T) # transpose
axis = plt.gca() # get current axis
axis.set_xticklabels([]) # hide x-axis tick labels

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

while psm.getKeyPressCount() < 1:
    tilt = imu.get_tiltall()[0] # read the x, y, and z tilt data
    if tilt == ('','',''):
        answer = psm.screen.askQuestion(["AbsoluteIMU not found!", "Please connect an AbsoluteIMU sensor", "to BAS1."], ["OK", "Cancel"], goBtn=True)
        if answer != 0: break
        continue # try again after you tap "OK" or press GO
    data = np.roll(data, -1)
    for i in range(3): # update the data array and graph line for each axis
        data[i][-1] = tilt[i]
        axis.lines[i].set_ydata(data[i])
    plt.savefig(image.name, format="png")
    psm.screen.fillBmp(0,0, 320,240, image.name)
Esempio n. 6
0
#!/usr/bin/env python


#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)

# tilt data conversion
def convertTilt(tilt):
from pixy import BlockArray
from pixy import pixy_init
from pixy import pixy_get_blocks
from pixy import *
import math
import time
import datetime
import numpy

from ctypes import *
from PiStorms import PiStorms
from mindsensors_i2c import mindsensors_i2c
from mindsensors import ABSIMU
psm = PiStorms()
absimu = ABSIMU()


#print screen
def p(row, text):
    psm.screen.termPrintAt(row, text)


blockSize = 20  # Correct number

pixy_init()


class Finder(object):
    def __init__(self, driver, SubsumptionPixy, grabber):
        self.driver = driver
        self.SubsumptionPixy = SubsumptionPixy