Ejemplo n.º 1
0
def open_device():
    log.info('attempting to connect over USB')
    try:
        gdx.open_usb()
    except OSError as _:
        gdx.devices = []
        pass
    if not gdx.devices:
        log.info('attempting to connect over BLE')
        try:
            gdx.open_ble(config['device_id'])
        except OSError as _:
            return False
    # select sensors for GDX-RB 0K1007T6 BLE -41
    # 1: Force (N)
    # 2: Respiration Rate (bpm)
    # 4: Steps (steps)
    # 5: Step Rate (spm)
    gdx.select_sensors([1,2])
    gdx.start(int(config['sampling_period_ms']))
    return True
'''
In this example we are saving the data to a csv file to be opened with Excel.

'''

from gdx import gdx
gdx = gdx.gdx()

import csv
import os

#gdx.open_usb()
gdx.open_ble(
)  # Comment this out if you decide to use the gdx.open_usb() function instead.

gdx.select_sensors()

with open('csvexample.csv', 'w', newline='') as my_data_file:
    # The commented-out code below would be used if you want to hard-code in an absolute file path for the location of the csv file...
    #with open('C:/full/path/to/your/documents/folder/csvexample2.csv', 'w', newline='') as my_data_file:
    csv_writer = csv.writer(my_data_file)

    gdx.start(period=200)
    column_headers = gdx.enabled_sensor_info()
    csv_writer.writerow(column_headers)

    for i in range(0, 40):
        measurements = gdx.read()
        if measurements == None:
            break
        csv_writer.writerow(measurements)
Ejemplo n.º 3
0
def simulation(q):

    import time
    from gdx import gdx  #The gdx function calls are from a gdx.py file inside the gdx folder, which must be with this program.

    gdx = gdx.gdx()

    time_between_readings_in_seconds = 0.2
    number_of_readings = 500
    digits_of_precision = 2

    gdx.open_usb()
    gdx.select_sensors(
        [1]
    )  # You will be asked to select the sensors to be used. You can select up to three.

    sensor_times = []
    sensor_readings = []
    period_in_ms = time_between_readings_in_seconds * 1000

    gdx.start(period_in_ms)

    # Data Collection:

    collection_complete = False
    while not collection_complete:
        try:
            time = 0
            print('Starting...')

            for i in range(0, number_of_readings):

                # This is where we are reading the list of measurements from the sensors.
                measurements = gdx.read()
                if measurements == None:
                    break

                q.put([time, measurements[0]])

                # Update the time variable with the new time for the next data point
                time = time + time_between_readings_in_seconds

            # The data collection loop is finished
            collection_complete = True
            print('Data collection complete.')

            #stop sensor readings and disconnect device
            gdx.stop()
            gdx.close()

            q.put('Q')
            exit()

        except KeyboardInterrupt:
            collection_complete = True
            gdx.stop()  #Stop sensor readings
            gdx.close()  #Disconnect the device
            print('data  collection stopped by keypress')
            print('Number of readings: ', i + 1)
            q.put('Q')
            exit()
import matplotlib.pyplot as plt
from gdx import gdx  #The gdx function calls are from a gdx.py file inside the gdx folder, which must be with this program.

gdx = gdx.gdx()

fig, ax = plt.subplots()

# CHANGE TO MATCH YOUR EXPERIMENT
time_between_readings_in_seconds = 0.5
number_of_readings = 20
digits_of_precision = 2

#gdx.open_usb() # Comment out if you are not using a USB connection.
gdx.open_ble()  # Uncomment if you wish to connect via Bluetooth.

gdx.select_sensors(
)  # You will be asked to select the sensors to be used. You can select up to three.
#gdx.select_sensors([1]) # You can also use an argument to select sensors. Separate multiple sensors with a comma, ([1,3])

# This gets the name and units of the sensors selected.
column_headers = gdx.enabled_sensor_info()

# Store the number of sensors. This variable is used in plot_graph() and print_table()
number_of_sensors = len(column_headers)

# Use the columm_headers to create a list of the units for each sensor.
# Use this list of units in the Collect loop below to add the units to the graph
unit_list = []
units = ''
for headers in column_headers:
    units = str(headers[headers.find('('):headers.find(')') + 1])
    unit_list.append(units)
Ejemplo n.º 5
0
the serial number) or "proximity_pairing", or leave it blank. 

'''

from gdx import gdx
gdx = gdx.gdx()

gdx.open_ble(
    "GDX-FOR 071000U9"
)  #replace "GDX-FOR 071000U9" with the name of your device (order code, space, serial number)

device_info = gdx.device_info(
)  # device_info list [0 = name, 1 = description, 2 = battery %, 3 = charger state, 4 = rssi]
battery_level = device_info[2]
charger_state = device_info[3]
print("battery level % = ", battery_level)
print("charger state = ", charger_state)

gdx.select_sensors([1, 2])
gdx.start(period=500)
column_headers = gdx.enabled_sensor_info()
print(column_headers)

for i in range(0, 5):
    measurements = gdx.read()
    if measurements == None:
        break
    print(measurements)

gdx.stop()
gdx.close()
import sys
import time

from gdx import gdx  #the gdx function calls are from a gdx.py file inside the gdx folder.
gdx = gdx.gdx()

gdx.open_usb()
info = gdx.sensor_info()
chan = info[0][0]
gdx.select_sensors(
)  #Auto-selects lowest channel available in connected device
gdx.start()
count = int(0)
num = int(100)  #Number of measurements to take
sensNum = len(
    gdx.getSensors())  #Get total number of sensors to test dictionary against

begin = time.time()
while count < num:
    measurements = gdx.readValuesRetLatestDict(
    )  #returns a list of measurements from the sensors selected
    for val in measurements:
        if count < num:  #Prevents printing out too many measurements, ie packet of 3 printing 100 measurements ends on 102
            print(count + 1, "", val)
        count += 1
end = time.time()
final = end - begin
print("")
print(final, "is total runtime")
gdx.stop()
gdx.close()
# If there is an error trying to find the gdx module, uncomment this to see where
# the program is looking to find the gdx folder
#print(sys.path)

from gdx import gdx
from vpython import *
gdx = gdx.gdx()

import math

canvas(title='<b>Live Freebody Diagram<b>')

hanging_mass=float(input("Enter the mass (in kg) of the hanging mass:"))    # prompts user for mass of hanging mass

gdx.open_ble('GDX-FOR 07200362') # change GDX-FOR ID to match your device
gdx.select_sensors([1,2,3,4])   # GDX-FOR sensors: 1 - force sensor, 2 - x axis accel, 3 - y axis accel, 4 - z axis accel
gdx.start(period=200)   # data collection period of 200 ms, means a sampling rate of 5 samples/second

# create vpython objects for the ring and each force, as well as labels for the forces
obj = ring(axis=vector(0,0,1),radius=0.5,thickness=0.1,color=color.blue)
Pointer_hm = arrow (pos=vector(0,-1.1,0),axis=vector(0,-1,0),length=hanging_mass*9.8,color=color.red)
Label_hm = label(text='<i><b>F</i></b><sub>hanging mass</sub> = '+str(round(9.8*hanging_mass,2))+' N @ 270°',color=color.red,pos=Pointer_hm.pos,xoffset=10,yoffset=-10,box=False,line=False)
Pointer_gdx = arrow(color=color.green)
Label_gdx=label(text='<i><b>F</i></b><sub>GDX-FOR</sub>',color=color.green,pos=Pointer_gdx.pos,xoffset=50,yoffset=20,box=False,line=False)
Pointer_string = arrow(color=color.yellow)
Label_string=label(text='<i><b>F</i></b><sub>string</sub>',color=color.yellow,pos=Pointer_string.pos,xoffset=-50,yoffset=20,box=False,line=False)

# data collection loop, runs for 100 samples or 20 seconds (with a 200 ms period -> see line 27)
for i in range(0,100):
    # get force and direction measurements from GDX-FOR
    measurements = gdx.read()
Ejemplo n.º 8
0
This example assumes the Go Direct sensor is connected via USB. Go to the
gdx_getting_started_4.py example to see how to open a bluetooth connection.

Note that the select_sensors argument is a list and the sensor numbers must be inside 
list brackets, e.g. gdx.select_sensors([1,2,3]).

How do you know what the sensor numbers are on your Go Direct device? Go to 
gdx_getting_started.3.py example to list all of the sensor channels.

'''
import socket, pickle
from gdx import gdx  #the gdx function calls are from a gdx.py file inside the gdx folder.
gdx = gdx.gdx()

gdx.open_usb()
gdx.select_sensors([2])
gdx.start(period=1000)

for i in range(0, 1):
    measurements = gdx.read(
    )  #returns a list of measurements from the sensors selected.
    if measurements == None:
        break
    HOST = 'localhost'
    PORT = 50007
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.listen(5)
    while True:
        conn, addr = s.accept()
        from_client = ''
pos_graph.height = 500
model_data=gcurve(color=color.red)
actual_data=gcurve(color=color.blue)
model_data.plot(0,0)  
actual_data.plot(0,0)
model_data.delete()
actual_data.delete()


scene.autoscale = False


gdx.open_usb()
#gdx.open_ble()

gdx.select_sensors([5]) #use the motion detector distance channel only. This is channel 5


##############################
# A record button is created. Use it to take live measurements from the Motion Detector
##############################
def Record(r):

    model_data.delete() #clear the graph
    actual_data.delete()

    global time_at_max_stretch #these variables will be used to pass the info to the Model function
    global index_at_max_stretch
    global actual_list
    global max_stretch
    global dt
Ejemplo n.º 10
0
import roslib
import sys
import rospy

from std_msgs.msg import Float32MultiArray, Bool

# For Godirect libs.
from gdx import gdx
# define information of Veriner sensors
sensor_name = 'GDX-RB 0K2002Z5'  # change name with your device __name__
sensor_sampling_rate = 10  #unit = milliseconds

gdx = gdx.gdx()
gdx.open_ble(sensor_name)
# 1: Force (N), 2: Respiration Rate (bpm), 4: Steps (steps), 5: Step Rate (spm)
gdx.select_sensors([1, 2, 4, 5])


class veriner_resp_belt_reading():
    #############################################################
    # Subscriber Functions
    #############################################################
    def sub_respiration_belt_state_callback(self,
                                            msg):  #For a callback function
        self.sensor_status = msg.data
        #print(self.sensor_status)

    #############################################################
    # Main Loop
    #############################################################
    def __init__(self):
Ejemplo n.º 11
0
    sys.path.append(gdx_module_path)

# If there is an error trying to find the gdx module, uncomment this to see where
# the program is looking to find the gdx folder
#print(sys.path)

from gdx import gdx
gdx = gdx.gdx()

import math


gdx.open_usb()
#gdx.open_ble()

gdx.select_sensors([1,3,4])   # Hand Dynamometer sensors to use: 3 - y axis accel, 4 - z axis accel
gdx.start(period=200) 


import turtle
square = turtle.Turtle()
square.shape("square")
square.shapesize(5,20)

#for i in range(0,100):
a = True
while a:
    measurements = gdx.read()
    if measurements == None:
        break
    force = measurements[0]/5
Ejemplo n.º 12
0
CLIportP = {}
DataportP = {}
CLIportD = {}
DataportD = {}

CLIportD, DataportD, CLIportP, DataportP = serialConfig(configFileName)

# Get the configuration parameters from the configuration file
configParameters = parseConfigFile(configFileName)

# START QtAPPfor the plot
app = QtGui.QApplication([])

## Vernier
gdx.open_usb()
gdx.select_sensors([6])
gdx.start(period=20)
column_header = gdx.enabled_sensor_info()

## Camera
"""
Available image formats are     (depending on platform):
 - pylon.ImageFileFormat_Bmp    (Windows)
 - pylon.ImageFileFormat_Tiff   (Linux, Windows)
 - pylon.ImageFileFormat_Jpeg   (Windows)
 - pylon.ImageFileFormat_Png    (Linux, Windows)
 - pylon.ImageFileFormat_Raw    (Windows)
"""
img = pylon.PylonImage()
tlf = pylon.TlFactory.GetInstance()
Ejemplo n.º 13
0
from godirect import GoDirect
import matplotlib.pyplot as plt
import queue
import numpy as np
from matplotlib.animation import FuncAnimation
from gdx import gdx

sample_rate = 10
gdx = gdx.gdx()
gdx.open_usb()
gdx.select_sensors(sensors=gdx.devices[0].list_sensors())
gdx.start(period=1000 / sample_rate)  # the unit is millisecond
data = queue.Queue()

# for i in range(0,40):
#     measurements = gdx.read()
#     if measurements == None:
#         break
#     print(data)
#     data.put(measurements)

# animation script
fig, ax = plt.subplots()
plt.xlabel('Time (s)')
plt.ylabel('Force (N)')
xdata, ydata = [], []
ln, = plt.plot([], [], 'r-')
time = 0


def init():