Skip to content

Commit 9d0e4f7

Browse files
committed
added examples, fixed readme
1 parent 56be7be commit 9d0e4f7

File tree

17 files changed

+927
-1
lines changed

17 files changed

+927
-1
lines changed

README.md

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,116 @@
11
# embryo
2-
State machine for EIT Manufacturing's EMBRYO educational metal press machine.
2+
3+
## Description
4+
5+
Step by step construction of a state machine for EIT Manufacturing's EMBRYO educational metal press machine.
6+
7+
## Installation
8+
9+
### First Method
10+
11+
1. Navigate to the Releases page.
12+
2. Download the latest release.
13+
3. Extract the zip file in your Arduino's Sketchbook
14+
4. In the Arduino IDE, navigate to File > Sketchbook > EMBRYO-X.Y.Z
15+
16+
## Features
17+
18+
- ### Official dependencies
19+
20+
Code examples depend on the official EduIntro library.
21+
22+
- ### Easy to use
23+
24+
It is simple, basic and very easy to understand. Just import the code collection in your Sketchbook and try out the different examples.
25+
26+
- ### Complete package for the EMBRYO machine
27+
28+
Learn how to use the machine from scratch and step by step build a reliable state machine that will give you access to all of its capabilities.
29+
30+
- ### Intuitive syntax
31+
32+
The code has a simple and intuitive syntax to handle variables and functions.
33+
34+
- ### Give back
35+
36+
EMBRYO is free for everyone. Everyone can download and use it in their projects, assignments or anywhere for free.
37+
38+
## Components and functions
39+
40+
This is an example of how code can be built iteratively around a certain machine but slowly adding improvements to the core software. Here a list of components of the code
41+
42+
- ### Architecture
43+
Includes information about the system itself, the pinouts to the connected sensors and actuators, and constructs to navigate through them
44+
45+
- ### Comm Functions
46+
Functions dedicated to send and receive informaiton via Serial port
47+
48+
- ### Data Functions
49+
Handling of the information from sensors, arranging into easy to compare arrays, etc
50+
51+
- ### States
52+
Definitions of names of states to make the code easier to read
53+
54+
## General code structure
55+
56+
There are many examples implemented in this repository. Below are shown some of the examples.
57+
58+
- ### 03 Machine Status Serial Control
59+
In this example, the machine offers a bi-directional communication port to the computer for you to send commands to it and collect information in real time. The main loop responds to the structure:
60+
61+
``` C++
62+
void loop() {
63+
// Check the inputs
64+
readInputs();
65+
66+
// Serial terminal
67+
serialCheck();
68+
69+
// Print out the inputs if there is an event
70+
if (inputEvent()) {
71+
printInputs();
72+
}
73+
74+
// Copy arrays of inputs to check state changes
75+
copyInputs();
76+
}
77+
```
78+
79+
## Versions
80+
81+
### v0.0.1 (Current Stable version)
82+
83+
#### April, 2021
84+
85+
* Initial release of examples
86+
87+
## Contributing
88+
89+
If you want to contribute to this project:
90+
91+
- Report bugs and errors
92+
- Ask for enhancements
93+
- Create issues and pull requests
94+
- Tell others about this code
95+
- Contribute new protocols
96+
97+
Please read [CONTRIBUTING.md](https://github.com/AghaSaad04/EduIntro/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
98+
99+
## Credits
100+
101+
Created and maintained by D. Cuartielles, Malmo, 2021
102+
103+
Based on previous work by:
104+
105+
- F. Troya, Malmo, 2020
106+
- [Arduino community](https://www.arduino.cc)
107+
108+
## Current stable version
109+
110+
**number:** v0.0.1
111+
112+
**codename:** Jokkmokk
113+
114+
## License
115+
116+
This library is licensed under [GPLv3](https://www.gnu.org/licenses/quick-guide-gplv3.html).
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
EMBRYO Control system v2.0
3+
4+
Machine control using an event driven approach and designing
5+
a state machine around the different inputs and outputs
6+
7+
Test 00: Machine Status
8+
9+
This example checks the different inputs and outputs, as
10+
well as it establishes the different mechanisms for reading
11+
all inputs and actiating all outputs
12+
13+
This code is in the public domain
14+
15+
2021 D. Cuartielles
16+
17+
*/
18+
19+
// Include the machine's architecture
20+
#include "architecture.h"
21+
22+
// Include the sensor / actuator handling library
23+
#include <EduIntro.h>
24+
25+
// Shall we debug the code?
26+
const int DEBUG = true;
27+
28+
// Array to store input values
29+
int inputValuesOld[NUM_PINS_DIGITAL + NUM_PINS_ANALOG];
30+
int inputValues[NUM_PINS_DIGITAL + NUM_PINS_ANALOG];
31+
32+
// Array to store the output values
33+
int outputValues[NUM_PINS_OUTPUT];
34+
35+
void setup() {
36+
// Initialise serial communication
37+
Serial.begin(115200);
38+
39+
// Do not start until computer is connected
40+
while (!Serial) {};
41+
42+
// Status prints
43+
if (DEBUG) {
44+
Serial.print("Size of digital input array: ");
45+
Serial.println(NUM_PINS_DIGITAL);
46+
Serial.print("Size of analog input array: ");
47+
Serial.println(NUM_PINS_ANALOG);
48+
Serial.print("Size of output array: ");
49+
Serial.println(NUM_PINS_OUTPUT);
50+
}
51+
52+
// Declare inputs and outputs as such
53+
for (int i = 0; i < NUM_PINS_DIGITAL; i++)
54+
pinMode(INPUTS_DIGITAL[i], INPUT);
55+
for (int i = 0; i < NUM_PINS_OUTPUT; i++)
56+
pinMode(OUTPUTS[i], OUTPUT);
57+
}
58+
59+
void loop() {
60+
// Check the inputs
61+
readInputs();
62+
63+
// Printout the inputs if there is an event
64+
if (inputEvent()) {
65+
printInputs();
66+
}
67+
68+
// Copy arrays of inputs to check state changes
69+
copyInputs();
70+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Machine architecture
2+
// * Inputs
3+
const int PIN_BUTTON_LEFT = 6;
4+
const int PIN_BUTTON_RIGHT = 5;
5+
const int PIN_BUTTON_UP = 7;
6+
const int PIN_BUTTON_DOWN = 2;
7+
8+
const int PIN_END_STOP = A2;
9+
const int PIN_END_STOP_MOTOR = 3;
10+
11+
const int PIN_BUTTON_INIT = 4;
12+
const int PIN_BUTTON_EMERGENCY = 9;
13+
const int PIN_POT = A0;
14+
15+
// * Outputs
16+
const int PIN_BUZZER = A1;
17+
18+
const int PIN_LED = A3;
19+
const int PIN_LED_EMERGENCY = 8;
20+
const int PIN_MOTOR_DIR = 11;
21+
const int PIN_MOTOR_STEP = 10;
22+
23+
const int INPUTS_DIGITAL[] = {
24+
PIN_BUTTON_LEFT,
25+
PIN_BUTTON_RIGHT,
26+
PIN_BUTTON_UP,
27+
PIN_BUTTON_DOWN,
28+
PIN_END_STOP,
29+
PIN_END_STOP_MOTOR,
30+
PIN_BUTTON_INIT,
31+
PIN_BUTTON_EMERGENCY
32+
};
33+
34+
const int INPUTS_ANALOG[] = {
35+
PIN_POT
36+
};
37+
38+
const int OUTPUTS[] = {
39+
PIN_BUZZER,
40+
PIN_LED,
41+
PIN_LED_EMERGENCY,
42+
PIN_MOTOR_DIR,
43+
PIN_MOTOR_STEP
44+
};
45+
46+
const int NUM_PINS_DIGITAL = sizeof(INPUTS_DIGITAL) / sizeof(INPUTS_DIGITAL[0]);
47+
const int NUM_PINS_ANALOG = sizeof(INPUTS_ANALOG) / sizeof(INPUTS_ANALOG[0]);
48+
const int NUM_PINS_OUTPUT = sizeof(OUTPUTS) / sizeof(OUTPUTS[0]);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
void copyInputs() {
2+
// Copy all values one by one
3+
for (int i = 0; i < NUM_PINS_DIGITAL + NUM_PINS_ANALOG; i++)
4+
inputValuesOld[i] = inputValues[i];
5+
}
6+
7+
void printInputs() {
8+
// Print out all values separated by blank spaces
9+
for (int i = 0; i < NUM_PINS_DIGITAL + NUM_PINS_ANALOG; i++) {
10+
Serial.print(inputValues[i]);
11+
Serial.print(" ");
12+
}
13+
14+
Serial.println();
15+
}
16+
17+
boolean inputEvent() {
18+
boolean result = false;
19+
20+
// Check all values one by one
21+
for (int i = 0; i < NUM_PINS_DIGITAL + NUM_PINS_ANALOG; i++)
22+
if (inputValues[i] != inputValuesOld[i])
23+
result = true;
24+
25+
return result;
26+
}
27+
28+
void readInputs() {
29+
// Read digital inputs
30+
for (int i = 0; i < NUM_PINS_DIGITAL; i++)
31+
inputValues[i] = digitalRead(INPUTS_DIGITAL[i]);
32+
33+
// Read analog inputs
34+
for (int i = 0; i < NUM_PINS_ANALOG; i++)
35+
inputValues[NUM_PINS_DIGITAL + i] = analogRead(INPUTS_ANALOG[i]);
36+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
EMBRYO Control system v2.0
3+
4+
Machine control using an event driven approach and designing
5+
a state machine around the different inputs and outputs
6+
7+
Test 01: Machine Status Button States
8+
9+
This example checks the different inputs and outputs, as
10+
well as it establishes the different mechanisms for reading
11+
all inputs and actiating all outputs. In this case we check
12+
for buttons to be PRESSED, RELEASED, and HELD
13+
14+
The main difference between this example and the previous
15+
one is the use of the EduIntro library to detect button
16+
states and encode them. Note that the library considers
17+
all buttons to be pulled up, which is not the case, thus
18+
the code (check it out and see)
19+
20+
This code is in the public domain
21+
22+
2021 D. Cuartielles
23+
24+
*/
25+
26+
// Include the machine's architecture
27+
#include "architecture.h"
28+
#include "states.h"
29+
30+
// Include the sensor / actuator handling library
31+
#include <EduIntro.h>
32+
33+
// Shall we debug the code?
34+
const int DEBUG = true;
35+
36+
// Array to store input values
37+
int inputValuesOld[NUM_PINS_DIGITAL + NUM_PINS_ANALOG];
38+
int inputValues[NUM_PINS_DIGITAL + NUM_PINS_ANALOG];
39+
40+
// Array to store the output values
41+
int outputValues[NUM_PINS_OUTPUT];
42+
43+
// Array for all of the buttons
44+
// unfortunately this cannot be declared automatically
45+
// like with
46+
// for (int i = 0; i < NUM_PINS_DIGITAL; i++)
47+
// inputButtons[i] = new Button(INPUTS_DIGITAL[i]);
48+
// and theefore cannot be automated :-(
49+
Button inputButtons[] {
50+
Button(INPUTS_DIGITAL[0], PULL_DOWN),
51+
Button(INPUTS_DIGITAL[1], PULL_DOWN),
52+
Button(INPUTS_DIGITAL[2], PULL_DOWN),
53+
Button(INPUTS_DIGITAL[3], PULL_DOWN),
54+
Button(INPUTS_DIGITAL[4], PULL_DOWN),
55+
Button(INPUTS_DIGITAL[5], PULL_DOWN),
56+
Button(INPUTS_DIGITAL[6], PULL_DOWN),
57+
Button(INPUTS_DIGITAL[7], PULL_UP),
58+
};
59+
60+
void setup() {
61+
// Initialise serial communication
62+
Serial.begin(115200);
63+
64+
// Do not start until computer is connected
65+
while (!Serial) {};
66+
67+
// Status prints
68+
if (DEBUG) {
69+
Serial.print("Size of digital input array: ");
70+
Serial.println(NUM_PINS_DIGITAL);
71+
Serial.print("Size of analog input array: ");
72+
Serial.println(NUM_PINS_ANALOG);
73+
Serial.print("Size of output array: ");
74+
Serial.println(NUM_PINS_OUTPUT);
75+
}
76+
77+
// Declare outputs as such
78+
for (int i = 0; i < NUM_PINS_OUTPUT; i++)
79+
pinMode(OUTPUTS[i], OUTPUT);
80+
}
81+
82+
void loop() {
83+
// Check the inputs
84+
readInputs();
85+
86+
// Printout the inputs if there is an event
87+
if (inputEvent()) {
88+
printInputs();
89+
}
90+
91+
// Copy arrays of inputs to check state changes
92+
copyInputs();
93+
}

0 commit comments

Comments
 (0)