Sensoren auslesen/umwandeln/codieren und State Maschine

Dependencies:   mbed

Fork of StateMachine_1 by Roboshark

StateMachine.cpp

Committer:
Jacqueline
Date:
2018-04-19
Revision:
3:6e28589a732f
Parent:
1:619ca6edc4a9
Child:
4:91a9737e4821

File content as of revision 3:6e28589a732f:

#include "mbed.h"
 
case FORWAERTSFAHREN:

    buttonNow = button->read();
    if (buttonNow && !buttonBefore){
        controller-> setTranslationVelocity(0.0f);
        state = LANGSAM_FAHREN;
        }
        else if(((irSensorF.read() < DISTANCE_F)
        && (irSensorR.read() < DISTANCE_R)) {
            controller.setTranslationVelocity(0.0f);
            controller.setRotationVelocity(ROTATION_VELOCITY);
            state = 270_GRAD_RECHTS;
            }
        else if(irSensorR.read() > DISTANCE_R){
        controller.setTranslationVelocity(0.0f);
         controller.setRotationVelocity(ROTATION_VELOCITY);
            state = 90_GRAD_RECHTS;
            }
        else if((irSensorF.read() < DISTANCE_F)
        && (irSensorR.read() < DISTANCE_R) (SensorL.read() < DISTANCE_THRESHOLD)) {
            controller.setTranslationVelocity(0.0f);
            controller.setRotationVelocity(ROTATION_VELOCITY);
            state = 180_GRAD_RECHTS;
            }
            buttonBefore = buttonNow;
            break;
            
 
case 90_GRAD_RECHTS
 
    buttonNOW = button.read();
    if (buttonNow && !buttonBefore {  // deect button rising edge
    controller.setRotationalVelocity(0.0f);
    state = LANGSAM_FAHREN;
        } else if ((irSensorR < DISTANCE_R) {
        controller.setTranslationalvelocity(TRANSLATIONAL_VELOCITY);
        state = VORWAERTSFAHREN;
    }
    
    
 
case 270_GRAD_RECHTS
 
    buttonNow = button.read();
    if (buttonNow && !buttonBefore {  //detect button rising edge
        controller.set RotationalVelociy(0.0f);
        state = LANGSAM_FAHREN;
        } else if ((irSensorF.read() > DISTANCE_F)
                && (irSensorR.read() > DISTANCE_R)
                && (irSensorL.read() < DISTANCE_L) {
    controller.setTranslationalVelocity(TRANSLATIONAL_VELOCITY);
    state= VORWAERTSFAHREN;
}


case 180_GRAD_RECHTS
 
    buttonNow && !button.read();
    if (buttonNow && !buttonBefore {  // detect button rising edge
        state = LANGSAM_FAHREN;
        } else if (( irSensorR.read() > DISTANCE_R)
            && (irSensorF.read() > DISTANCE_F)
            && (irSensorL.read() > DISTANCE_L)) {
    controller.setTranslationalVelocity(TRANCLATIONAL_VELOCITY) {
    state = VORWAERTSFAHREN;
    
    
    
case LANGSAM_FAHREN;
 
    if ((fabs(controller.getActualTranslationalVelocity()) < 0.01f )
        && (fabs(controller.getActualRotationalVelocity()) < 0.1f ) {
        enableMotorDriver = 0;
        state = ROBOT_OFF;
        }
        break;