Commit 82f02b74 authored by Werner Sembach's avatar Werner Sembach
Browse files

Finish implementing and debugging example riddles

parent 7bb3d92b
......@@ -3,10 +3,11 @@
#include "Util.h"
//#include "spring_riddle.h"
#include "hill_riddle.h"
#include "easy_riddle.h"
//#include "hill_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)
static cyg_uint8 my_stack[STACKSIZE];
......
#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
......@@ -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];
riddle1[0] = set_spring(256, 'n', 0, false); //potty deadzone
riddle1[1] = set_spring(4096 - 256, 'r', -1, false); // main spring simulation
......
......@@ -149,6 +149,7 @@ extern "C" bool simulate_spring(Spring springs[], size_t length) {
for(size_t i = 0; i < length; i++){
if (adc_value < springs[i].threshold){
if (springs[i].power < 0){
//FIXME both directions and dynamic start and endpoint
if (springs[i].direction == SPRING_LEFT){
dc_set_percent(DC_LEFT, adc_value / 4096.0);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment