Skip to content
Snippets Groups Projects
Commit 31b65c2f authored by Marcus Thelander Andrén's avatar Marcus Thelander Andrén
Browse files

Changes to simple example

parent 5a354624
No related branches found
No related tags found
No related merge requests found
Pipeline #716 failed
...@@ -24,6 +24,7 @@ to be used locally on the BB. ...@@ -24,6 +24,7 @@ to be used locally on the BB.
<p align="center"> <p align="center">
<img src="docs/src/fig/computertypes.png" height="320" width="900"> <img src="docs/src/fig/computertypes.png" height="320" width="900">
</p> </p>
The module `LabConnections.Computer` contains the user interface on the host computer side, and defines 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 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 host computer and different IO-devices (BB or Comedi). There are currently 3
...@@ -67,45 +68,57 @@ First, you should follow the instructions on how to install the required softwar ...@@ -67,45 +68,57 @@ First, you should follow the instructions on how to install the required softwar
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`. 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. 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 the Julia REPL and input Then, start a Julia REPL on the host computer and type
```
using LabConnections.Computer 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 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") stream = BeagleBoneStream(ip"192.168.7.2")
Now, we continue by defining the LED we want to control ```
Now, we continue by defining the onboard LED on the BB we want to control
```
led = SysLED(1) led = SysLED(1)
```
The object `led` will now correspond to the first system LED on the BBB. 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!`
To tell the BBB that we want to control the LED, we make a call to `init_devices!` ```
init_devices!(stream, led) init_devices!(stream, led)
Now we can start controlling the LED on the BBB. Let's begin by turning it on ```
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) 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 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
sends it immediately to the BBB. immediately sends it to the BB.
We can read the current status of the LED by calling `read` 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. 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 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 can call We do this with the command `put!`. To turn on 2 LEDS at the same time, we do the following call
```
led2 = SysLED(2) led2 = SysLED(2)
led3 = SysLED(3) led3 = SysLED(3)
init_devices!(stream, led2, led3) init_devices!(stream, led2, led3)
put!(led2, true) put!(led2, true)
put!(led3, true) put!(led3, true)
send(stream) send(stream)
```
Similarly we can read from several devices at the same time by using `get` Similarly we can read from several devices at the same time by using `get`
```
get(led2) get(led2)
get(led3) get(led3)
v1, v2 = read(stream) 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
```
gpio112 = GPIO(1, true)
gpio66 = GPIO(29,false)
```
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).
### More Examples ### More Examples
There are several examples found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/examples/examples.md#examples) There are several examples found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/examples/examples.md#examples)
......
...@@ -25,5 +25,9 @@ This will transfer the current development version of `LabConnections.jl` found ...@@ -25,5 +25,9 @@ This will transfer the current development version of `LabConnections.jl` found
### Development with hardware in the loop ### Development with hardware in the loop
When testing `LabConnections.jl` with hardware in the loop, the external hardware will be connected to the pin headers on the BB. For reference, the pin map of the BeagleBone (BB) is shown below. When testing `LabConnections.jl` with hardware in the loop, the external hardware will be connected to the pin headers on the BB. For reference, the pin map of the BeagleBone (BB) is shown below.
<img src="../fig/beaglebone_black_pinmap.png" height="400" width="700">
<p align="center">
<img src="../fig/beaglebone_black_pinmap.png" height="500" width="900">
</p>
When running examples and tests 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 >1 kOhm in parallel. When running examples and tests 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 >1 kOhm in parallel.
...@@ -28,7 +28,7 @@ Start by downloading the Debian image [here](http://beagleboard.org/latest-image ...@@ -28,7 +28,7 @@ Start by downloading the Debian image [here](http://beagleboard.org/latest-image
Proceed by downloading the Julia v1.0 binary for 32-bit ARMv7 found [here](https://julialang.org/downloads/). Put the .tar-file of the Julia binary on the micro-SD card containing the Debian image under `/home/debian`, and unzip it. Proceed by downloading the Julia v1.0 binary for 32-bit ARMv7 found [here](https://julialang.org/downloads/). Put the .tar-file of the Julia binary on the micro-SD card containing the Debian image under `/home/debian`, and unzip it.
Make sure that the Julia folder has the correct name by typing Make sure that the Julia folder has the correct name by typing
``` ```
mv /home/debian/julia-<distro specific tag>/bin/julia /home/debian/julia/bin/julia mv /home/debian/julia-<distro specific tag> /home/debian/julia
``` ```
The file structure on the micro-SD now has the correct structure. The file structure on the micro-SD now has the correct structure.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment