Dominik Święch
/
Czosnekengine
Czosnekengine
Revision 0:a0c8b50a7292, committed 2016-05-18
- Comitter:
- yruiewyrui3
- Date:
- Wed May 18 12:08:19 2016 +0000
- Commit message:
- losowo przod i tyl
Changed in this revision
diff -r 000000000000 -r a0c8b50a7292 Engine.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Engine.cpp Wed May 18 12:08:19 2016 +0000 @@ -0,0 +1,37 @@ +#include "Engine.h" + +// przelicza procenty na pwn: +// - wartosc poczatkowa - 0.2377, +// - prog - 0.0077 +float Engine::getPwm(float speed){ + if (speed == 0) + return 0; + else if (speed > 0) + return 0.2377f + (fabs(speed) - 1) * 0.0077f; + else + return 0.406f + (fabs(speed) - 1) * 0.006f; + } + +void Engine::move(int speed){ + if (speed == 0){ + //soft stop + _fwd = 0; + _rev = 0; + return; + } + + if (speed < 0){ + _fwd = 0; + _rev = 1; + } + else{ + _fwd = 1; + _rev = 0; + } + _pwm = getPwm(speed); +} + +//hard stop +void Engine::stop(){ + _pwm = 0; +} \ No newline at end of file
diff -r 000000000000 -r a0c8b50a7292 Engine.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Engine.h Wed May 18 12:08:19 2016 +0000 @@ -0,0 +1,22 @@ +#ifndef ENGINE_H +#define ENGINE_H + +#include "mbed.h" + + +class Engine{ + private: + PwmOut _pwm; + DigitalOut _fwd; + DigitalOut _rev; + + float getPwm(float val); + + public: + Engine(PinName pwm, PinName fwd, PinName rev): _pwm(pwm), _fwd(fwd), _rev(rev){} + void move(int speed); // silniki pracuja z okreslona predkoscia (speed ma zakres od -1 do 1) + void stop(); //hard stop +}; + + +#endif \ No newline at end of file
diff -r 000000000000 -r a0c8b50a7292 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 18 12:08:19 2016 +0000 @@ -0,0 +1,36 @@ +#include "Engine.h" + +Serial pc(SERIAL_TX, SERIAL_RX); +int liczba =0; +int main() { + //inicjalizacja silnikow - piny dzialaja: + Engine eng_left = Engine(PB_13, PB_4, PB_10); + Engine eng_right = Engine(PB_14, PB_5, PB_3); + + + while(true) { + // testy - przyspiesz od 0 do 100% a potem zwolnij: + eng_left.move(0); + eng_right.move(0); + wait(1); + srand( time( NULL ) ); + liczba = (std::rand() % 200 ) - 100; + eng_left.move(liczba); + eng_right.move(liczba); + wait(5); + if (liczba==0){ + pc.printf("%f", time(NULL)); + pc.printf("Nie ma wiatru, wiec stoje w miejscu."); + } + else if (liczba>0){ + pc.printf("%f", time(NULL)); + pc.printf("Jade do przodu. Predkosc w procentach to %d \n", liczba); + } + else { + pc.printf("%f", time(NULL)); + pc.printf("Jade do tylu. Predkosc w procentach to %d \n", liczba); + } + + } + +} \ No newline at end of file
diff -r 000000000000 -r a0c8b50a7292 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed May 18 12:08:19 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e \ No newline at end of file