Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Update nodes doc from PR: 93 #64

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

[//]: # (Custom component imports)

import DocString from '@site/src/components/DocString';
import PythonCode from '@site/src/components/PythonCode';
import Parameters from '@site/src/components/Parameters';
import AppDisplay from '@site/src/components/AppDisplay';
import SectionBreak from '@site/src/components/SectionBreak';
import AppendixSection from '@site/src/components/AppendixSection';

[//]: # (Docstring)

import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt';
import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt';
import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml';

<DocString>{DocstringSource}</DocString>
<PythonCode GLink='bin/flojoy-io/docs/docs/./INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/SERIAL_SINGLE_MEASUREMENT.py'>{PythonSource}</PythonCode>
<Parameters>{ParametersSource}</Parameters>

<SectionBreak />



[//]: # (Examples)

## Examples

<AppDisplay
GLink='bin/flojoy-io/docs/docs/./INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT'
nodeLabel='SERIAL_SINGLE_MEASUREMENT'>
</AppDisplay>

<SectionBreak />



[//]: # (Appendix)

import Notes from '!!raw-loader!./appendix/notes.md';
import Hardware from '!!raw-loader!./appendix/hardware.md';
import Media from '!!raw-loader!./appendix/media.md';

## Appendix

<AppendixSection index={0} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/'>{Notes}</AppendixSection>
<AppendixSection index={1} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/'>{Hardware}</AppendixSection>
<AppendixSection index={2} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./INSTRUMENTS/Serial/SERIAL_SINGLE_MEASUREMENT/appendix/'>{Media}</AppendixSection>


Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Node to take a single reading of data from an Ardunio,
or a similar serial device.
For example you can record temperature following this tutorial:

https://learn.adafruit.com/thermistor/using-a-thermistor

with Serial.println(steinhart) as the only line printing.

It is important that the last line Arduino is returning is the
data with a new line at the end (i.e. println()).

The other lines must be returned with print()
with print(",") between each line.

For example:

print(reading0)
print(",")
println(reading1)

If there is more than one column, the SELECT_ARRAY node must be
used after this node.

params:
BAUD_RATE: Baud rate for the serial device.
com_port: COM port of the serial device

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
baudrate:
default: 9600
type: float
comport:
default: /dev/ttyUSB0
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from flojoy import flojoy, DataContainer
from time import sleep
import serial
import numpy as np
from datetime import datetime
import plotly.graph_objects as go


@flojoy
def SERIAL_SINGLE_MEASUREMENT(dc_inputs, params):

print("parameters passed to SERIAL_TIMESERIES: ", params)
COM_PORT = params["comport"]
BAUD = int(params["baudrate"])

ser = serial.Serial(COM_PORT, timeout=1, baudrate=BAUD)
# The first reading is commonly empty.
s = ser.readline().decode()

# Some readings may be empty. Try a second time if so.
if s != "":
reading = s[:-2].split(",")
else:
s = ser.readline().decode()
reading = s[:-2].split(",")

reading = np.array(reading)
reading = reading.astype("float64")

data = go.Line(x=[0], y=[0], mode="markers")
fig = go.Figure(data=data)
return DataContainer(type="plotly", fig=fig, x=[0], y=reading)


@flojoy
def SERIAL_SINGLE_MEASUREMENT_MOCK(dc, params):
print("Running mock version of Serial")

x = np.linspace(0, 100, 100)
y = np.linspace(0, 100, 100)

return DataContainer(x=x, y=y)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

[//]: # (Custom component imports)

import DocString from '@site/src/components/DocString';
import PythonCode from '@site/src/components/PythonCode';
import Parameters from '@site/src/components/Parameters';
import AppDisplay from '@site/src/components/AppDisplay';
import SectionBreak from '@site/src/components/SectionBreak';
import AppendixSection from '@site/src/components/AppendixSection';

[//]: # (Docstring)

import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt';
import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt';
import ParametersSource from '!!raw-loader!./a1-[autogen]/parameters.yaml';

<DocString>{DocstringSource}</DocString>
<PythonCode GLink='bin/flojoy-io/docs/docs/./INSTRUMENTS/Serial/Serial_timeseries/SERIAL_TIMESERIES.py'>{PythonSource}</PythonCode>
<Parameters>{ParametersSource}</Parameters>

<SectionBreak />



[//]: # (Examples)

## Examples

<AppDisplay
GLink='bin/flojoy-io/docs/docs/./INSTRUMENTS/Serial/Serial_timeseries'
nodeLabel='SERIAL_TIMESERIES'>
</AppDisplay>

<SectionBreak />



[//]: # (Appendix)

import Notes from '!!raw-loader!./appendix/notes.md';
import Hardware from '!!raw-loader!./appendix/hardware.md';
import Media from '!!raw-loader!./appendix/media.md';

## Appendix

<AppendixSection index={0} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./INSTRUMENTS/Serial/Serial_timeseries/appendix/'>{Notes}</AppendixSection>
<AppendixSection index={1} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./INSTRUMENTS/Serial/Serial_timeseries/appendix/'>{Hardware}</AppendixSection>
<AppendixSection index={2} folderPath='nodes/nodes/bin/flojoy-io/docs/docs/nodes/./INSTRUMENTS/Serial/Serial_timeseries/appendix/'>{Media}</AppendixSection>


Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

Node to take simple time dependent 1d data from an Ardunio,
or a similar serial device.
For example, you can record temperature following this tutorial:

https://learn.adafruit.com/thermistor/using-a-thermistor

with Serial.println(steinhart) as the only line printing.

It is important that the last line Arduino is returning is the
data with a new line at the end (i.e. println()).

The other lines must be returned with print()
with print(",") between each line.

For example:

print(reading0)
print(",")
println(reading1)

If there is more than one column, the SELECT_ARRAY node must be
used after this node.

params:
num_readings: Number of points to record.
record_period: Length between two recordings in seconds.
BAUD_RATE: Baud rate for the serial device.
com_port: COM port of the serial device

num_readings * record_period is roughly the run length in seconds.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
baudrate:
default: 9600
type: int
comport:
default: /dev/ttyACM0
type: string
num_readings:
default: 100
type: int
record_period:
default: 1
type: float
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from flojoy import flojoy, DataContainer
from time import sleep
import serial
import numpy as np
from datetime import datetime
import plotly.graph_objects as go


@flojoy
def SERIAL_TIMESERIES(dc_inputs, params):


COM_PORT = params.get("com_port", "/dev/ttyUSB0")
BAUD = params.get("baudrate", 9600)
NUM = params.get("num_readings", 100)
RECORD_PERIOD = params.get("record_period", 1)

ser = serial.Serial(COM_PORT, timeout=1, baudrate=BAUD)
readings = []
times = []
# The first reading is commonly empty.
s = ser.readline().decode()

for i in range(NUM):
ts = datetime.now()
s = ser.readline().decode()
# Some readings may be empty.
if s != "":
reading = s[:-2].split(",")
if len(reading) == 1:
reading = reading[0]
readings.append(reading)

ts = datetime.now()
seconds = float(
ts.hour * 3600 + ts.minute * 60 + ts.second + ts.microsecond / 10**6
)

times.append(seconds)

if len(times) > 0:
time1 = seconds - times[i]
else:
# Estimate execution time.
time1 = 0.1

if time1 < RECORD_PERIOD:
sleep(RECORD_PERIOD - time1)

times = np.array(times)
try:
times -= times[0]
except IndexError:
raise IndexError("No data detected from the Arduino")

readings = np.array(readings)
readings = readings.astype("float64")
# If there are two or more columns return a Plotly figure.
if readings.ndim == 2:
data = go.Line(x=times, y=readings[:, 0], mode="markers")
fig = go.Figure(data=data)
return DataContainer(type="plotly", fig=fig, x=times, y=readings)
else:
return DataContainer(x=times, y=readings)


@flojoy
def SERIAL_TIMESERIES_MOCK(dc, params):
x = np.linspace(0, 100, 100)
y = np.linspace(0, 100, 100)
return DataContainer(x=x, y=y)
Loading