Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Wave | ||
**Boards:** Master and at least 2 valve boards | ||
**Tube connections:** Connect all supply ports to the air supply. Connect each output port to an inflatable. | ||
|
||
![](../images/Wave.jpg) | ||
|
||
In this example, we demonstrate an advanced valve timing sequence. We want each valve to turn on shortly after its neighbor has turned on, thus propagating a "wave" motion down the row of inflatables. The code for this example is extendable to arbitrary numbers of valve boards. | ||
|
||
We first designate the length of an entire wave cycle. Every time a new cycle begins, we compute the on and off times for each individual valve, which depends on the valve's position, the time offset between valves, and the duration we want each valve to stay on. This information is stored and used on subsequent `loop()` iterations to open and close valves when appropriate. When the end of the wave cycle occurs, the whole process repeats. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <PneuDuino.h> | ||
|
||
PneuDuino p; | ||
|
||
// number of valve boards | ||
#define N 2 | ||
|
||
|
||
// length of the wave cycle | ||
unsigned long cycle_length = 1000L; | ||
// time that the most recent cycle began | ||
unsigned long cycle_start_time; | ||
|
||
// times to turn on/off each valve | ||
unsigned long on_times[2*N]; | ||
unsigned long off_times[2*N]; | ||
|
||
// duration to keep each valve on | ||
unsigned long on_duration = 100L; | ||
|
||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
p.begin(); | ||
p.setAddressMode(PNEUDUINO_ADDRESS_VIRTUAL); | ||
} | ||
|
||
|
||
void loop() { | ||
p.update(); | ||
|
||
// get the current time | ||
unsigned long m = millis(); | ||
|
||
// cycle is over, reset everything for the next cycle | ||
if(m > cycle_start_time + cycle_length) { | ||
// loop through all 2*N valves | ||
for(int n=0; n<2*N; n++) { | ||
on_times[n] = m + (n*cycle_length / (2*N)); | ||
off_times[n] = on_times[n] + on_duration; | ||
} | ||
|
||
// loop through all N valve boards | ||
// turn off all valves (indexed from 1, not 0) | ||
for(int n=0; n<N; n++) { | ||
p.out(n+1, LEFT); | ||
p.out(n+1, RIGHT); | ||
} | ||
|
||
// reset cycle start time | ||
cycle_start_time = m; | ||
} | ||
|
||
// loop through all N valve boards | ||
for(int n=0; n<N; n++) { | ||
// if turn on time is reached, open the valve | ||
if(m > on_times[2*n]) | ||
p.in(n+1, LEFT); | ||
if(m > on_times[2*n + 1]) | ||
p.in(n+1, RIGHT); | ||
|
||
// if turn off time is reached, close the valve | ||
if(m > off_times[2*n]) | ||
p.out(n+1, LEFT); | ||
if(m > off_times[2*n + 1]) | ||
p.out(n+1, RIGHT); | ||
} | ||
} | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.