Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julia1 #1

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
79cc424
Almost working julia1.0 version
mfalt Dec 5, 2018
33d60f3
Update README.md with link to usage examples
baggepinnen Dec 7, 2018
59537ee
Add new directory
marcus-andren Dec 7, 2018
96e726f
Added device tree overlay for BB, which avoids conflict with HDMI/aud…
marcus-andren Dec 7, 2018
4448a3e
Added a readme file for setting up the device tree overlay.
marcus-andren Dec 11, 2018
cbb9e0b
Added instructions on how to load a device tree overlay
marcus-andren Dec 11, 2018
cb61791
Fixed sysled bug
mfalt Dec 20, 2018
db5618e
Updated flashing instructions in installation.md
marcus-andren Apr 10, 2019
d93d27a
Update installation.md
marcus-andren Apr 10, 2019
37f5cf7
Update README.md
marcus-andren Apr 11, 2019
8bf1d0d
Update README.md
marcus-andren Apr 11, 2019
f0f9153
Updated build of docs
marcus-andren Apr 11, 2019
4ab5fd4
Changed from html to md format
marcus-andren Apr 11, 2019
9ba3ac3
Minor changes to the installation instruction.
marcus-andren Apr 11, 2019
bded7b7
Added figures in docs
marcus-andren Apr 11, 2019
5825cd2
fixed dead figure link.
marcus-andren Apr 11, 2019
0db3c54
Updated installation instructions.
marcus-andren Apr 11, 2019
de0b9dc
Added dev page to docs
marcus-andren Apr 11, 2019
ad21955
Updated index
marcus-andren Apr 11, 2019
556b5e7
Minor change to flashing script
marcus-andren Apr 11, 2019
6827c1b
Updated flashing script
marcus-andren Apr 11, 2019
ae91cb6
Updated installation instructions
marcus-andren Apr 11, 2019
441ec87
Fixed GPIO for julia1 and added GPIO on computer side
mfalt Apr 11, 2019
12e1d3f
more readable commands and gpio test
mfalt Apr 11, 2019
52b6b29
Minor changes to installation instructions
marcus-andren Apr 15, 2019
c64d301
Changes in instructions to transfer LabConnections and serbus to BB
marcus-andren Apr 15, 2019
a9c8ff4
updated make
marcus-andren Apr 15, 2019
291ab81
Updated auto-server instructions
marcus-andren Apr 15, 2019
48ea366
minor update to docs
marcus-andren Apr 15, 2019
8aed4a9
Added development to docs
marcus-andren Apr 15, 2019
a8bc9af
Modified development and testing instructions
marcus-andren Apr 15, 2019
9dc39aa
Removed DTO instructions, since they are not required with Debian 4.1…
marcus-andren Apr 15, 2019
002c1d8
Delete obsolete startup.sh
marcus-andren Apr 15, 2019
b2a2f41
Updated development instructions
marcus-andren Apr 15, 2019
cb48ab8
updates startupscript and precompile
mfalt Apr 15, 2019
c217d0d
Remove test file and remove unnessesary code
mfalt Apr 15, 2019
f1ce9b3
Changed overview figs
marcus-andren Apr 15, 2019
5a35462
Changes to overview in README
marcus-andren Apr 15, 2019
31b65c2
Changes to simple example
marcus-andren Apr 15, 2019
752d7a3
Changes in figs
marcus-andren Apr 15, 2019
774ceda
Update development.md
marcus-andren Apr 15, 2019
8a6c738
README.md is fully updated.
marcus-andren Apr 15, 2019
d2b044d
small fix to README
marcus-andren Apr 15, 2019
25aa435
Revised PWM functionality to be compatible with the 4.14 kernel
mgreiff Apr 15, 2019
076696c
Merge branch 'julia1' of https://gitlab.control.lth.se/labdev/LabConn…
mgreiff Apr 15, 2019
369b27a
add precompilatoin of the PWM read/write
mgreiff Apr 15, 2019
a367636
Add notes on the new kernel
mgreiff Apr 16, 2019
838a086
Update installation instructions
mgreiff Apr 16, 2019
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
21 changes: 12 additions & 9 deletions Examples/testLED.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#On beaglebone, run:
# include("LabConnections/src/LabConnections.jl")
# using LabConnections.BeagleBone
# run_server()
# using Main.LabConnections.BeagleBone
# srv = run_server()

using LabConnections.Computer
using Sockets

stream = BeagleBoneStream(ip"192.168.7.2")
led1 = SysLED(1)
Expand All @@ -16,6 +17,7 @@ led4 = SysLED(4)
init_devices!(stream, led1, led2, led3, led4)
ledon = true
for i = 1:100
global ledon
put!(led1, ledon)
put!(led2, !ledon)
put!(led3, ledon)
Expand All @@ -25,24 +27,25 @@ for i = 1:100
get(led1)
get(led2)
get(led3)
#sleep(0.1)
v1,v2,v3 = read(stream) #Sends request to read, reads all inputs for which get! was called
v1 == !v2 == v3 == ledon ? nothing : println("ledon is $ledon, but read v1, v2, v3 = $v1, $v2, $v3")
sleep(0.1)
v1,v2,v3 = .==(read(stream), "1") #Sends request to read, reads all inputs for which get! was called
v1 == !v2 == v3 == ledon ? nothing : println("ledon is $ledon, but read v1, v2, v3 = $v1, $v2, $v3")
ledon = !ledon
end
for i = 1:40
global ledon
send(led1, ledon)
#sleep(0.03)
v1 = read(led1)
v1 = read(led1) == "1"
send(led2, ledon)
#sleep(0.03)
v2 = read(led2)
v2 = read(led2) == "1"
send(led3, ledon)
#sleep(0.03)
v3 = read(led3)
v3 = read(led3) == "1"
send(led4, ledon)
#sleep(0.03)
v4 = read(led4)
v4 = read(led4) == "1"
v1 == v2 == v3 == v4 == ledon ? nothing : println("ledon is $ledon, but read v1, v2, v3, v4 = $v1, $v2, $v3, $v4")
ledon = !ledon
end
Expand Down
12 changes: 12 additions & 0 deletions Examples/tetsGPIO.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using LabConnections.Computer
using Sockets

stream = BeagleBoneStream(ip"192.168.7.2")

gpio112 = GPIO(1, true) # Writing P9.30 (according to setup specification on BB)
gpio66 = GPIO(29, false) # Reading P8.7

init_devices!(stream, gpio112, gpio66)

send(gpio112, true)
val = read(gpio112)
5 changes: 5 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
14 changes: 14 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = "LabConnections"
uuid = "e9ebaa62-f26d-11e8-0a59-692f6511a9a1"
authors = ["Mattias Fält <[email protected]>", "Marcus Greiff", "Marcus Thelander Andrén <[email protected]>"]
version = "0.1.0"

[deps]
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
177 changes: 101 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,111 +2,136 @@
[![coverage report](https://gitlab.control.lth.se/labdev/LabConnections.jl/badges/master/coverage.svg)](https://gitlab.control.lth.se/labdev/LabConnections.jl/commits/master)

# Welcome to LabConnections.jl - the IO-software part of the LabDev project
<img src="docs/images/labio_overview.png" height="200" width="1050">

The goal of this project is to develop a software package in [Julia](https://julialang.org/)
for interfacing with lab processes using either the [BeagleBone Black Rev C](http://beagleboard.org/) (BBB)
<p align="center">
<img align="center" src="docs/src/fig/labio_overview.png" height="180" width="900">
</p>
The goal of this project is to develop a software package in [Julia](https://julialang.org/)
for interfacing with lab processes using either the [BeagleBone Black Rev C](http://beagleboard.org/) (BB)
with custom [IO-board cape](https://gitlab.control.lth.se/labdev/ioboards), or the old IO-boxes in the labs using Comedi.
With this package, the user is able to setup a connection between the
host computer and the IO-device, and send and
With this package, the user is able to setup a connection between the
host computer and the IO-device (BB or old IO-box), and send and
receive control signals and measurements from the lab process.

The full documentation of the package is available [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/index.md).
The full documentation of the package is available [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/julia1/docs/build/index.md).

## Package Overview
The `LabConnections.jl` package is subdivided into two main modules; `Computer`
and `BeagleBone`. `Computer` defines the user interface on the host
computer side, while `BeagleBone` defines low-level types and functions meant
to be used locally on the BBB.

### Computer
<img src="docs/images/computertypes.png" height="300" width="800">

This module contains the user interface on the host computer side, and defines
types for devices/connections to the lab process, and filestreams between the
host computer and different IO-devices (BBB or Comedi). There are currently 3
The `LabConnections.jl` package is subdivided into two main modules; `LabConnections.Computer`
and `LabConnections.BeagleBone`. `LabConnections.Computer` defines the user interface on the host
computer side, while `LabConnections.BeagleBone` defines low-level types and functions meant
to be used locally on the BB.

### LabConnections.Computer
<p align="center">
<img src="docs/src/fig/computertypes.png" height="320" width="900">
</p>

The module `LabConnections.Computer` contains the user interface on the host computer side, and defines
types for devices/connections to the lab process, and filestreams between the
host computer and different IO-devices (BB or Comedi). There are currently 3
different device/connection types (each has the abstract super type `AbstractDevice`):
* `AnalogInput10V` : Represents ±10V connections from the lab process to the IO-device. Each instance will correspond to a physical ±10V measurement signal from the lab process, whose value can be read.
* `AnalogOutput10V` : Represents ±10V connections from the IO-device to the lab process. Each instance will correspond to a physical ±10V input signal to the lab process, whose value can be set.
* `SysLED` : Represents the System LEDs on the BBB. Used for simple testing and debugging from the host computer side.
* `SysLED` : Represents the System LEDs on the BB. Used for simple testing and debugging from the host computer side.

There are 2 different filestream types (each has the abstract super type `LabStream`):
* `BeagleBoneStream` : Represents the data stream between the host computer and the BBB.
* `ComediStream` : Represent the data stream between the host computer and the old IO-boxes using Comedi.
* `BeagleBoneStream` : Represents the data stream between the host computer and the BB.
* `ComediStream` : Represent the data stream between the host computer and the old IO-boxes using Comedi.

### BeagleBone
<img src="docs/images/beaglebonetypes.png" height="300" width="500">
### LabConnections.BeagleBone
<p align="center">
<img src="docs/src/fig/beaglebonetypes.png" height="420" width="700">
</p>

This module defines types representing different pins and LEDs on the BBB, and
The module `LabConnections.BeagleBone` defines types representing different pins and LEDs on the BB, and
functions to change their status and behaviour. There are currently 4 different types defined
(each has the abstract super type `IO_Object`):
* `GPIO` : Represents the BBB's General Purpose Input Output (GPIO) pins.
Each instance will correspond to a physical GPIO pin on the board, and can be
* `GPIO` : Represents the BB's General Purpose Input Output (GPIO) pins.
Each instance will correspond to a physical GPIO pin on the board, and can be
set as an input or output pin, and to output high (1) or low (0).
* `PWM` : Represents the BBB's Pulse Width Modulation (PWM) pins.
* `PWM` : Represents the BB's Pulse Width Modulation (PWM) pins.
Each instance will correspond to a physical PWM pin on the board, which can be
turned on/off, and whose period, duty cycle and polarity can be specified.
* `SysLED` : Represents the 4 system LEDs on the BBB, and can be turned on/off.
Used to perform simple tests and debugging on the BBB.
* `Debug` : Used for debugging and pre-compilation on the BBB. It does
* `SysLED` : Represents the 4 system LEDs on the BB, and can be turned on/off.
Used to perform simple tests and debugging on the BB.
* `Debug` : Used for debugging and pre-compilation on the BB. It does
not represent any physical pin or LED on the board.

**Note:** In addition to GPIO and PWM, the BBB also has pins dedicated for [Serial Peripheral
**Note:** In addition to GPIO and PWM, the BB also has pins dedicated for [Serial Peripheral
Interface](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus) (SPI).
Work to feature this functionality in the module `BeagleBone` is currently ongoing. More
information can be found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/man/introduction.md#spi-development)
Work to include this functionality in the module `LabConnections.BeagleBone` is currently ongoing.

## Getting Started
### Installation
Instructions on installing the required software and setting up a connection between
the host computer and the BBB are found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/man/installation.md#installation-instructions).
First, you should follow the instructions on how to install the required software and setting up a connection between the host computer and the BB. These instructions are found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/julia1/docs/build/man/installation.md#installation-instructions).

### A Simple Example
We will here go through a simple example of using the host computer interface to communicate with the BBB and control the onboard system LEDs.

First make sure that you have followed the installation guide, and that the BBB is running a server and is connected to the host computer.
Then, start the Julia REPL and input

using LabConnections.Computer
to load the host computer interface. Then define a file stream `stream` and connect to the server running on the BBB by inputting

stream = BeagleBoneStream(ip"192.168.7.2")
Now, we continue by defining the LED we want to control

led = SysLED(1)

The object `led` will now correspond to the first system LED on the BBB.
To tell the BBB that we want to control the LED, we make a call to `init_devices!`

init_devices!(stream, led)
Now we can start controlling the LED on the BBB. Let's begin by turning it on

send(led, true)
You should now see the first system LED on the BBB being lit.
The function `send` puts a new command (`true`) to a device (`led`) to the file stream buffer and
sends it immediately to the BBB.
This is a simple example that demonstrates the usage of local devices on the BB via a host computer. The devices that will be used in the example are `SysLED` and `GPIO`.

First make sure that you have followed the installation guide, and that the BB is running a server connected to the host computer.
Then, start a Julia REPL on the host computer and type
```
using LabConnections.Computer
using Sockets
```
to load the host computer interface. Then define a file stream and connect to the server running on the BB by typing
```
stream = BeagleBoneStream(ip"192.168.7.2")
```
Now, we continue by defining the onboard LED on the BB we want to control
```
led = SysLED(1)
```
The argument `1` means that the object `led` will correspond to the first system LED on the BB. So far, this definition is only known to the host computer. To tell the BB that we want to control the LED, we make a call to `init_devices!`
```
init_devices!(stream, led)
```
Now the LED object is defined also on the BB, and we can start controlling it from the host computer. Let's begin by turning it on
```
send(led, true)
```
You should now see the first onboard LED on the BB being lit. The function `send` puts a new command (in this case `true`) to a device (in this case `led`) to the file stream buffer and
immediately sends it to the BB.
We can read the current status of the LED by calling `read`

v = read(led)
```
v = read(led)
```
You should now see a printout saying that the LED is turned on.

We can also stack several commands to the buffer before sending them to the BBB.
We do this with the command `put!`. To turn on 2 LEDS at the same time, we can call

led2 = SysLED(2)
led3 = SysLED(3)
init_devices!(stream, led2, led3)
put!(led2, true)
put!(led3, true)
send(stream)
We can also stack several commands to the message buffer before sending them to the BB.
We do this with the command `put!`. To turn on 2 LEDS at the same time, we do the following call
```
led2 = SysLED(2)
led3 = SysLED(3)
init_devices!(stream, led2, led3)
put!(led2, true)
put!(led3, true)
send(stream)
```
Similarly we can read from several devices at the same time by using `get`

get(led2)
get(led3)
v1, v2 = read(stream)
```
get(led2)
get(led3)
v1, v2 = read(stream)
```
We can also manipulate other types of devices on the BB. Let's try manipulating a couple of physical GPIO's on the BB. Similar to the LEDs, we begin by defining two `GPIO`-objects and initializing them on the BB
```
gpio112 = GPIO(1, true)
gpio66 = GPIO(29,false)
init_devices!(stream, gpio112, gpio66)
```
When creating the `GPIO`-objects, we input two arguments. The first one is an integer value (1-33) which defines which physical GPIO pin we want to access. The integer corresponds to the index of the physical GPIO in the `gpio_channels`-array defined [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/julia1/src/BeagleBone/IO_Object.jl). Additionally, the pin map of the BB can be found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/julia1/docs/build/man/development.md#Package-Development-1). The second argument defines if the GPIO should be of output (`true`) or input (`false`) type.

Now that we have access to two GPIO pins, we can e.g set the output pin's value to high (`true`)
```
send(gpio112, true)
```
The physical GPIO pin on the BB will now output a voltage. The other GPIO pin was defined to be of input type, and if we want to read from it we simply type
```
val = read(gpio66)
```
where `val` will be either 0 or 1 depending on the voltage value read by the pin.

### More Examples
There are several examples found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/examples/examples.md#examples)
which let's you test out the functionality of `LabConnections.jl`.

More examples for testing out the functionality of `LabConnections.jl` are found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/examples/examples.md#examples).

A real-world example using `LabConnections.jl` with the old IO-boxes for controlling the ball and beam process is avaible [here](https://gitlab.control.lth.se/processes/LabProcesses.jl/blob/master/src/interface_implementations/ballandbeam.jl).
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.6
julia 1.0
6 changes: 3 additions & 3 deletions docs/build/examples/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
# Examples


The following examples may be run from the BB, and may require the user to export the the LabConnections module to the LOAD_PATH manually, executing the following line in the Julia prompt
The following examples may be run from the BeagleBone (BB), and may require the user to export the the LabConnections module to the LOAD_PATH manually, executing the following line in the Julia REPL (while SSH:d into the BB)


```
push!(LOAD_PATH, "/home/debian/juliapackages")
```


When running the examples with hardware in the loop, take caution not to short the BB ground with any output pin, as this will damage the board. For instance, if connecting a diode to the output pins, always use a resistor of >1000 Ohm in parallel. See the configuration page for information on which functionality specific pins support.
When running the examples with hardware in the loop, take caution not to short the BBB ground with any output pin, as this will damage the board. For instance, if connecting a diode to the output pins, always use a resistor of >1000 Ohm in parallel.


<a id='Example-with-LEDs-(BB)-1'></a>

## Example with LEDs (BB)


To test the system LED functionality of the Julia code from the BBB, open a Julia prompt and run the SYS_LED_test.jl file
To test the system LED functionality of the Julia code from the BBB, open a Julia prompt and run the SYS*LED*test.jl file


```
Expand Down
19 changes: 9 additions & 10 deletions docs/build/examples/testing.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@

<a id='Tests-1'></a>
<a id='Testing-1'></a>

# Tests
# Testing


The BeagleBone tests can be run on any computer, regrdless of their file-syste. By setting the flag RUNNING_TESTS to true, a dummy file-system is exported in which the tests are run operate. This has the advantage of enabling testing of the code run on the BB free from the BB itself, without building the Debian FS, thereby enabling the automatic testing through Travis.
Scripts for testing the code in `LabConnections.jl` are found under `/test`. The test-sets under `/test/BeagleBone` can be run on any computer (i.e not only on a real BeagleBone (BB)), regardless of their file system. By setting the flag RUNNING_TESTS to true, a dummy file-system is exported in which the tests are run. This has the advantage of enabling testing of the code run on the BB free from the BB itself, without building the Debian file system, thereby enabling the automatic testing through Travis.


To run the tests, simply enter the /test/ directory and run
To run the tests, simply navigate to the `/test` directory and run


```
julia run_tests.jl
julia runtests.jl
```


If the tests are to be run on the BB with hardware in the loop, run
If the tests are to be run on the BB with hardware in the loop, SSH into the BB and run the tests from a local Julia REPL


```
julia run_tests.jl
push!(LOAD_PATH, "/home/debian/juliapackages")
using LabConnections
include("/home/debian/juliapackages/LabConnections/test/runtests.jl")
```


on the BB, to run examples separately, see

Binary file added docs/build/fig/beaglebonetypes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/build/fig/computertypes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading