Tobis Programm forked to not destroy your golden files

Dependencies:   mbed

Fork of Robocode by PES 2 - Gruppe 1

source/movement.cpp

Committer:
cittecla
Date:
2017-03-02
Revision:
20:859c7aebf8a6
Parent:
19:baa8371d55b4
Child:
21:cb40c0533bc2

File content as of revision 20:859c7aebf8a6:

/**
 * Movement function library
 * Handels Movement of the Robot
**/


#include "mbed.h"
#include "move.h"

static double time_counter = 0.0f;
static double timer0 = 0.0f;
static float PID_correction_value = 1.0f;

static float power_value_slow = 0.6f;
static float power_value_medium = 0.7f;
static float power_value_fast = 0.8f;
static float ludicrous_value = 1.0f;


//motor stuff
DigitalOut enableMotorDriver(PB_2);
PwmOut pwmL(PA_8);
PwmOut pwmR(PA_9);

void move_init()
{
    pwmL.period(0.00005f); // Setzt die Periode auf 50 μs
    pwmR.period(0.00005f);

    pwmL = 0.5f; // Setzt die Duty-Cycle auf 50%
    pwmR = 0.5f;
    enableMotorDriver = 0;
}

void move_forward_slow(float correction_value)
{
    pwmL = power_value_slow;
    pwmR = 1-power_value_slow*correction_value;
    enableMotorDriver = 1;
}

void move_forward_medium(float correction_value)
{
    pwmL = power_value_medium;
    pwmR = 1-power_value_medium*correction_value;
    enableMotorDriver = 1;
}

void move_forward_fast(float correction_value)
{
    pwmL = power_value_fast;
    pwmR = 1-power_value_fast*correction_value;
    enableMotorDriver = 1;
}

void move_backward_slow(float correction_value)
{
    pwmL = 1-power_value_slow*correction_value;
    pwmR = power_value_slow;
    enableMotorDriver = 1;
}

void move_backward_medium(float correction_value)
{
    pwmL = 1-power_value_slow*correction_value;
    pwmR = power_value_slow;
    enableMotorDriver = 1;
}

void move_backward_fast(float correction_value)
{
    pwmL = 1-power_value_slow*correction_value;
    pwmR = power_value_slow;
    enableMotorDriver = 1;
}

void stop_movement()
{
    enableMotorDriver = 1;
}

void sync_movement(bool speed, bool direction)
// PID correction Value calcualtion








// Call movement:
// direction 0 = backward, direction 1 = forward
// speed 0 = slow, speed 1 = medium
{
    if(direction && speed) {
        move_forward_medium(PID_correction_value);
    }
    if(direction && !speed) {
        move_forward_slow(PID_correction_value);
    }
    if(!direction && speed) {
        move_backward_medium(PID_correction_value);
    }
    if(!direction && !speed {
    move_backward_slow(PID_correction_value);
    }
}

void termiante_sync_movement(){
    PID_correction_value = 1.0f;
    }