Skip to content

Commit b96c4bd

Browse files
committed
Merge branch 'master' into steamfitters-updates
2 parents bbd4e2c + 3a9d812 commit b96c4bd

File tree

22 files changed

+358
-163
lines changed

22 files changed

+358
-163
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v1
1212
- name: test
13-
run: make && make examples
13+
run: ./deploy.sh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Module.symvers
5959
Mkfile.old
6060
dkms.conf
6161
out/
62+
build/
6263
### C++ ###
6364
# Prerequisites
6465

CMAKE_README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# How to use CMake
2+
3+
This document gives an overview of the basics of cmake and how to use
4+
it to make libraries and executables for `pod-embedded`.
5+
6+
## Cmake basics
7+
8+
CMake projects are specified using a `CMakeFiles.txt` in each
9+
library/exectutable directory.
10+
11+
### Basic CMakeFiles.txt layout
12+
A top level CMakeFiles.txt always contains a `cmake_minimum_required`
13+
and a `project` declaration. The rest is populated with `add_subdirectory`,
14+
calls, which include CMakeFiles.txts from subdirectories.
15+
16+
### Variables
17+
CMake varaibles are specified using `set(VARIABLE_NAME value...)`, which
18+
sets the variable `VARIABLE_NAME` to any subsequent values (multiple values
19+
will make a list.)
20+
21+
Eg:
22+
23+
```
24+
#set importantDirectory to /usr/local/bin
25+
set(importantDirectory /usr/local/bin)
26+
27+
#set libraries to list containing middleware, drivers, utils
28+
set(libraries middleware
29+
drivers
30+
utils)
31+
```
32+
33+
The fundametnal primitives when defining a cmake project are
34+
executables and libraries.
35+
36+
## Making a library
37+
38+
To create a library that is imported by other executables, we use the following
39+
40+
```
41+
#Define the project for the library
42+
project(foobarlib VERSION 1.0
43+
DESCRIPTION "The foobar library"
44+
LANGUAGES CXX)
45+
46+
#Define the library target called foobar with all of its source directories
47+
#Files specified with respect to CMakeLists.txt for the library
48+
add_library(foobar src/somefile.c
49+
src/bin.c
50+
src/baz.c)
51+
52+
#Add any header files by specifying the include directory, in this case
53+
#called include
54+
target_include_directories(foobar PUBLIC include)
55+
56+
#add any library dependencies
57+
target_link_libraries(foobar PUBLIC someotherlibrary verynicedependency)
58+
target_link_libraries(foobar PRIVATE thisonelibrary)
59+
60+
#export library to cmake file so it can be imported elsewhere
61+
export(TARGETS foobar FILE FoobarConfig.cmake)
62+
```
63+
64+
In this example we define a project called `foobarlib` in its own CMakeLists.txt
65+
and define a library called `foobar` with its respective source files.
66+
Then any header files are added by specifying an include directory with `target_include_directories(...)`. Then we link any other libraries `foobar` depends on with `target_link_libraries(...)`. Finally we export the library using `export(...)` so the library can be imported elsewhere in the project.
67+
68+
### PUBLIC vs PRIVATE vs INTERFACE
69+
Whenever a dependency is specified for a project, you must specify if that dependency
70+
is `PUBLIC`, `PRIVATE` or `INTERFACE`. This changes the availability of the dependencies
71+
you're adding to any project that depends on the library you're writing.
72+
73+
For example, if library `foo` depends on library `bar` publically, then
74+
any library that depends on `foo` will be linked with headers from `bar`.
75+
76+
The rule of thumb is:
77+
78+
* If your source files depend on the library, make it `PRIVATE`.
79+
* If your header files depend on the library, make it `INTERFACE`
80+
* If both of the above are true, make it `PUBLIC`
81+
82+
Dependencies for executables should always be `PRIVATE`.
83+
84+
## Making an executable
85+
86+
To make an executable, simply use
87+
88+
```
89+
add_executable(binaryName, sourceFile1.c
90+
sourceFile2.c
91+
sourceFileN.c)
92+
```
93+
94+
and specify includes and dependencies with `target_include_directories(...)` and `target_link_libraries(...)` in the same way as with libraries.
95+

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
3+
project(PodEmbedded VERSION 1.0
4+
DESCRIPTION "Pod embedded")
5+
6+
#put binaries in out/
7+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib)
8+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib)
9+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out)
10+
11+
#add cmake projects from subdirectories
12+
add_subdirectory(embedded/app)
13+
add_subdirectory(embedded/data)
14+
add_subdirectory(embedded/drivers)
15+
add_subdirectory(embedded/examples)
16+
add_subdirectory(embedded/peripherals)
17+
add_subdirectory(embedded/utils)
18+
add_subdirectory(middleware)

Makefile

Lines changed: 0 additions & 110 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,38 @@
22

33
[![Actions Status](https://github.com/badgerloop-software/pod-embedded/workflows/CI/badge.svg)](https://github.com/badgerloop-software/pod-embedded/actions)
44

5-
*Developers: Rohan Daruwala, Ezra Boley*
5+
*Developers: Rohan Daruwala, Ezra Boley, Nic Hodlofski*
66

77
The embedded repository for Badgerloop's pod in the Hyperloop Competition
88

99
## Beaglebone Make Instructions
1010

11-
There are currently 3 sets of targets:
11+
To build all compile targets:
1212

13-
1) Making the main programs (`badgerloop_LV` and `badgerloop_HV`), placed in the `out/` folder
13+
1) Make a directory called build in the root of the repository and enter it
1414

1515
```
16-
make
16+
mkdir build
17+
cd build
1718
```
1819

19-
The main target can also be executed in a special debug mode, adding useful
20-
print outs from various modules. Any of the following targets can also take
21-
advantage of the added debug functionality. To build in debug mode, run:
20+
2) Run cmake on the parent directory
2221

2322
```
24-
make DEBUG=1
23+
cmake ..
2524
```
2625

27-
2) Making the examples, placed into the `out/tests` folder
26+
3) Build the project with make
2827

2928
```
30-
make examples
29+
make
3130
```
3231

33-
3) Making utilities for showcasing various parts of the pod's functionality
32+
There are currently 3 sets of targets:
3433

35-
```
36-
make utils
37-
```
34+
The main programs (`badgerloop_LV` and `badgerloop_HV`) are placed in the `out/` directory
35+
36+
Tests will be placed in `out/tests`, and utilities in `out/utils`.
3837

3938
### Adding Tests
4039

deploy.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#!/bin/bash
22

3-
sudo modprobe vcan
4-
./embedded/utils/setupCAN.sh
5-
make examples VIRTUAL=1
3+
mkdir build && cd build
4+
cmake ..
65
retVal=$?
76
if [ $retVal -ne 0 ]; then
87
exit 1
98
fi
10-
make VIRTUAL=1
9+
make
1110
retVal=$?
1211
if [ $retVal -ne 0 ]; then
1312
exit 1
1413
fi
15-
python3 ./embedded/examples/sims/rms.py &
16-
./out/tests/can_test
1714
exit 0

embedded/app/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#setup library for the stuff in src/ because it's used elsewhere >_>
2+
project(applib VERSION 1.0
3+
DESCRIPTION "main"
4+
LANGUAGES CXX)
5+
6+
#yeah, it's annoying, but glob has problems with needing to run cmake again,
7+
#and it's SUPER discouraged.
8+
set(dependecies src/bms_fault_checking.c
9+
src/nav.c
10+
src/state_machine.c
11+
src/init.c
12+
src/pressure_fault_checking.c
13+
src/states.c
14+
src/motor.c
15+
src/rms_fault_checking.c
16+
src/transitions.c)
17+
18+
#required libraries for the main pod executables
19+
set(libraries middleware
20+
data
21+
peripherals
22+
drivers
23+
Threads::Threads) #so pthreads work
24+
25+
#configure app library
26+
add_library(app ${dependecies})
27+
target_include_directories(app PUBLIC include)
28+
target_link_libraries(app PRIVATE ${libraries})
29+
30+
#export app library so it can be used externally
31+
export(TARGETS app FILE AppLibConfig.cmake)
32+
33+
#configure HV and LV executables
34+
find_package(Threads REQUIRED)
35+
add_executable(badgerloop_HV main/badgerloop_HV.cpp ${dependecies})
36+
add_executable(badgerloop_LV main/badgerloop_LV.cpp ${dependecies})
37+
38+
target_link_libraries(badgerloop_HV PRIVATE ${libraries})
39+
target_link_libraries(badgerloop_LV PRIVATE ${libraries})
40+
41+
target_include_directories(badgerloop_HV PRIVATE include)
42+
target_include_directories(badgerloop_LV PRIVATE include)

embedded/app/include/states.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Pressure sensor acceptable limits (in PSI) */
1010
#define PS1_BOTTOM_LIMIT_IDLE -50
11-
#define PS1_BOTTOM_LIMIT_PRE 0
11+
#define PS1_BOTTOM_LIMIT_PRE -50
1212
#define PS1_BOTTOM_LIMIT_CRAWLPOST 300
1313
#define PS1_TOP_LIMIT_PRE 1300
1414
#define PS1_TOP_LIMIT_CRAWLPOST 1000
@@ -32,15 +32,15 @@
3232
#define PS3_TOP_LIMIT_CRAWLPOST 150
3333

3434
#define SEC_PS1_BOTTOM_LIMIT_IDLE -50
35-
#define SEC_PS1_BOTTOM_LIMIT_PRE 300
35+
#define SEC_PS1_BOTTOM_LIMIT_PRE -300
3636
#define SEC_PS1_BOTTOM_LIMIT_CRAWLPOST 300
3737
#define SEC_PS1_TOP_LIMIT_PRE 1400
3838
#define SEC_PS1_TOP_LIMIT_CRAWLPOST 1400
3939
#define SEC_PS1_TOP_LIMIT_IDLE 1400
4040

4141

4242
#define SEC_PS2_BOTTOM_LIMIT_IDLE -15
43-
#define SEC_PS2_BOTTOM_LIMIT_PRE 0
43+
#define SEC_PS2_BOTTOM_LIMIT_PRE -10
4444
#define SEC_PS2_BOTTOM_LIMIT_CRAWLPOST 0
4545
#define SEC_PS2_TOP_LIMIT_PRE 150
4646
#define SEC_PS2_TOP_LIMIT_CRAWLPOST 150

0 commit comments

Comments
 (0)