Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Werner Sembach
Ainigma
Commits
82f02b74
Commit
82f02b74
authored
Sep 07, 2017
by
Werner Sembach
Browse files
Finish implementing and debugging example riddles
parent
7bb3d92b
Changes
4
Hide whitespace changes
Inline
Side-by-side
main.c
View file @
82f02b74
...
@@ -3,10 +3,11 @@
...
@@ -3,10 +3,11 @@
#include
"Util.h"
#include
"Util.h"
//
#include "
spring
_riddle.h"
#include
"
easy
_riddle.h"
#include
"hill_riddle.h"
//
#include "hill_riddle.h"
//#include "lever_riddle.h"
//#include "lever_riddle.h"
//#include "easy_riddle.h"
//#include "nine_riddle.h"
//#include "spring_riddle.h"
#define STACKSIZE (CYGNUM_HAL_STACK_SIZE_MINIMUM+1024)
#define STACKSIZE (CYGNUM_HAL_STACK_SIZE_MINIMUM+1024)
static
cyg_uint8
my_stack
[
STACKSIZE
];
static
cyg_uint8
my_stack
[
STACKSIZE
];
...
...
riddles/nine_riddle.h
0 → 100644
View file @
82f02b74
#pragma once
#include
<stdint.h>
#include
<stdio.h>
#include
<inttypes.h>
#include
<stdio.h>
#include
"DCMotor.h"
#include
"ExternButton.h"
#include
"LeverKey.h"
#include
"ServoMotor.h"
#include
"Util.h"
void
riddle
(
void
)
{
bool
button_pressed
=
false
;
bool
spring_broken
=
false
;
bool
upside_down
=
false
;
bool
levers_set
=
false
;
servo_set_percent
(
SERVO_0
,
0
.
5
);
dc_set_percent
(
0
,
0
.
0
);
while
(
true
)
{
//poti protection
bool
protection
=
block_spring
(
LOWER_BOUND
,
256
)
||
block_spring
(
UPPER_BOUND
,
4096
-
256
);
//check if solved
if
(
button_pressed
&&
spring_broken
&&
upside_down
&&
levers_set
)
{
printf
(
"CONGRATULATIONS! YOU FINALLY MADE IT!
\n
"
);
servo_set_percent
(
SERVO_0
,
1
.
0
);
break
;
}
button_pressed
=
button_get
();
double
degree_max
=
get_degree_max
();
upside_down
=
(
degree_max
<
90
);
//spring riddle can only be solved if button is pressed
if
(
!
protection
)
{
if
(
spring_broken
)
{
dc_set_percent
(
0
,
0
.
0
);
}
else
if
(
button_pressed
)
{
spring_broken
=
simulate_spring_simple
();
}
else
if
(
!
block_spring
(
UPPER_BOUND
,
2048
))
{
dc_set_percent
(
0
,
0
.
0
);
}
}
//Binary 9 up binary 6 down
levers_set
=
lever_get
(
LEVER_0
)
==
1
&&
lever_get
(
LEVER_3
)
==
1
&&
lever_get
(
LEVER_1
)
==
-
1
&&
lever_get
(
LEVER_2
)
==
-
1
;
}
}
\ No newline at end of file
riddles/spring_riddle.h
View file @
82f02b74
...
@@ -48,7 +48,7 @@ void riddle(void) {
...
@@ -48,7 +48,7 @@ void riddle(void) {
}
}
}
}
//same riddle using parametrized spring simulation
//same riddle using parametrized spring simulation
, however the liniar simulation is broken there
/*struct spring riddle1[3];
/*struct spring riddle1[3];
riddle1[0] = set_spring(256, 'n', 0, false); //potty deadzone
riddle1[0] = set_spring(256, 'n', 0, false); //potty deadzone
riddle1[1] = set_spring(4096 - 256, 'r', -1, false); // main spring simulation
riddle1[1] = set_spring(4096 - 256, 'r', -1, false); // main spring simulation
...
...
src/Util.cpp
View file @
82f02b74
...
@@ -149,6 +149,7 @@ extern "C" bool simulate_spring(Spring springs[], size_t length) {
...
@@ -149,6 +149,7 @@ extern "C" bool simulate_spring(Spring springs[], size_t length) {
for
(
size_t
i
=
0
;
i
<
length
;
i
++
){
for
(
size_t
i
=
0
;
i
<
length
;
i
++
){
if
(
adc_value
<
springs
[
i
].
threshold
){
if
(
adc_value
<
springs
[
i
].
threshold
){
if
(
springs
[
i
].
power
<
0
){
if
(
springs
[
i
].
power
<
0
){
//FIXME both directions and dynamic start and endpoint
if
(
springs
[
i
].
direction
==
SPRING_LEFT
){
if
(
springs
[
i
].
direction
==
SPRING_LEFT
){
dc_set_percent
(
DC_LEFT
,
adc_value
/
4096.0
);
dc_set_percent
(
DC_LEFT
,
adc_value
/
4096.0
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment