Skip to content

Automatic Keyword Generation #29

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

Merged
merged 8 commits into from
Feb 27, 2020
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/robotlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install deps
run: sudo apt-get install lcov gcc-avr binutils-avr avr-libc
run: ./install-deps.sh
- name: Verify keywords
run: ./verify-keywords
- name: Run build-avr
run: ./build-avr.sh
- name: Run build
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ignore build files
# Ignore build and dev files
build/
keywords/
.vscode/

#ignore coverage files
# Ignore coverage files
out/
*.gch
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ You can view examples using RobotLib in Arduino. Go to File > Examples > RobotLi
## Installation and Documentation

Instructions for how to install as well as documentation are both available on [our Github wiki](https://github.com/Sooner-Competitive-Robotics/RobotLib/wiki).

## Contributing

Please see [tests/README.md](tests/README.md).
4 changes: 2 additions & 2 deletions build-avr.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#make build dir
# Make build dir
rm -r build #for local development
mkdir build
cd build

#make the project
# Make the project
cmake -DCMAKE_CXX_COMPILER='/usr/bin/avr-gcc' ..
make
16 changes: 11 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#make build dir
# Generate keywords from src folder into ../keywords.txt
~/.local/bin/arduino-keywords src --output ..

# Remove operator= from keywords.txt
sed -i '/operator=/d' keywords.txt

# Make build dir
rm -r build #for local development
mkdir build
cd build

#make the project
# Make the project
cmake -DCMAKE_BUILD_TYPE=Coverage ..
make

#create baseline
# Create baseline
lcov -c -i -d src/CMakeFiles/ -o base.info

#testing
# Testing
ctest --output-on-failure .

#merge baseline with testing
# Merge baseline with testing
lcov -c -d tests/CMakeFiles/ -o test.info
lcov -l test.info #debug
lcov -a base.info -a test.info -o total.info #merge base and test info
Expand Down
8 changes: 8 additions & 0 deletions install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Dependencies for building
sudo apt-get update
sudo apt-get install gcc lcov gcc-avr binutils-avr avr-libc -y

# Depdendencies for arduinokeywords
sudo apt-get install python-pip -y
python -m pip install --upgrade pip setuptools wheel
pip install arduinokeywords
60 changes: 41 additions & 19 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
BusInOut KEYWORD1
mode KEYWORD2
read KEYWORD2
write KEYWORD2
Encoder KEYWORD1
HallEffectEncoder KEYWORD1
Motor KEYWORD1
PIDController KEYWORD1
QuadratureEncoder KEYWORD1
RLUtil KEYWORD1
StepperMotor KEYWORD1
TrackingLoop KEYWORD1
pullup KEYWORD2
getTicks KEYWORD2
getValue KEYWORD2
process KEYWORD2
reset KEYWORD2
HallEffectEncoder KEYWORD1
begin KEYWORD2
getTicks KEYWORD2
getValue KEYWORD2
begin KEYWORD2
process KEYWORD2
reset KEYWORD2
setDirection KEYWORD2
reverse KEYWORD2
setDefaultOnZero KEYWORD2
output KEYWORD2
outputBool KEYWORD2
Motor KEYWORD1
begin KEYWORD2
disableOutput KEYWORD2
enableOutput KEYWORD2
getNumPins KEYWORD2
output KEYWORD2
outputBool KEYWORD2
reverse KEYWORD2
setDefaultOnZero KEYWORD2
PIDController KEYWORD1
begin KEYWORD2
getIntegratorValue KEYWORD2
reset KEYWORD2
setBounded KEYWORD2
setIntegratorBounds KEYWORD2
setOutputRange KEYWORD2
setTolerance KEYWORD2
update KEYWORD2
getIntegratorValue KEYWORD2
QuadratureEncoder KEYWORD1
begin KEYWORD2
getTicks KEYWORD2
getValue KEYWORD2
process KEYWORD2
pullup KEYWORD2
reset KEYWORD2
setResolution KEYWORD2
RLUtil KEYWORD1
clamp KEYWORD2
lerp KEYWORD2
slerp KEYWORD2
step KEYWORD2
setRPM KEYWORD2
StepperMotor KEYWORD1
begin KEYWORD2
getCurrentSteps KEYWORD2
reset KEYWORD2
setRPM KEYWORD2
step KEYWORD2
TrackingLoop KEYWORD1
getAccelEstimate KEYWORD2
getPositionEstimate KEYWORD2
getVelocityEstimate KEYWORD2
getAccelEstimate KEYWORD2
setIntegratorBounds KEYWORD2
setTolerance KEYWORD2
reset KEYWORD2
update KEYWORD2
4 changes: 2 additions & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ The build process will automatically find your new file during compilation.

## Running tests locally

First, make sure you have gcc and lcov installed.
First, make sure you have necessary dependencies.

`sudo apt-get install gcc lcov`
`./install-deps.sh`

You can run the unit tests by running `build.sh` while in base directory. This will create a new folder `build` with all the output. Any errors will be shown in stdout along with a brief summary of the coverage. If you would like to view a summary of the coverage in a webpage, you can run `genhtml build/total.info -o out/` and it will create a folder `out` that contains a static website.
29 changes: 29 additions & 0 deletions verify-keywords
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /usr/bin/env python
import os
import sys

# Run arduino-keywords
os.system("mkdir keywords")
os.system("~/.local/bin/arduino-keywords src --output ../keywords > /dev/null 2>&1")
os.system("sed -i '/operator=/d' keywords/keywords.txt > /dev/null 2>&1")

# Get a set of the lines from a file
# Using a set to ignore order (as arduino-keyword search order is system dependent)
def get_keywords(filename):
results = set()
with open(filename, "r") as f:
for line in f:
results.add(line)
return results

# Read both keywords.txt
existing_set = get_keywords("keywords.txt")
new_set = get_keywords("keywords/keywords.txt")

# Are they the same?
if existing_set != new_set:
print("keywords.txt is not correct. Please run build.sh to generate keywords.txt!")
print("Differences:")
for keyword in existing_set.symmetric_difference(new_set):
print(keyword)
sys.exit(1)