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

Run-time hardware tests and other changes #38

Merged
merged 17 commits into from
Aug 24, 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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "libraries/PacketSerial"]
path = libraries/PacketSerial
url = https://github.com/bakercp/PacketSerial.git
[submodule "libraries/SerialCommand"]
path = libraries/SerialCommand
url = https://github.com/kroimon/Arduino-SerialCommand.git
[submodule "libraries/SoftI2CMaster"]
path = libraries/SoftI2CMaster
url = https://github.com/todbot/SoftI2CMaster.git
Expand Down
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
matrix:
include:
- language: cpp
dist: bionic
dist: focal
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
- MATRIX_EVAL="CC=gcc-9 && CXX=g++-9"
before_install:
- eval "${MATRIX_EVAL}"
- pip install gcovr
- gcovr --version
script:
- "./test/test.sh"
- language: c
dist: bionic
dist: focal
addons:
apt:
packages:
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## 1.0.0 / Unreleased

* Migrate to AYAB API v6
* Remove dependency on SerialCommand library
* Add informative error codes
* Allow carriage to start on the right-hand side moving left
* Add run-time hardware tests
* Migrate to generic firmware from machine-specific versions
* Change libraries to submodules
* Add unit tests that can run in the absence of the hardware
* Add GPLv3 license for the repository, and LGPLv2.1 for the SerialCommand library
* Add GPLv3 license
* Add development environment documentation to README
* Add firmware update instructions to README
* Add CHANGELOG.md
Expand Down
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,45 @@ In [ayab-desktop](https://github.com/AllYarnsAreBeautiful/ayab-desktop): go to T

To set up a working development environment follow these steps:

0. Clone the repository and update all submodules
0. Clone the repository and update all submodules.

`git clone --recurse-submodules https://github.com/AllYarnsAreBeautiful/ayab-firmware.git ayab`
Ubuntu:
```bash
sudo apt install -y git
git clone --recurse-submodules https://github.com/AllYarnsAreBeautiful/ayab-firmware.git ayab
```

1. Install the [Arduino.mk](https://github.com/sudar/Arduino-Makefile) package and setup environment variables
1. Install the [Arduino.mk](https://github.com/sudar/Arduino-Makefile) package and setup environment variables.

Ubuntu:
```bash
sudo apt install arduino-mk
sudo apt install -y arduino-mk cmake
export ARDMK_DIR=/usr/share/arduino
```
Running ./build.sh should work now.
Running `./build.sh` should work now.

2. Install clang-format and gcovr

2. Install `clang-format`, `gcovr`, and update `gcc` to version 9.

Ubuntu:
```bash
sudo apt install clang-format gcovr
sudo apt install -y clang-format gcovr \
gcc-9 g++-9 cpp-9 gcc-9-base gcc-10-base \
libgcc-9-dev libstdc++-9-dev
```

3. Install [pre-commit](https://pre-commit.com/) via pip and use it to install git hooks

```bash
3. Install [pre-commit](https://pre-commit.com/) via pip and use it to install git hooks.
```
pip3 install --user pre-commit
pre-commit install
```

4. Optionally create a pre-push hook
4. Optionally create a pre-push hook.

Add the following snippet in a file called .git/hooks/pre-push
```bash
Add the following snippet in a file called `.git/hooks/pre-push`:
```
#!/bin/bash
set -e

./build.sh
./test/test.sh -c
```

40 changes: 18 additions & 22 deletions doc/finite_state_machine.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# Finite State Machine
### Finite State Machine

The knitting machine finite state machine is defined in the Knitter class.
The finite state machine is defined in the `Fsm` class.

A graphical representation follows.
|State||
--:|:--
`Init` | Wait for carriage to be put in the correct location.
`Ready` | Wait to start operation.
`Knit` | Knitting mode.
`Test` | Hardware testing mode.
|||

\startuml
skinparam shadowing false
skinparam ArrowColor DimGray
skinparam state {
backgroundColor LightSteelBlue
BorderColor Gray
}
hide empty description
A tabular representation of state transitions follows.

Init : Wait for carriage to be put in the correct location.
Ready: Wait to start operation.
Operate: Knit.
Test: Calculate but don't exercise solenoids.
|Transition||
--:|:--
`Init -> Test` |`Tester::startTest()`
`Ready -> Test` |`Tester::startTest()`
`Test -> Init` | `Tester::quitCmd()`
`Init -> Ready` | `Knitter::isReady()`
`Ready -> Knit` | `Knitter::startKnitting()`
`Knit -> Ready` | `m_workedOnLine && m_lastLineFlag`

Reset --> Init
Init --> Test : startTest()
Ready --> Test : startTest()
Init -> Ready : Direction == Right\n&& HallActive == Left
Ready -> Operate : startOperation()
Operate -> Ready : lastLine()\n&& finished
\enduml
1 change: 0 additions & 1 deletion libraries/SerialCommand
Submodule SerialCommand deleted from 76ebd2
2 changes: 1 addition & 1 deletion src/ayab/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
PROJECT_DIR = $(shell dirname $(shell pwd))/..
$(info $(PROJECT_DIR))

ARDUINO_LIBS = Wire Adafruit_MCP23008 SoftI2CMaster PacketSerial SerialCommand
ARDUINO_LIBS = Wire Adafruit_MCP23008 SoftI2CMaster PacketSerial
USER_LIB_PATH = $(realpath $(PROJECT_DIR)/libraries)

TARGET = ayab
Expand Down
2 changes: 2 additions & 0 deletions src/ayab/beeper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*!
* \file beeper.cpp
* \brief Class containing methods to actuate a beeper connected
* to PIEZO_PIN.
*
* This file is part of AYAB.
*
Expand Down
41 changes: 34 additions & 7 deletions src/ayab/beeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,46 @@ constexpr uint8_t BEEP_ON_DUTY = 0U;
constexpr uint8_t BEEP_OFF_DUTY = 20U;
constexpr uint8_t BEEP_NO_DUTY = 255U;

/*!
* Class to actuate a beeper connected to PIEZO_PIN
*/
class Beeper {
class BeeperInterface {
public:
virtual ~BeeperInterface(){};

// any methods that need to be mocked should go here
virtual void ready() = 0;
virtual void finishedLine() = 0;
virtual void endWork() = 0;
};

// Container class for the static methods that control the beeper.
// Dependency injection is enabled using a pointer to a global instance of
// either `Beeper` or `BeeperMock`, both of which classes implement the
// pure virtual methods of `BeeperInterface`.

class GlobalBeeper final {
private:
// singleton class so private constructor is appropriate
GlobalBeeper() = default;

public:
Beeper() = default;
// pointer to global instance whose methods are implemented
static BeeperInterface *m_instance;

static void ready();
static void finishedLine();
static void endWork();
};

/*!
* \brief Class to actuate a beeper connected to PIEZO_PIN
*/
class Beeper : public BeeperInterface {
public:
void ready();
void finishedLine();
void endWork();

private:
static void beep(uint8_t length);
void beep(uint8_t length);
};

#endif // BEEPER_H_
#endif // BEEPER_H_
4 changes: 2 additions & 2 deletions src/ayab/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ constexpr uint8_t I2Caddr_sol1_8 = 0x0U; ///< I2C Address of solenoids 1 - 8
constexpr uint8_t I2Caddr_sol9_16 = 0x1U; ///< I2C Address of solenoids 9 - 16

// TODO(Who?): Optimize Delay for various Arduino Models
constexpr uint16_t START_OPERATION_DELAY = 2000U;
constexpr uint16_t START_KNITTING_DELAY = 2000U;

// Determine board type
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
Expand All @@ -63,4 +63,4 @@ constexpr uint16_t START_OPERATION_DELAY = 2000U;
#error "untested board - please check your I2C ports"
#endif

#endif // BOARD_H_
#endif // BOARD_H_
Loading