Projekt code für Hfecter
Dependencies: PM2_Libary PM2_Example_PES_board
Diff: main.cpp
- Revision:
- 15:1ebd2ee7b1c8
- Parent:
- 14:cfe1311a63f0
- Child:
- 16:5d4a58eecf55
--- a/main.cpp Sun May 09 15:02:06 2021 +0000 +++ b/main.cpp Thu May 13 16:28:04 2021 +0000 @@ -8,7 +8,7 @@ #include "PositionController.h" #include "FastPWM.h" #include "RangeFinder.h" - +/*Defines initialisieren*/ #define AUFLOESUNG 0.25412f #define FUELSENSOR 1 #define BATTERIE 2 @@ -22,10 +22,16 @@ InterruptIn user_button(USER_BUTTON); InterruptIn sensor(PA_1); - +/*Initialisierung outputs*/ +DigitalOut led(LED1); +AnalogOut BatteryLED (PA_5); +AnalogOut WeightLED (PA_4); +/*Initialisierung inputs*/ +AnalogIn adc_vbat(ADC_VBAT); +AnalogIn analogIn_2(PA_0); +DigitalIn digitalIn(D5); //AnalogIn analogIn_1(PA_1); -DigitalOut led(LED1); bool executeMainTask = false; Timer user_button_timer, loop_timer; @@ -37,15 +43,18 @@ void sensor_fall(); void led_blinken(int fehler); /* create analog input object */ -AnalogIn adc_vbat(ADC_VBAT); -DigitalIn digitalIn(D5); + -AnalogIn analogIn_2(PA_0); - +/*Variabeln initialisieren*/ float movement = 0.0f; float batt = 0.0f; float weight = 0.0f; float rotation = 0.0f; +int situation = FUELSENSOR; +int Fehler = 0; +int sensor_trig = 0; +int timer_1 = 0; +/*Initialisierung motor ¦ entnommen aus PM2_example_PES_board*/ /* create enable dc motor digital out object */ DigitalOut enable_motors(PB_15); /* create pwm objects */ @@ -64,13 +73,9 @@ PositionController positioncontroller_M2(counts_per_turn, kn, max_voltage, pwmOut_M2, encoderCounter_M2); /* analog output */ -AnalogOut BatteryLED (PA_5); -AnalogOut WeightLED (PA_4); -int situation = FUELSENSOR; -int Fehler = 0; -int sensor_trig = 0; -int timer_1 = 0; + +/*Hauptprogramm*/ int main() { @@ -89,79 +94,79 @@ batt = adc_vbat.read()* (3.3f/AUFLOESUNG); loop_timer.reset(); - + weight = analogIn_2.read() * 5; /* ------------- start hacking ------------- -------------*/ - weight = analogIn_2.read() * 5; + movement = 0; -//roundf(analogIn_1.read()*1.2); rotation = positioncontroller_M2.getRotation(); switch (situation) { case FUELSENSOR: - if(weight < 4) { - WeightLED = 1; - situation = BATTERIE; - if (weight < 3.5) { - Fehler = F_FUELSENSOR; - situation = SPERREN; + if(weight < 4) {//Ist Der Füllstand Unter 25%? + WeightLED = 1;//Anzeige LED + situation = BATTERIE;//Weiter zu Batteriestand + if (weight < 3.5) {//Ist der Füllstand unter 10% + Fehler = F_FUELSENSOR;//Weitergabe Feler + situation = SPERREN;//Gerät sperren } } else { - WeightLED = 0; - situation = BATTERIE; + WeightLED = 0;//LED AUS + situation = BATTERIE;//Weiter zu Batteriestand } break; - case BATTERIE: - if(batt <3.2) { - BatteryLED = 1; - situation = SENSOR; - if(batt < 3) { - //fehler = F_BATTERIE; - //situation = FEHLER; + case BATTERIE: //Der Batteriestand + if(batt <3.2) { //Ist der Batteriesand Unter 25% + BatteryLED = 1;//Anzeige LED + situation = SENSOR;//Weiter zu Sensor + if(batt < 3) {//Ist der Batteriestand unter 10% + fehler = F_BATTERIE;//Weitergabe Fehler + situation = FEHLER;//Gerät sperren } } else { - BatteryLED = 0; - situation = SENSOR; + BatteryLED = 0;//LED AUS + situation = SENSOR;//Weiter zu Sensor } break; - case SENSOR: - if (sensor_trig == 1) { - situation = MOTOR; - sensor_trig = 0; + case SENSOR: //Sensor + if (sensor_trig == 1) {//Wurde der Bewegungsensor Betätigt + situation = MOTOR;//Weiter zu Motor + sensor_trig = 0; } else { - situation = FUELSENSOR; + situation = FUELSENSOR;//Weiter zu Füllsensor } break; - case MOTOR: - if(timer_1 > 200) { - enable_motors = 1; + case MOTOR: //Motor + if(timer_1 > 200) { //Ist genug zeit vergangen das jemand seine Hand wegnemmen konte(hier 2 sek) + enable_motors = 1; //motor ein positioncontroller_M2.setDesiredRotation(1.0f); - if (timer_1 ==500) { + if (timer_1 ==500) {//Hat der motor lange genug gedreht? positioncontroller_M2.setDesiredRotation(0.0f); - enable_motors = 0; + enable_motors = 0;//Motor aus timer_1 = 0; - situation = FUELSENSOR; + situation = FUELSENSOR;//weiter zu Füllsensor } else { - timer_1 ++; + timer_1 ++; //warten } } else { - timer_1 ++; + timer_1 ++; //warten } break; + /*Gerät Sperren*/ case SPERREN: - if (Fehler == F_FUELSENSOR) { - led_blinken(F_FUELSENSOR); - if(weight > 4.2) { - WeightLED = 0; - situation = BATTERIE; + if (Fehler == F_FUELSENSOR) { //Liegt der Fehler beim Füllsensor? + led_blinken(F_FUELSENSOR);//Anzeige LED Blinken + if(weight > 4.2) { //Liegt der Füllstand über 30% + WeightLED = 0; //LED aus + situation = BATTERIE; //Weiter Batteriestand } } else { - led_blinken(F_BATTERIE); + led_blinken(F_BATTERIE);//Anzeige LED Blinken if(batt >3.2) { - BatteryLED = 0; - situation = SENSOR; + BatteryLED = 0; //LED aus + situation = SENSOR;//Weiter zu Sensor } } break; @@ -177,8 +182,7 @@ movement, weight, batt, - timer_1, - motor); + timer_1); /* ------------- stop hacking ------------- -------------*/ @@ -198,8 +202,8 @@ void sensor_fall() { - if (situation == SENSOR) { - motor = 1; + if (situation != MOTOR && situation != SPERREN) { + sensor_trig = 1; }