Esempio 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)
'''
import time
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 = ''
Esempio n. 4
0
                device.

Note the example also uses gdx.device_info() and gdx.enabled_sensor_info() to get device 
and sensor information.

**** go to the gdx.open_ble() function and delete "GDX-FOR 071000U9" and 
replace it with your device's name (order code followed by a blank space followed by 
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):
Esempio n. 5
0
Motion Detector sensor numbers are [5,6,7].

This example highlights the use of the following gdx functions:

gdx.device_info()
gdx.sensor_info()
gdx.enabled_sensor_info()

Note: This example assumes one Go Direct device
'''

from gdx import gdx
gdx = gdx.gdx()

#gdx.open_usb() #uncomment this function and comment out the ble function if you wish to connect via USB
gdx.open_ble()

# Return the device_info list [name, description, battery %, charger state, rssi]
input('press enter to get device info')
device_info = gdx.device_info()
device_name = device_info[0]
device_description = device_info[1]
battery = device_info[2]
charger_state = device_info[3]
rssi = device_info[4]
print("device name = ", device_name)
print("device description = ", device_description)
print("battery charge % = ", battery)
print("charging state of the battery = ", charger_state)
print("rssi (bluetooth signal) = ", rssi)
print()
# 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
Esempio n. 7
0
#!/usr/bin/env python3
#[SMART LAB] ROS template by Wonse Jo
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