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
     
    spring_stretch_actual = 0 
    max_stretch = 0
    i=0
    t = 0.0
    dt = 0.05 #note gdx.start below where it sets the sampling period to 100ms (or 0.1 seconds)
 
    time_at_max_stretch = 0
    index_at_max_stretch = 0
    actual_list = []

    #gdx.start(period=50) #start data collection
    gdx.start(period = (dt*1000))
    
    while t < tmax + dt: #use the loop to read the data
    
        measurements = gdx.read() #returns a list of measurements from the sensors selected.
        if measurements == None: 
            break 
        print('distance (cm) = ', measurements[0]*100)
        spring_stretch_actual = measurements[0]*100 - starting_spring_position
        spring_actual.axis.y =  -spring_equilibrium_length + spring_stretch_actual
        mass_actual.pos.y = spring_actual.pos.y-spring_equilibrium_length + spring_stretch_actual
        actual_data.plot(t,spring_stretch_actual)
        actual_list.append(spring_stretch_actual) #create a list of all the measurements. Store in a variable to send to the Model function
    
        if spring_stretch_actual>max_stretch: #Capture the biggest stretch. Store in variables to send to the Model function
            max_stretch=spring_stretch_actual
            time_at_max_stretch = t
            index_at_max_stretch = i
    
        t = t + dt
        i = i + 1
    gdx.stop()  
Пример #2
0
def update(frame):
    measurements = gdx.read()[0]
    time = len(xdata) / sample_rate
    xdata.append(time)
    ydata.append(measurements)
    xmin, xmax = ax.get_xlim()
    ymin, ymax = ax.get_ylim()

    if time >= xmax:
        ax.set_xlim(xmin, 2 * xmax)
        ax.figure.canvas.draw()
    if measurements >= ymax:
        ax.set_ylim(ymin, measurements + 5)
        ax.figure.canvas.draw()
    if measurements <= ymin:
        ax.set_ylim(measurements - 5, ymax)
        ax.figure.canvas.draw()
    ln.set_data(xdata, ydata)

    return ln,
Пример #3
0
    def __init__(self):
        #############################################################
        # Global Variables
        #############################################################
        #example: self.dx_1_read_position_data = 0
        self.sensor_status = 0
        #############################################################
        # Publisher Parts
        #############################################################
        self.pub_respiration_belt_data = rospy.Publisher(
            "respiration_belt/data", Float32MultiArray, queue_size=10)
        #############################################################
        # Subscriber Parts
        #############################################################
        # Set up your subscriber and define its callback
        self.sub_h10_request_state = rospy.Subscriber(
            "/respiration_belt/status", Bool,
            self.sub_respiration_belt_state_callback)

        #############################################################
        # ROS main loop
        #############################################################
        r = rospy.Rate(sensor_sampling_rate)  # 10hz
        while not rospy.is_shutdown():
            if self.sensor_status == True:
                gdx.start(sensor_sampling_rate)
                arr_resp_belt_data = gdx.read()
                self.pub_respiration_belt_data.publish(
                    Float32MultiArray(data=arr_resp_belt_data))
            else:
                gdx.stop()
                pass

            r.sleep()
        gdx.close()

        rospy.spin()  # Spin until ctrl + c
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)
        print(measurements)

gdx.stop()
gdx.close()

# If you did not hard-code in an absolute path, this is where the file should be found.
print("location of current working directory = ", os.getcwd())
Пример #5
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()
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Below is a simple starter program. Note that this program does not pass any 
arguments in the functions. Go to the gdx_getting_started_2.py example to 
see how you can pass arguments to the open(), select sensors(), and start() 
functions, and avoid the prompts.

**** This example assumes the Go Direct sensor is connected via USB.

'''
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()
gdx.select_sensors()
gdx.start() 

begin = time.time()
for i in range(0,10):
    measurements = gdx.read() #returns a list of measurements from the sensors selected.
    if measurements == None: 
        break 
    print(measurements)
end = time.time()
final = end - begin
print("")
print(final, "is total runtime")
gdx.stop()
gdx.close()