Skip to content

Commit

Permalink
Merge pull request #2 from bastinjul/develop
Browse files Browse the repository at this point in the history
First GRiSP application using temperature
  • Loading branch information
Laymer authored Oct 28, 2019
2 parents be0cb0e + 5a738c2 commit 511511d
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 19 deletions.
48 changes: 39 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,50 @@ Build

Building VM from source
-----------------------

$ rebar3 grisp build --clean true --configure true
$ rebar3 compile

```bash
$ rebar3 grisp build --clean true --configure true
$ rebar3 compile
```

Local dependencies
-----

In the root directory of the project :

$ mkdir _checkouts && cd _checkouts
$ git clone https://github.com/grisp/rebar3_grisp
$ git clone https://github.com/grisp/grisp_tools
In the root directory of the project :

```bash
$ mkdir _checkouts && cd _checkouts
$ git clone https://github.com/grisp/rebar3_grisp
$ git clone https://github.com/grisp/grisp_tools
```
Deploy
------

$ rebar3 grisp deploy -n=name -v=vsn
`$ rebar3 grisp deploy -n=<name> -v=<vsn>`

Connecting over Wifi to the GRiSP board
---------------------------------------

You need to modify some files in [grisp/grisp_base/files](https://github.com/achlysproject/workshop/tree/master/grisp/grisp_base/files) :

- erl_inetrc :
- in the line 4 `{host, {X,X,X,X}, ["<host>"]}.`, replace `{X,X,X,X}` by your local ip address, for example `{192,168,1,57}`, and `<host>` by the hostname of you computer (you can see it with the command `$ hostname -s`)
- grisp.ini.mustache :
- in line 5 replace `MyCookie` by your own cookie
- in line 10 replace `my_grisp_board` by your own grisp board name
- wpa_supplicant.conf :
- replace `<wifi_name>` by your wifi name (this name is case sensitive)
- replace `<pwd>` by your wifi password

You also need to add to the `/etc/hosts/` file:
```
X.X.X.X my_grisp_board
```
where `X.X.X.X` is the local ip of your grisp_board and `my_grisp_board` the name you give to it.

Then to connect to a board you need to enter this command in a command prompt:

``` bash
$ erl -sname my_remote_shell -remsh project@my_grisp_board -setcookie MyCookie
```
by replacing *project*, *my_grisp_board* and *MyCookie* with you own values.
13 changes: 13 additions & 0 deletions grisp/grisp_base/files/erl_inetrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%--- Erlang Inet Configuration -------------------------------------------------

% Add hosts
{host, {X,X,X,X}, ["<host>"]}.

% Do not monitor the hosts file
{hosts_file, ""}.

% Disable caching
{cache_size, 0}.

% Specify lookup method
{lookup, [file, native]}.
11 changes: 11 additions & 0 deletions grisp/grisp_base/files/grisp.ini.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[boot]
image_path = /media/mmcsd-0-0/{{release_name}}/erts-{{erts_vsn}}/bin/beam.bin

[erlang]
args = erl.rtems -- -home . -pa . -root {{release_name}} -boot {{release_name}}/releases/{{release_version}}/{{release_name}} -internal_epmd epmd_sup -kernel inetrc "./erl_inetrc" -sname {{release_name}} -setcookie MyCookie

[network]
ip_self = dhcp
wlan = enable
hostname = my_grisp_board
wpa = wpa_supplicant.conf
5 changes: 5 additions & 0 deletions grisp/grisp_base/files/wpa_supplicant.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
network={
ssid="<wifi_name>"
key_mgmt=WPA-PSK
psk="<pwd>"
}
19 changes: 11 additions & 8 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{deps, [grisp]}.
{deps, [
grisp,
{epmd, {git, "https://github.com/erlang/epmd", {ref, "4d1a59"}}}
]}.

{erl_opts, [debug_info]}.

Expand All @@ -11,20 +14,20 @@
% ==========
% Mac OS X :
% ==========
{pre_script, "rm -rf /Volumes/GRISP/*"},
{destination, "/Volumes/GRISP"},
{post_script, "diskutil unmount /Volumes/GRISP"}
% {pre_script, "rm -rf /Volumes/GRISP/*"},
% {destination, "/Volumes/GRISP"},
% {post_script, "diskutil unmount /Volumes/GRISP"}
% ==========
% Linux :
% ==========
% {pre_script , "rm -rf /media/user/GRISP/*"} ,
% {destination , "/media/user/GRISP"} ,
% {post_script , "umount /media/user/GRISP"}
{pre_script , "rm -rf /media/julien/GRISP/*"} ,
{destination , "/media/julien/GRISP"} ,
{post_script , "umount /media/julien/GRISP"}
]}
]}.

{shell, [{apps, []}]}.

{relx, [
{release, {workshop, "0.1.0"}, [workshop]}
{release, {workshop, "0.1.0"}, [{epmd, none}, workshop]}
]}.
6 changes: 5 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{"1.1.0",
[{<<"grisp">>,{pkg,<<"grisp">>,<<"1.1.6">>},0},
[{<<"epmd">>,
{git,"https://github.com/erlang/epmd",
{ref,"4d1a595b9d5c32fc0e55f462da381de62de23bf0"}},
0},
{<<"grisp">>,{pkg,<<"grisp">>,<<"1.1.6">>},0},
{<<"mapz">>,{pkg,<<"mapz">>,<<"0.3.0">>},1}]}.
[
{pkg_hash,[
Expand Down
90 changes: 89 additions & 1 deletion src/workshop.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,96 @@
-export([start/2]).
-export([stop/1]).

% New functions
-export([temperature_range/2]).
-export([light_percentage/0]).
-export([directionX/0, directionY/0, directionZ/0]).
-export([rotationX/0, rotationY/0, rotationZ/0]).

%--- Callbacks -----------------------------------------------------------------

start(_Type, _Args) -> workshop_sup:start_link().
start(_Type, _Args) ->
{ok, Supervisor} = workshop_sup:start_link(),
initiate_sensors(),
spawn(workshop, rotationZ, []),
{ok, Supervisor}.

stop(_State) -> ok.

initiate_sensors() ->
grisp:add_device(spi1, pmod_nav),
grisp:add_device(spi2, pmod_als).

temperature_range(Min, Max) ->
[Temp] = pmod_nav:read(alt, [out_temp]),
if
Temp > Max -> [grisp_led:color(L, red) || L <- [1,2]];
Temp < Min -> [grisp_led:color(L, blue) || L <- [1,2]];
true -> [grisp_led:color(L, green) || L <-[1,2]]
end,
timer:sleep(2500),
[grisp_led:color(L, yellow) || L <- [1,2]],
timer:sleep(2500),
temperature_range(Min, Max).

light_percentage() ->
Percentage = pmod_als:percentage(),
if
Percentage < 20 -> [grisp_led:color(L, blue) || L <- [1,2]];
Percentage < 40 -> [grisp_led:color(L, magenta) || L <- [1,2]];
Percentage < 60 -> [grisp_led:color(L, aqua) || L <- [1,2]];
Percentage < 80 -> [grisp_led:color(L, yellow) || L <- [1,2]];
true -> [grisp_led:color(L, white) || L <- [1,2]]
end,
timer:sleep(2500),
[grisp_led:color(L, red) || L <- [1,2]],
timer:sleep(2500),
light_percentage().

directionX() ->
[X, _Y, _Z] = pmod_nav:read(acc, [out_x_xl, out_y_xl, out_z_xl]),
if
X > 0 -> grisp_led:color(1, red);
X < 0 -> grisp_led:color(1, blue)
end,
directionX().

directionY() ->
[_X, Y, _Z] = pmod_nav:read(acc, [out_x_xl, out_y_xl, out_z_xl]),
if
Y > 0 -> grisp_led:color(2, red);
Y < 0 -> grisp_led:color(2, blue)
end,
directionY().

directionZ() ->
[_X, _Y, Z] = pmod_nav:read(acc, [out_x_xl, out_y_xl, out_z_xl]),
if
Z > 0 -> [grisp_led:color(L, red) || L <- [1,2]];
Z < 0 -> [grisp_led:color(L, blue) || L <- [1,2]]
end,
directionZ().

rotationX() ->
[X, _, _] = pmod_nav:read(acc, [out_x_g, out_y_g, out_z_g]),
if
X > 0 -> grisp_led:color(1, red);
X < 0 -> grisp_led:color(1, blue)
end,
rotationX().

rotationY() ->
[_, Y, _] = pmod_nav:read(acc, [out_x_g, out_y_g, out_z_g]),
if
Y > 0 -> grisp_led:color(2, red);
Y < 0 -> grisp_led:color(2, blue)
end,
rotationY().

rotationZ() ->
[_, _, Z] = pmod_nav:read(acc, [out_x_g, out_y_g, out_z_g]),
if
Z > 0 -> [grisp_led:color(L, red) || L <- [1,2]];
Z < 0 -> [grisp_led:color(L, blue) || L <- [1,2]]
end,
rotationZ().

0 comments on commit 511511d

Please sign in to comment.