Commit e5bbbc7b authored by Werner Sembach's avatar Werner Sembach
Browse files

Cleanup

parent 42d73c76
......@@ -7,7 +7,7 @@ extern "C" {
#endif
void adc_init(void);
uint16_t adc_get(uint8_t channel);
uint32_t adc_get(uint8_t channel);
#ifdef __cplusplus
}
......
......@@ -11,7 +11,7 @@ extern "C" {
void button_init(void);
int button_get(void);
bool button_get(void);
#ifdef __cplusplus
}
......
......@@ -19,45 +19,18 @@ static cyg_thread threaddata;
void main_thread(cyg_addrword_t arg) {
all_init();
unsigned int loop = 0;
while(1) {
printf("Loop: %8d\n", loop++);
servo_set_percent(SERVO_0, 0.0);
servo_set_percent(SERVO_1, 0.0);
servo_set_percent(SERVO_2, 0.0);
servo_set_percent(SERVO_3, 0.0);
cyg_thread_delay(5000);
servo_set_percent(SERVO_0, 0.5);
servo_set_percent(SERVO_1, 0.5);
servo_set_percent(SERVO_2, 0.5);
servo_set_percent(SERVO_3, 0.5);
cyg_thread_delay(5000);
servo_set_percent(SERVO_0, 1.0);
servo_set_percent(SERVO_1, 1.0);
servo_set_percent(SERVO_2, 1.0);
servo_set_percent(SERVO_3, 1.0);
cyg_thread_delay(5000);
}
/*bool button_pressed = false;
bool button_pressed = false;
bool spring_broken = false;
bool upside_down = false;
servo_set(SERVO_0, 0);
servo_set_percent(SERVO_0, 0.0);
dc_set(0, 0);
while (true) {
//check if solved
if(button_pressed && spring_broken && upside_down) {
ezs_printf("CONGRATULATIONS! YOU FINALLY MADE IT!\n");
servo_set(SERVO_0, 255);
servo_set_percent(SERVO_0, 1.0);
break;
}
......@@ -75,7 +48,7 @@ void main_thread(cyg_addrword_t arg) {
else {
block_spring();
}
}*/
}
}
void cyg_user_start(void) {
......
......@@ -56,12 +56,11 @@ extern "C" void adc_init() {
adc_power_on(ADC1);
}
extern "C" uint16_t adc_get(uint8_t channel) {
extern "C" uint32_t adc_get(uint8_t channel) {
uint8_t channel_array[16];
channel_array[0] = channel;
adc_set_regular_sequence(ADC1, 1, channel_array);
adc_start_conversion_regular(ADC1);
while (!adc_eoc(ADC1));
uint16_t reg16 = adc_read_regular(ADC1);
return reg16;
return adc_read_regular(ADC1);
}
// huge codechuncks copied from ezs_dac.c by Florian Jung of libEZS
//huge codechuncks copied from libEZS from file ezs_dac.c by Florian Jung
#include "DCMotor.h"
......@@ -96,12 +96,12 @@ static void pwm_init(uint32_t timer, uint8_t channel, uint32_t period) {
}
}
static void pwm_setup(void) {
static void pwm_setup() {
rcc_periph_clock_enable(RCC_TIM3);
pwm_init(TIM3, 1, PWM_PERIOD);
pwm_init(TIM3, 2, PWM_PERIOD);
pwm_init(TIM3, 3, PWM_PERIOD);
pwm_init(TIM3, 4, PWM_PERIOD);
pwm_init(TIM3, 1, (uint32_t)PWM_PERIOD);
pwm_init(TIM3, 2, (uint32_t)PWM_PERIOD);
pwm_init(TIM3, 3, (uint32_t)PWM_PERIOD);
pwm_init(TIM3, 4, (uint32_t)PWM_PERIOD);
// PWM channels = PB0, PB1
// AHB1-bus ? _ gpIO Port D ENable
......@@ -129,10 +129,10 @@ void dc_init() {
void dc_set(uint8_t direction, uint8_t speed) {
if (direction == DC_RIGHT) {
timer_set_oc_value(TIM3, TIM_OC4, 0);
timer_set_oc_value(TIM3, TIM_OC3, speed * PWM_PERIOD / 255);
timer_set_oc_value(TIM3, TIM_OC3, (uint32_t)(speed * PWM_PERIOD / 255));
}
else if (direction == DC_LEFT) {
timer_set_oc_value(TIM3, TIM_OC3, 0);
timer_set_oc_value(TIM3, TIM_OC4, speed * PWM_PERIOD / 255);
timer_set_oc_value(TIM3, TIM_OC4, (uint32_t)(speed * PWM_PERIOD / 255));
}
}
......@@ -6,8 +6,8 @@ extern "C" void button_init() {
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(D, 11, PULLUP));
}
extern "C" int button_get() {
extern "C" bool button_get() {
int button;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(D, 11, PULLUP), &button);
return !button;
return !(bool)button;
}
// huge codechuncks copied from ezs_dac.c by Florian Jung of libEZS
//huge codechuncks copied from libEZS from file ezs_dac.c by Florian Jung
#include "ServoMotor.h"
......
......@@ -96,7 +96,7 @@ extern "C" double get_degree_max() {
// TODO: make parameters possible in a cool way
// get array with (thresold, direction, power, solved)
extern "C" bool simulate_spring() {
uint16_t adc_value = adc_get(11);
uint32_t adc_value = adc_get(11);
if (adc_value < 256) {
//potty protection deadzone
......@@ -109,7 +109,7 @@ extern "C" bool simulate_spring() {
}
else {
//main simulation
dc_set(DC_RIGHT, adc_value / 4096.0 * 255);
dc_set(DC_RIGHT, (uint8_t)(adc_value / 4096.0 * 255));
}
return false;
}
......@@ -117,13 +117,12 @@ extern "C" bool simulate_spring() {
// turns the motor real fast if in certain position
// TODO: make that position a parameter
extern "C" void block_spring() {
uint16_t adc_value = adc_get(11);
uint32_t adc_value = adc_get(11);
if(adc_value > 2048) {
dc_set(DC_RIGHT, 255);
}
else if(adc_value > (2048 - 256)) {
uint8_t speed = adc_value - (2048 - 256) / 256.0 * 255;
dc_set(DC_RIGHT, speed);
dc_set(DC_RIGHT, (uint8_t)(adc_value - (2048 - 256) / 256.0 * 255));
}
else {
dc_set(0, 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