-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
randomtest.ini is completed and tested
- Loading branch information
Vasileios Bimpikas
committed
Apr 3, 2015
1 parent
6b2a0ec
commit bd60d0d
Showing
6 changed files
with
124 additions
and
2 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
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,119 @@ | ||
// randomTest(); simulateCarMotor(); | ||
|
||
SIGNAL void randomTest() | ||
{ | ||
int pos; | ||
int i, j; | ||
int lastPulsePinValue; | ||
int reached1, reached2, reached3; | ||
int requested1, requested2, requested3; // 1 if a call has been made to this floor | ||
int at_floor; | ||
|
||
// Random variables | ||
int randButton, initFeed, random, count, delay; | ||
|
||
reached1 = 0; | ||
reached2 = 0; | ||
reached3 = 0; | ||
requested1 = 0; | ||
requested2 = 0; | ||
requested3 = 0; | ||
pos = 0; | ||
count = 0; | ||
at_floor = 0; | ||
|
||
// Initially feed the random variable | ||
initFeed = rand(0xAB21); | ||
printf("initFeed: %d\n", initFeed); | ||
random = rand(initFeed); | ||
|
||
printf("randomTest() is running\n"); | ||
while(1) // run forever | ||
{ | ||
// Get a random value at every iteration depending on counter | ||
random = rand(count + random); // counter's number is arbitary (because we're starting with random delay) | ||
delay = random % 5; // 0 to 5 sec (maximum) delay | ||
|
||
// call from random floor | ||
randButton = rand(count + random) % 3; | ||
PORTC |= 1 << randButton; | ||
|
||
// register that a call to this floor has been made | ||
if(randButton == 0) | ||
requested1 = 1; | ||
else if(randButton == 1) | ||
requested2 = 1; | ||
else | ||
requested3 = 1; | ||
|
||
// close the doors | ||
PORTC |= 1 << 8; | ||
|
||
swatch(0.0025); | ||
// reset the pin (button) | ||
PORTC ^= 1 << randButton; | ||
|
||
|
||
// delay for the generated amount of time | ||
while(j < delay) | ||
j++; | ||
j = 0; | ||
at_floor = 0; | ||
// every second, check whether we are at a floor | ||
if ((PORTC & (1 << 7)) && !TIM3_CCR1 && !TIM3_CCR2) | ||
{ | ||
if (pos >= -1 && pos <= 1 && !reached1) { | ||
// reached floor 1 | ||
printf("arrived at floor 1\n"); | ||
reached1 = 1; | ||
if(!requested1) | ||
printf("Unnecessary stop!\n"); | ||
requested1 = 0; // served | ||
at_floor = 1; | ||
} | ||
if (pos >= 399 && pos <= 401 && !reached2) { | ||
// reached floor 2 | ||
printf("arrived at floor 2\n"); | ||
reached2 = 1; | ||
if(!requested2) | ||
printf("Unnecessary stop!\n"); | ||
requested2 = 0; // served | ||
at_floor = 1; | ||
} | ||
if (pos >= 799 && pos <= 801 && !reached3) { | ||
// reached floor 3 | ||
printf("arrived at floor 3\n"); | ||
reached3 = 1; | ||
if(!requested3) | ||
printf("Unnecessary stop!\n"); | ||
requested3 = 0; // served | ||
at_floor = 1; | ||
} | ||
} | ||
|
||
|
||
if (TIM3_CCR1 || TIM3_CCR2) // if the elevator is moving, nothing has been reached | ||
{ | ||
reached1 = 0; | ||
reached2 = 0; | ||
reached3 = 0; | ||
} | ||
|
||
// if we have stopped at a floor, we open the doors for 1s | ||
if (at_floor) | ||
PORTC ^= 1 << 8; | ||
|
||
// wait 1s | ||
for (i = 0; i < 400; ++i) { | ||
if (lastPulsePinValue < (PORTC & (1 << 9))) | ||
pos += TIM3_CCR1 ? 1 : -1; | ||
lastPulsePinValue = PORTC & (1 << 9); | ||
swatch(0.0025); | ||
} | ||
|
||
// close the doors | ||
PORTC |= 1 << 8; | ||
|
||
count++; // increment the counter. Used as rand() feed. Overflow of this counter is desired (more random values) | ||
} | ||
} |
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
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