Exemplo n.º 1
0
 def __init__(self, buss_id, address):
     self.gyro = Gyroscope(buss_id, address)
     self.gyro_full_scale = 245
     self.acc = Accelerometer(buss_id, address)
     self.acc_full_scale = 2
     self.fifo = Fifo(buss_id, address)
     self.temp = Temperature(buss_id, address)
Exemplo n.º 2
0
class Minimu:
    VERSION = 'minimu9v5'

    def __init__(self, buss_id, address):
        self.gyro = Gyroscope(buss_id, address)
        self.gyro_full_scale = 245
        self.acc = Accelerometer(buss_id, address)
        self.acc_full_scale = 2
        self.fifo = Fifo(buss_id, address)
        self.temp = Temperature(buss_id, address)

    def enable(self, odr=104):
        self.gyro.enable(odr)
        self.gyro_full_scale = self.gyro.get_full_scale_selection()
        self.acc.enable(odr)
        self.acc_full_scale = self.acc.get_full_scale_selection()
        self.fifo.enable(odr)

    def disable(self):
        self.gyro.disable()
        self.acc.disable()
        self.fifo.disable()

    def read_fifo_raw(self):
        data = np.array(self.fifo.get_data(), dtype=np.int)
        return data

    def read_fifo(self):
        data = np.array(self.fifo.get_data(), dtype=np.double)
        try:
            data[:, :3] *= 1
        except IndexError:
            sleep(0.1)
            data = np.array(self.fifo.get_data(), dtype=np.double)

        data[:, :3] *= self.gyro_full_scale
        data[:, -3:] *= self.acc_full_scale
        data[data > 0] /= 32767
        data[data < 0] /= 32768
        return data

    def read_temperature(self):
        return self.temp.get_temperature()
Exemplo n.º 3
0
def main():
    dt = 0.0001  # the unit time to calculate
    Nsteps = 20  # steps to refresh the screen
    gyro = Gyroscope()
    show = Show()  # create the screen to show the movement of gyroscope
    control = Control(gyro)  # create a screen to control gyroscope
    while True:
        rate(100)  # refresh the screen 100 times one second
        for i in range(Nsteps):
            gyro.go(dt)  # let the gyroscope go
        x, y, z = gyro.GetPos()
        angle = gyro.GetRotationVel() * dt * Nsteps
        show.update(x, y, z,
                    angle)  # update the position and angle of the gyroscope
        control.ShowEnergy()  # show total energy of gyroscope
Exemplo n.º 4
0
import socket
import pickle
from math import sin, cos, pi, radians
from time import sleep
from random import randint

from gyroscope import Gyroscope

import board
import neopixel

g = Gyroscope()

FML = 59
FMR = FML + 1
BMR = 133
BML = BMR + 1
''' LONGBOARD
BACK. X is where setup is located

     BMR BML
       ___
      |   |
     _| x |_
    |       |
    |       |
    |       |
    |       |
    |       |
    |       |
    |_     _|
Exemplo n.º 5
0
import communications as com
from smbus import SMBus
from gyroscope import Gyroscope
from accelerometer import Accelerometer
from barometer import Barometer
from gps import GPSSensor

import numpy as np
from time import sleep

# Initialise the i2c bus
I2CBUS_NUMBER = 1
bus = SMBus(I2CBUS_NUMBER)

# Initialise the gyroscope
gyroscope1 = Gyroscope(bus)

# Initialise the accelerometer
accelerometer1 = Accelerometer(bus)

# Initialise the barometer
barometer1 = Barometer(bus)
barometer1.calibrate()

# Initialise the GPS
gps1 = GPSSensor()
gps1.initialise()

# Initialise the server
server = com.ServerSocket()
server.connect()
Exemplo n.º 6
0
# Simple test for NeoPixels on Raspberry Pi
import time
import board
import neopixel
from gyroscope import Gyroscope

pixel_pin = board.D18  # NeoPixels must be connected to D10, D12, D18 or D21 to work.
num_pixels = 100  # Num of neopixels. 240 is my max
ORDER = neopixel.GRB  # My strip needs this line for normal RGB format

g = Gyroscope()

with neopixel.NeoPixel(pixel_pin,
                       num_pixels,
                       brightness=0.2,
                       auto_write=False,
                       pixel_order=ORDER) as pixels:
    while True:
        x, y, z = g.get_xyz_acceleration()
        pixels.fill((0, 0, 0))
        if abs(x) > 0.3:
            if x > 0:
                print('right')
                c = 0
            else:
                print('left')
                c = 1
            pixels[c::2] = [(100, 0, 0)] * (len(pixels) // 2)
        else:
            pixels.fill((0, 100, 0))
Exemplo n.º 7
0
import matplotlib

matplotlib.use('tkagg')

import matplotlib.pyplot as plt
from itertools import count
import random
from matplotlib.animation import FuncAnimation

from gyroscope import Gyroscope

g = Gyroscope()

x_vals = []
y_vals = []

#index = count()


def animate(i):
    #x_vals.append(next(index))
    #y_vals.append(random.randint(0,5))

    x, y = g.xy_rotation()
    x_vals.append(x)
    y_vals.append(y)

    plt.cla()
    plt.xlabel('X [degrees]')
    plt.ylabel('Y [degrees]')
    plt.xlim([-90, 90])