Breadcrumbs


Prídavné zariadenia

Sieťové komponenty

Iné články

Online chat


Turn off/on Sound Options Smileys History FAQ Kide Chat

Powered by Kide Shoutbox

17:50-- PUSyySlaERxXx69: even emotikens no working srsly what is dis? git gut
9:59-- USak M9: Stfu, stupid kid get real life m9, i'm 3pro5uM9
10:03-- Gesg TG sd: 8) :_(;);):-*
10:03-- Gesg TG sd: :_(
10:03-- KOKOD: Drz piču
10:03-- Gesg TG sd: Coze sam si ju drz
10:03-- KOKOD: :)
10:03-- Gesg TG sd: halío
10:04-- Gesg TG sd: was was?
10:04-- KOKOD: šaize
10:04-- Gesg TG sd: 451gsd
10:04-- Gesg TG sd: svinia
10:04-- Gesg TG sd: jedna
10:04-- Gesg TG sd: velka
10:04-- KOKOD: :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :)
10:04-- Gesg TG sd: :D :D:D(!)(?):(:(:(:)8):) ;)
10:05-- KOKOD: :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :)
10:05-- Gesg TG sd: :) :):):_(:_(:_(
10:05-- System: Gesg TG sd has been banned


Endora



Reklama



Návštevnosť


Dnes158
Včera331
Tento týždeň1739
Tento mesiac3450
Celkovo6256

Vaša IP je 13.59.177.14 Prehliadate z Unknown - Unknown nedeľa, 12. máj 2024, 12:36

Kto je online?

Guests : 127 guests online Members : No members online
Powered by CoalaWeb


Auto ovládané cez internet - Program Arduina

Odkaz na stiahnutie zdrojového kódu programu a knižníc | [stará verzia]

/* * * * * * * * * * * * * * * *
* Auto ovládané cez internet
* Arduino program vozidla
*
* Autor: scsc
*
* Licencia: Voľný softvér, Open-Source GNU GPL v3+
* Všeobecná verejná licencia. Program je dovolené voľne šíriť a upravovať.
* Upravený program / časť programu môže ktokoľvek využiť ako na osobné,
* tak aj komerčné účely, ale nemôže ho vydať s vlastným copyrightom,
* ktorý nie je kompatibilný s GNU GPL v3+.
* gnu.org/licenses/gpl-faq.html
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

//Program funguje dobre pri kapacite flash 29,436 bytes (todo: odmerat presnejsie)

//Oficiálne knižnica Arduina pre Ethernet
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

//Oficiálna knižnica Arduina pre servo motory
#include <Servo.h>

//Oficiálna knižnica Arduina pre teplomer
#include <OneWire.h>

//Neoficiálna knižnica na časovanie funkcií
#include <SoftTimer.h>

//Všetky piny Arduina
int pin_motor = 2; //PWM motor - pohon zadných kolies
int pin_riadenie = 3; //servo - otáčanie predných kolies
int pin_sonic_echo_dozadu = 4; //sonické senzory
int pin_sonic_trigger_dozadu = 5;
int pin_sonic_echo_dopredu = 6;
int pin_sonic_trigger_dopredu = 7;
int pin_teplomer = 8; //OneWire teplomer
int pin_trubenie = 9; //trúbenie
int pin_feedback_napajania = A0; //feedback aktualneho stavu baterie cez delic napatia
int pin_vypnutie_napajania = A1; //digitálny výstup, odpojenie batérie v prípade vybitia (inak je riziko jej zničenia)
int pin_webcam = A2; //digitálny výstup, odpojenie webkamery od napájania na základe požiadavky používateľa

Servo riadenie; //objekt servo motora riadiaceho predne kolesa

Task motor_pohyb_task(20, motor_pohyb); //objekt SoftTimer.h, hlavny cyklus programu

//nastavovacie premenne pre server
byte mac[] = {
0xDE, 0xAD, 0xDE, 0xAD, 0xCA, 0xFE //MAC adresa pre Ethernet Shield
};
IPAddress ip(192,168,1,2); //staticka IP serverov ak sa nepouzije DHCP
EthernetServer server(80); //port pre webovy server
const int udp_port = 21315; //port pre UDP server

EthernetUDP udp; //objekt na komunikaciu s UDP klientom
EthernetClient client; //objekt na komunikaciu s TCP klientom

//konstanty smeru pre motor_smer
#define DOPREDU 0
#define DOZADU 1

//konstanty stavu pre motor_stav [1000-2000]
#define MIN_DOPREDU 1750
#define MAX_DOPREDU 2000
#define STOP 1500 //používa sa stále ak nepríde iný signál, podmienka PWM motora
#define MIN_DOZADU 1350
#define MAX_DOZADU 1000

//konstanty stavu pre riadenie [0-180]
#define ALT_VLAVO 120
#define VLAVO 160
#define STRED 90
#define VPRAVO 30
#define ALT_VPRAVO 60

//nastavovacie premenne pre servo motory a vedlajsie funkcie
boolean riadenie_reset = false; //automaticke resetovanie riadenia na centrovanu polohu
unsigned long motor_wait = 50; //cakanie pred resetom motora do vypnuteho stavu
unsigned long riadenie_wait = 50; //cakanie pred resetom serva na pohyb do stredu
unsigned long trubenie_wait = 50; //cakanie pred resetom trubenia
int motor_doba_zrychlovania = 50; //doba na dosiahnutie max. rychlosti pri zrychlovani
//hodnota urcuje pocet cyklov, cyklus trva 20 milisekund (50*20=1000 [ms])

//nastavovacie premenne pre sonicky senzor
int motor_sonic_limit_dopredu = 1750;
int motor_sonic_limit_dozadu = 1350;
boolean motor_sonic_limit = true; //defaultna hodnota pre aktivaciu spomalenia pri prekazke
int motor_sonic_limit_timer = 0; //zabezpecenie brzdenia po detekcii novej prekazky
float motor_sonic_limit_cm = 65.0; //vzdialenost od prekazky v cm pod ktorou vozidlo spomali

//bezpecnostne hodnoty pre odpojenie napajania
//limity napatia na baterii: min. 7.2V, max. 8.4V
//hodnota pre pin_feedback prichadza z delica napatia
//vypocet: feedback * cca. 105-115 = napatie na baterii
int feedback_napajania_min = 760;
int feedback_napajania_max = 850;
//int feedback_napajania_history[5] = {0}; //5 poslednych stavov pre vypocet priemerov
int feedback_napajania; //namerana hodnota na baterii
int feedback_napajania_i = 0; //odpocet pred vypnutim baterie
int feedback_napajania_i_max = 50; //pocet loop cyklov (20ms) pred vypnutim baterie
boolean feedback_napajania_DEACTIVATED = false;

/*
Feedback napatia na baterii je rieseny pomocou delica napatia (Arduino nepodporuje az 7V).
Polovica napatia na baterii ide do vstupneho pinu pin_feedback_napajania.
Po prekroceni max. alebo min. hodnoty sa zmeni hodnota na pin_vypnutie_napajania.
Namerana hodnota z delica napatia je priebezne ulozena v premennej feedback_napajania.
*/

//nastavovacie premenne pre teplomer
OneWire ds(pin_teplomer);

/*
Schema na zapojenie Teplomera
OneWire parazitny obvod pre DS18B20 teplomer (iba 2 piny),
ale lepsie je zapojit priamo 5V do Vdd pre stabilitu.
* ^D = GND
* -D = DQ [Data pin & Parasite power]
* _D (= Vdd)

* GND -> GND
* Data pin -> DQ
* +5V -> 4,7 pullup resistor (-> Diode) -> DQ
*/

//vnutorne premenne pre teplomer
float thermometer_celsius; //premenna, do ktorej sa stale uklada namerana teplota
int thermometer_ready = 0; //urcuje aktualny stav cykla (odpocet pred dalsim meranim)
byte thermometer_addr[8];
byte thermometer_type_s;
bool thermometer_found = false; //na zaciatku programu sa urci ci bol teplomer najdeny
bool thermometer_allowed = true; //povolenie teplomera po restarte arduina

//vnutorne premenne pre servo motory a vedlajsie funkcie
int motor_stav = STOP; //hlavna premenna na nastavovanie rychlosti motora
int motor_smer = DOPREDU; //spolu s hodnotou motor_stav ju treba prepisat na aktualny smer
int riadenie_stav = STRED; //potrebne pre osetrenie problemu prednych kolies na uplne centrovanie

unsigned long motor_wait_i = 0; //index cykla na odpocet resetu motora
unsigned long riadenie_wait_i = 0; //index cykla na odpocet resetu stavu riadenia
unsigned long trubenie_wait_i = 0; //index cykla na odpocet resetu stavu trubenia

int motor_zrychlovanie_i = 0; //index cykla na zrychlovanie

int regulator_fix = 0; //osetrenie chyby regulatora motora (prechod zo smeru dozadu -> dopredu)

//vnutorne premenne pre sonicky senzor
int sonic_smer = DOPREDU; //smer, pre ktory sa odmeria vzdialenost, po odmerani sa stale zmeni
float sonic_meranie_dopredu; //premenne, do ktorych sa stale ukladaju namerane hodnoty zo sonickych senzorov
float sonic_meranie_dozadu;

//vnutorne premenne pre web server
String cmd[2]; //prvy index = prikaz, druhy index = parameter
boolean show_index; //zobrazenie indexu; pre kazdeho klienta najprv true, urcite prikazy ho nastavia na false
boolean html_autorefresh = false; //refreshovanie iframu v indexe
boolean webcam_show = true; //zobrazenie nahladu webkameru v indexe
String webcam_address[5] =
{
"192","168","1","239","81"
};
boolean webcam_enabled = true; //premenna na odpojenie webkamery od napajania

//nastavovacie premenne zabezpecenia
String password = "heslo"; //heslo po zapnuti programu

//vnutorne premenne riadiace zabezpecenie
String password_input = ""; //heslo, pomocou ktoreho sa prave prihlasil pouzivatel
boolean password_correct = false; //nastavi sa true ak je nacitane heslo spravne alebo heslo neexistuje

//nastavovacie premenne pre trubenie
const int trubenie_freq_list_n = 4;
int trubenie_freq_list[trubenie_freq_list_n] =
{
20,50,150,255
};
int trubenie_freq = 100;

//vnutorne premenne pre trubenie
boolean trubenie = false;

//Jednorázovo vykonaná funkcia pre nastavenie na začiatku programu
void setup()
{
//Serial.begin(9600); //debug pre diagnostiku Arduina cez seriovy port (USB)
//nastavenie vstupneho a vystupneho pinu pre feedback napatia na baterii
pinMode(pin_vypnutie_napajania,OUTPUT);
pinMode(pin_feedback_napajania,INPUT);
digitalWrite(pin_vypnutie_napajania,0);

pinMode(pin_webcam,OUTPUT); //vystupny pin riadiaci odpojenie webkamery od napajania
pinMode(pin_trubenie,OUTPUT); //vystupny pin na trubenie

//if(Ethernet.begin(mac)==0) //odkomentovať pre automatické získanie IP adresy
Ethernet.begin(mac,ip); //statická IP adresa

//Serial.print("Server spusteny na IP ");
//Serial.println(Ethernet.localIP()); //debug informacia o uspesnosti pripojenia cez Ethernet

//spustenie TCP a UDP serverov
server.begin();
udp.begin(udp_port);

pinMode(pin_motor,OUTPUT); //nastavenie vystupneho pinu pre PWM motor
riadenie.attach(pin_riadenie); //pripojenie pinu servo motora na predne kolesa

//inicializacia hlavneho cyklu programu
SoftTimer.add(&motor_pohyb_task);

//nastavenie vstupnych a vystupnych pinov predneho a zadneho sonickeho senzora
pinMode(pin_sonic_echo_dopredu,INPUT);
pinMode(pin_sonic_trigger_dopredu,OUTPUT);
pinMode(pin_sonic_echo_dozadu,INPUT);
pinMode(pin_sonic_trigger_dozadu,OUTPUT);

//zistenie, ci je teplomer pripojeny (aby zbytocne nebezal cyklus merania ak nie je)
if(ds.search(thermometer_addr))thermometer_found = true;
}

//Funkcia na výpočet mocníny n^e
unsigned long my_pow(unsigned long n, int e)
{
if(e==0)
{
return 1;
}
unsigned long a=n;
for(int i=1;i<e;i++)
{
a*=n;
}
return a;
}

//Funkcia na naplnenie Stringov cmd[0] a cmd[1] v tvare ?cmd[0]=cmd[1] zo vstupného Stringu
int get_cmd(String get, int i_start = 0)
{
/*
Ak je iba jeden prikaz vrati 0.
Ak je viac prikazov tak zoberie prvy a vrati index pre dalsi.
Pre ziskanie dalsieho prikazu treba jeho index dosadit
ako druhy parameter tejto funkcie.
*/
cmd[0]="";
cmd[1]="";

//Vykonat kazdy GET prikaz zacinajuci na '?' alebo '&'
for(int i=i_start;i<get.length();i++)
{
if(get.charAt(i) == '?' || get.charAt(i) == '&')
{
int phase=0;
for(int j=i+1;j<get.length();j++)
{
//zmena faze nacitavania na parameter pri '=' a skoncenie pri '&' alebo ' '
if(get.charAt(j)=='=')
{
j++; //preskocit znak '='
phase=1;
}
if(get.charAt(j)==' ' || get.charAt(j)=='.')
{
//Koniec textu, ziadne dalsie prikazy
return 0;
}
if(get.charAt(j)=='&')
{
//Nasleduje dalsi prikaz, vrati index kde zacina
return j;
}

//faza 0: nacitat prikaz
if(phase==0)
{
cmd[0]+=get.charAt(j);
}
//faza 1: nacitat parameter
else if(phase==1)
{
cmd[1]+=get.charAt(j);
}
}
return 0;
}
}
//Koniec prikazu
return 0;
}

//Funkcia na získanie hodnoty teploty z digitálneho teplomera
void thermometer()
{
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
// Príklad dodávaný ku OneWire knižnici, prevzatý z:
// http://www.pjrc.com/teensy/td_libs_OneWire.html

byte i;
byte data[12];

/*
Funkcia rozdelena na fazy:
0 = pripravene na hladanie teplomera
1-999 = cakanie na nacitanie hodnoty
>=1000 = pripravene na nacitanie hodnoty
*/
if(thermometer_ready == 0)
{
if(thermometer_addr[0]==0x10) //Chip = DS18S20 or old DS1820
{
thermometer_type_s = 1;
}
else //Chip = DS18B20 or DS1822
{
thermometer_type_s = 0;
};
ds.reset();
ds.select(thermometer_addr);
ds.write(0x44,1); //start conversion, with parasite power on at the end

//zacat odpocet 1000ms na citanie
thermometer_ready = 20;
}
else if(thermometer_ready >= 1000)
{
ds.reset();
ds.select(thermometer_addr);
ds.write(0xBE); //Read Scratchpad

for (i=0; i<9; i++)
{
data[i]=ds.read();
};

// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (thermometer_type_s)
{
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else
{
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}

thermometer_celsius = (float)raw / 16.0;

//povolit nove citanie
thermometer_ready = 0;
}
else
{
thermometer_ready += 20;
}
}

//Prepočet premenných pre automatický reset servo motorov a vedľajších funkcií (zrýchlovanie a podobne)
void pocitanie_servo()
{
if(motor_wait_i>0)
{
if(motor_wait_i>motor_wait)
{
motor_stav=STOP;
motor_wait_i=0;
motor_zrychlovanie_i=0;
}
else
{
motor_wait_i++;
}
}

if(riadenie_reset && riadenie_wait_i>0)
{
if(riadenie_wait_i>riadenie_wait)
{
riadenie_stav=STRED;
riadenie.write(STRED);
riadenie_wait_i=0;
}
else
{
riadenie_wait_i++;
}
}

if(motor_zrychlovanie_i>0)
{
//Ak sa dosiahla hodnota limitu zrychlovania - zostat na maximalnej rychlosti
if(motor_zrychlovanie_i>=motor_doba_zrychlovania)
{
motor_zrychlovanie_i=motor_doba_zrychlovania;
if(motor_smer==DOPREDU)
{
motor_stav=MAX_DOPREDU;
}
else if(motor_smer==DOZADU)
{
motor_stav=MAX_DOZADU;
}
}
else
{
//Plynule zychlovat motor smerom dopredu alebo dozadu
if(motor_smer==DOPREDU)
{
motor_stav=(float)motor_zrychlovanie_i/motor_doba_zrychlovania*(MAX_DOPREDU-MIN_DOPREDU)+MIN_DOPREDU;
}
else if(motor_smer==DOZADU)
{
motor_stav=MIN_DOZADU-(float)motor_zrychlovanie_i/motor_doba_zrychlovania*(MIN_DOZADU-MAX_DOZADU);
}
motor_zrychlovanie_i++;
}
}

if(trubenie_wait_i>0)
{
if(trubenie_wait_i>trubenie_wait)
{
trubenie = false;
trubenie_wait_i=0;
}
else
{
trubenie_wait_i++;
}
}
}

//Vykonanie príkazu pre servo motor
void ovladanie(char c)
{
//Porovnat ci je prikaz medzi 'a' a 'z'
if(c >= 'a' && c <= 'z')
{
switch(c)
{
//reset
case 'x':
motor_stav=STOP;
motor_wait_i=0; //ziaden rozdiel vo funkcnosti
motor_zrychlovanie_i=0;
//riadenie.write(STRED);
//riadenie_wait_i=0;
break;

//motor_stav dopredu
case 'q':
if(motor_smer==DOZADU)regulator_fix=1; //osetrenie regulatora pred smerom dopredu
motor_smer=DOPREDU;
motor_stav=MIN_DOPREDU;
motor_wait_i=1;
motor_zrychlovanie_i=0;
break;

case 'w':
if(motor_smer==DOZADU)regulator_fix=1; //osetrenie regulatora pred smerom dopredu
if(motor_zrychlovanie_i==0 || motor_smer==DOZADU)
{
motor_smer=DOPREDU;
motor_zrychlovanie_i=1;
}
motor_wait_i=1;
break;

case 'e':
if(motor_smer==DOZADU)regulator_fix=1; //osetrenie regulatora pred smerom dopredu
motor_smer=DOPREDU;
motor_stav=MAX_DOPREDU;
motor_wait_i=1;
motor_zrychlovanie_i=0;
break;

//motor_stav dozadu
case 'y':
motor_smer=DOZADU;
motor_stav=MIN_DOZADU;
motor_wait_i=1;
motor_zrychlovanie_i=0;
break;

case 's':
if(motor_zrychlovanie_i==0 || motor_smer==DOPREDU)
{
motor_smer=DOZADU;
motor_zrychlovanie_i=1;
}
motor_wait_i=1;
break;

case 'c':
motor_smer=DOZADU;
motor_stav=MAX_DOZADU;
motor_wait_i=1;
motor_zrychlovanie_i=0;
break;

//riadenie
case 'f':
riadenie_stav=ALT_VLAVO;
riadenie.write(ALT_VLAVO);
riadenie_wait_i=1;
break;

case 'a':
riadenie_stav=VLAVO;
riadenie.write(VLAVO);
riadenie_wait_i=1;
break;

case 'd':
riadenie_stav=VPRAVO;
riadenie.write(VPRAVO);
riadenie_wait_i=1;
break;

case 'g':
riadenie_stav=ALT_VPRAVO;
riadenie.write(ALT_VPRAVO);
riadenie_wait_i=1;
break;

case 'r':
riadenie_stav=STRED;
riadenie.write(STRED);
riadenie_wait_i=0;
break;

//trubenie
case 't':
if(trubenie==false)trubenie_freq = trubenie_freq_list[random(0,trubenie_freq_list_n-1)];
trubenie = true;
trubenie_wait_i=1;
break;

case 'z':
trubenie = false;
trubenie_wait_i=0;
break;
}
}
}

//Funkcia spúšťaná každých 20ms, PWM ovládanie regulátora servo motora určeného na pohyb vpred/vzad
void motor_pohyb(Task* me)
{
/*
Regulator s obojsmernym pohybom:
1000-1470 = pohyb dozadu
1500 = ziaden pohyb = povinny standby signal, nestaci 0
1530-2000 = pohyb dopredu
*/

//zacat cyklus signalom 1 na pozadovanu dobu
digitalWrite(pin_motor,1);

//osetrenie pre regulator ktory nepodporuje skok zo smeru dozadu na smer dopredu
//- vykonat prvy cyklus dopredu, druhy cyklus stop a pokracovat normalne
if(regulator_fix==1 && motor_stav>1500)
{
regulator_fix=2;
}
else if(regulator_fix==2 && motor_stav>1500)
{
delayMicroseconds(STOP);
regulator_fix=0;
}
else
{
//Limitovanie rychlosti v pripade detekovanej prekazky
if(motor_sonic_limit)
{
//limit dopredu
if(motor_stav>motor_sonic_limit_dopredu && sonic_meranie_dopredu!=0 && sonic_meranie_dopredu<motor_sonic_limit_cm)
{
if(motor_sonic_limit_timer!= 0 && motor_sonic_limit_timer<4)
{
delayMicroseconds(MAX_DOZADU);
}
else if(motor_sonic_limit_timer==4)
{ //osetrenie regulatora pri prechode na smer vpred (vratenie po brzdeni)
delayMicroseconds(STOP);
}
else
{
delayMicroseconds(motor_sonic_limit_dopredu);
}
}
//limit dozadu
else if(motor_stav<motor_sonic_limit_dozadu && sonic_meranie_dozadu!=0 && sonic_meranie_dozadu<motor_sonic_limit_cm)
{
if(motor_sonic_limit_timer==1)
{ //osetrenie regulatora pri prechode na smer vpred (brzdenie)
delayMicroseconds(STOP);
}
else if(motor_sonic_limit_timer!= 0 && motor_sonic_limit_timer<6)
{
delayMicroseconds(MAX_DOPREDU);
}
else
{
delayMicroseconds(motor_sonic_limit_dozadu);
}
}
//ak ide povolenou rychlostou
else
{
delayMicroseconds(motor_stav);
}
}
//ak je funkcia spomalovania deaktivovana
else
{
delayMicroseconds(motor_stav);
if(motor_sonic_limit_timer>=25)motor_sonic_limit_timer = 0; //modul na spomalovanie bude vediet, ze prisla nova prekazka
}
}
if(motor_sonic_limit_timer>0)motor_sonic_limit_timer++;
digitalWrite(pin_motor,0); //po skonceni pozadovanej doby pre zvysok cyklu plati signal 0

//vykonat zvysok programu v prestavke pred dalsim cyklom
loop_falling();
}

//HTTP server, pripojenie cez webový prehliadač
void web_server()
{
client = server.available(); //zistit, ci sa pripojil novy pouzivatel
if(client)
{
password_correct = false; //heslo potrebne zadat pri kazdom pripojeni
password_input = "";

show_index = true;

String client_get;
int client_get_i = 0;
int client_get_reading = 0;
boolean client_blank_line = true;

//nacitat cely GET prikaz (adresu) a odpovedat klientovi
while(client.available())
{
char c = client.read();

//priprava na citanie GET
if(client_get_reading == 0)
{
//ak zacina obsah GET oznacit na citanie (1)
if(client_get_i>4)
{
client_get_reading = 1;
}
else
{
client_get_i++;
}
}

//citanie obsahu GET, po medzere oznacit ako skoncene (2)
if(client_get_reading == 1)
{
if(c != ' ')
{
client_get += c;
}
else
{
client_get_reading = 2;
}
}

if(c == '\n' && client_blank_line)
{
break;
}
if(c == '\n')
{
//http novy riadok
client_blank_line = true;
}
else if(c != '\r')
{
//http novy znak na riadku
client_blank_line = false;
}
}//koniec client.available()

//po nacitani poziadavky klienta odpovedat html kodom (odstranene F("") pre ziskanie pamate)
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html><head><title>Auto ovladane cez internet</title></head><body bgcolor=\"EEFFEE\"");
if(html_autorefresh)
{
client.print(" onload=window.setTimeout(\"location.reload(true);\",1)>\n");
}
else
{
client.print(F(">\n"));
}

//Vykona kazdy prikaz v String objekte client_get
int get_cmd_index = 0;
boolean last_cmd = false;
while(!last_cmd)
{
if(!(get_cmd_index = get_cmd(client_get,get_cmd_index)))
{
//Vykonat posledny prikaz
last_cmd = true;
}
//Spracovat GET prikazy pred zavretim body a html tagov
get_prikaz_vykonat();
}//koniec vykonavania getu

//ak nenastal exkluzivny prikaz ktory sa nema zobrazit v indexe, zobrazit index
if(show_index == true)
{
html_autorefresh=false; //osetrenie ak pouzivatel zapol autorefresh, ale znovu otvoril index
//vystup z webkamery
if(webcam_show)
{
client.print("<table border=\"0\"><tr><td>");
client.print("<iframe src=\"http://");
client.print(webcam_address[0]);
client.print(".");
client.print(webcam_address[1]);
client.print(".");
client.print(webcam_address[2]);
client.print(".");
client.print(webcam_address[3]);
client.print(":");
client.print(webcam_address[4]);
client.print("/video/liveipd.asp\" width=\"656\" height=\"551\"></iframe>");
client.print("</td><td><center>");
}
const __FlashStringHelper* td_ahref_text = (F("<td><a href=\"/?p="));
//iframe, v ktorom sa spustaju prikazy
client.print("<iframe name=\"car\" width=\"300\" height=\"36\" src=\"?p=");
if(password_input!="")client.print(password_input);
client.print("&cmd=\"></iframe><br>\n");
//tabulka na ovladanie vozidla
client.print("<table width=\"300\" height=\"100\" style=\"text-align:center\"><tr>\n");
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print("&cmd=q\" target=\"car\">[pomaly]</a></td>\n");
client.print(td_ahref_text);
client.print(password_input);
client.print("&cmd=w\" target=\"car\">DOPREDU</a></td>\n");
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print("&cmd=e\" target=\"car\">[rychlo]</a></td>\n");
client.print("</tr><tr>\n");
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print("&cmd=f\" target=\"car\">alt </a>\n");
client.print("<a href=\"/?p=");
if(password_input!="")client.print(password_input);
client.print("&cmd=a\" target=\"car\">VLAVO</a></td>\n");
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print("&cmd=r\" target=\"car\">[stred]</a></td>\n");
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print("&cmd=d\" target=\"car\">VPRAVO</a>\n");
client.print("<a href=\"/?p=");
if(password_input!="")client.print(password_input);
client.print("&cmd=g\" target=\"car\"> alt</a></td>\n");
client.print("</tr><tr>\n");
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print(F("&cmd=y\" target=\"car\">[pomaly]</a></td>\n"));
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print(F("&cmd=s\" target=\"car\">DOZADU</a></td>\n"));
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print(F("&cmd=c\" target=\"car\">[rychlo]</a></td></tr>"));
client.print(F("<tr><td></td>"));
client.print(td_ahref_text);
if(password_input!="")client.print(password_input);
client.print(F("&cmd=x\" target=\"car\">[stop]</a></td><td></td></tr></table>\n<p>"));
//ostatne funkcie
if(feedback_napajania_DEACTIVATED)
{ //upozornenie ak bola pouzita skryta funkcia na deaktivaciu ochrany baterie
client.print(F("<font color=\"red\">Bezpecnostne odpojenie baterie deaktivovane.</font><br>\n"));
}
if(feedback_napajania < feedback_napajania_min)
{ //upozornenie ak je bateria vybyta
client.print(F("<font color=\"red\">Bateria je vybita!!!</font><br>\n"));
}
//webkamera
client.print(F("Webkamera: <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&webcam=1\" target=\"car\">zapnut</a>"));
client.print(F(" | <a href=\"/?index=1&p="));
if(password_input!="")client.print(password_input);
client.print(F("&webcam=0\" target=\"car\">vypnut</a><br>"));
//zobrazit webkameru
client.print(F("Zobrazit webkameru: <a href=\"/?index=1&p="));
if(password_input!="")client.print(password_input);
client.print(F("&webcamshow=1\">ano</a>"));
client.print(F(" | <a href=\"/?index=1&p="));
if(password_input!="")client.print(password_input);
client.print(F("&webcamshow=0\">nie</a><br>"));
//autorefresh
client.print(F("Autorefresh prikazov: <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&autorefresh=1\" target=\"car\">ano</a>"));
client.print(F(" | <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&autorefresh=0\" target=\"car\">nie</a><br>"));
client.print(F("Vyrovnavanie prednych kolies: <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&riadeniereset=1\" target=\"car\">ano</a>"));
client.print(F(" | <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&riadeniereset=0\" target=\"car\">nie</a><br>"));
client.print(F("Spomalit pri prekazke: <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&soniclimit=1\" target=\"car\">ano</a>"));
client.print(F(" | <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&soniclimit=0\" target=\"car\">nie</a><br>"));
/*
Moznost povolit / zakazat teplomer z weboveho rozhrania
client.print(F("Teplomer: <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&teplomer=1\" target=\"car\">start</a>"));
client.print(F(" | <a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&teplomer=0\" target=\"car\">stop</a><br>"));
*/
client.print(F("<a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&bateria=1\" target=\"car\">Vypisat stav baterie</a><br>"));
client.print(F("<a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&teplota=1\" target=\"car\">Vypisat teplotu z teplomera</a><br>"));
client.print(F("<a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&sonic=1\" target=\"car\">Vypisat vzdialenost od prekazky</a><br>"));
//trubenie
client.print(F("<a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&cmd=t\" target=\"car\">Trubenie</a> | "));
client.print(F("<a href=\"/?p="));
if(password_input!="")client.print(password_input);
client.print(F("&cmd=z\" target=\"car\">stop</a><br></p>"));
//heslo
client.print(F("<form type=\"get\">\n"));
client.print(F("Pristupove heslo (ak je potrebne zabezpecenie):\n"));
client.print(F("<br><input name=\"p\" value=\""));
if(password_input!="")client.print(password_input);
client.print(F("\">\n"));
client.print(F("<input type=\"submit\" value=\"OK\">\n"));
client.print(F("</form>\n"));
//zmena hesla, zobrazi sa iba po spravnom hesle
if(password_correct || password == "")
{
client.print(F("<form type=\"get\">\n"));
client.print(F("Zmenit heslo na nove:\n"));
client.print(F("<input type=\"hidden\" name=\"p\" value=\""));
if(password_input!="")client.print(password_input);
client.print(F("\"><br><input name=\"changepass\">\n"));
client.print(F("<input type=\"submit\" value=\"OK\">\n"));
client.print(F("</form>\n"));
}
//nastavenie latencie
client.print(F("<form type=\"get\" target=\"car\">\n"));
client.print(F("Nastavit latenciu (dobu trvania prikazov) [ms]:\n"));
client.print(F("<input type=\"hidden\" name=\"p\" value=\""));
if(password_input!="")client.print(password_input);
client.print(F("\"><br><input name=\"lat\" value=\"1000\">\n"));
client.print(F("<input type=\"submit\" value=\"OK\">\n"));
client.print(F("</form>\n"));
//nastavenie ip a portu webkamery
client.print(F("<form type=\"get\">\n"));
client.print(F("Adresa webkamery [ip.ip.ip.ip:port]:\n"));
client.print(F("<input type=\"hidden\" name=\"p\" value=\""));
if(password_input!="")client.print(password_input);
client.print(F("\"><br>"));
const __FlashStringHelper* inputstyle = (F("<input style=\"width:30px;\" name=\"camadd"));
client.print(inputstyle);
client.print("0");
client.print(F("\" value=\""));
client.print(webcam_address[0]);
client.print(F("\">."));
client.print(inputstyle);
client.print("1");
client.print(F("\" value=\""));
client.print(webcam_address[1]);
client.print(F("\">."));
client.print(inputstyle);
client.print("2");
client.print(F("\" value=\""));
client.print(webcam_address[2]);
client.print(F("\">."));
client.print(inputstyle);
client.print("3");
client.print(F("\" value=\""));
client.print(webcam_address[3]);
client.print(F("\">:"));
client.print(inputstyle);
client.print("4");
client.print(F("\" value=\""));
client.print(webcam_address[4]);
client.print(F("\">."));
client.print(F("<input type=\"submit\" value=\"OK\">\n"));
client.print(F("</form><br>\n"));
client.print(F("<a href=\"http://www.sostrv.edu.sk/program_na_ovladanie_auta.zip\">Stiahnutie programu na ovladanie auta cez UDP</a>\n"));
if(webcam_show)
{
client.print(F("</center></td></tr></table>\n"));
}
}//koniec if show_index
client.print(F("</body></html>"));

client.stop();
}//koniec client
}

//Skúšanie, či nastal jeden z podporovaných príkazov na web serveri
void get_prikaz_vykonat()
{
//Vynimky, ktore sa zobrazuju v iframe = nezobrazovat pre nich index
if(cmd[0]=="cmd" || cmd[0]=="lat" || cmd[0]=="teplomer" || cmd[0]=="teplota" ||
cmd[0]=="autorefresh" || cmd[0]=="riadeniereset" || cmd[0]=="soniclimit" || cmd[0]=="webcam" ||
cmd[0]=="sonic" || cmd[0]=="bateria" || cmd[0]=="bateriasecret" || cmd[0]=="bateriaodpojenie")
{
show_index = false;
}

//Prikazy sa vykonaju iba ak bolo zadane heslo (ako prvy get prikaz) alebo ak ziadne nie je nastavene
if(password_correct || password == "")
{
if(cmd[0] == "cmd")
{
for(int cmd_i=0;cmd_i<cmd[1].length();cmd_i++)
{
ovladanie(cmd[1].charAt(cmd_i));
}

//obsah iframu
client.print(F("Prikaz = "));
client.print(cmd[1]);
}
else if(cmd[0] == "lat")
{
unsigned long lat=0;
for(int lat_i=cmd[1].length();lat_i>0;lat_i--)
{
lat+=(unsigned long)(cmd[1].charAt(cmd[1].length()-lat_i)-48)*my_pow(10,lat_i-1);
}

lat=lat/20;
motor_wait=lat;
riadenie_wait=lat;
trubenie_wait=lat;

//obsah iframu
client.print(F("Latencia [ms] = "));
client.print(lat*20);
}
else if(cmd[0] == "teplomer")
{
if(thermometer_found)
{
if(cmd[1]=="1" || cmd[1]=="true" || cmd[1]=="start" || cmd[1]=="zapnut")
{
thermometer_allowed = true;
client.print(F("Teplomer povoleny."));
}
else
{
thermometer_allowed = false;
client.print(F("Teplomer zakazany."));
}
}
else
{
if(ds.search(thermometer_addr))
{
thermometer_found = true;
client.print(F("Teplomer sa zapina."));
}
else
{
client.print(F("Teplomer nie je pripojeny."));
}
}
}
else if(cmd[0] == "teplota")
{
if(thermometer_found)
{
if(thermometer_allowed)
{
if(thermometer_celsius!=0.0)
{
client.print(F("Teplota je "));
client.print(thermometer_celsius);
client.print(F("&#176;C"));
}
else
{
client.print(F("Teplotu sa nepodarilo odmerat."));
}
}
else
{
client.print(F("Teplomer je zakazany."));
}
}
else
{
if(ds.search(thermometer_addr))
{
thermometer_found = true;
client.print(F("Teplomer sa zapina."));
}
else
{
client.print(F("Teplomer nie je pripojeny."));
}
}
}
else if(cmd[0] == "autorefresh")
{
if(cmd[1]=="1" || cmd[1]=="true")
{
html_autorefresh = true;
client.print(F("Autorefresh aktivovany."));
}
else
{
html_autorefresh = false;
client.print(F("Autorefresh deaktivovany."));
}
}
else if(cmd[0] == "riadeniereset")
{
if(cmd[1]=="1" || cmd[1]=="true")
{
riadenie_reset = true;
client.print(F("Vyrovnavanie kolies aktivovane."));
}
else
{
riadenie_reset = false;
client.print(F("Vyrovnavanie kolies deaktivovane."));
}
}
else if(cmd[0] == "c" || cmd[0] == "changepass" || cmd[0] == "changepassword")
{
if(password_correct || password == "")
{
password = cmd[1];
password_input = cmd[1];
}
}
else if(cmd[0] == "soniclimit")
{
const __FlashStringHelper* spomalovanieText1 = (F("Spomalovanie pri prekazke "));
const __FlashStringHelper* spomalovanieText2 = (F("aktivovane."));
if(cmd[1] == "0" || cmd[1] == "false")
{
motor_sonic_limit = false;
client.print(spomalovanieText1);
client.print(F("de"));
client.print(spomalovanieText2);
}
else
{
motor_sonic_limit = true;
client.print(spomalovanieText1);
client.print(spomalovanieText2);
}
}
else if(cmd[0] == "sonic")
{
client.print(F("Prekazka vpredu "));
if(sonic_meranie_dopredu==0&&sonic_meranie_dozadu==0)
{
client.print(F("aj vzadu prilis daleko."));
}
else
{
//vpredu
if(sonic_meranie_dopredu==0)
{
client.print(F("prilis daleko"));
}
else
{
client.print(sonic_meranie_dopredu);
client.print(F(" cm"));
}
//vzadu
client.print(F(", vzadu "));
if(sonic_meranie_dozadu==0)
{
client.print(F("prilis daleko."));
}
else
{
client.print(sonic_meranie_dozadu);
client.print(F(" cm."));
}
}
}
else if(cmd[0] == "bateria")
{
client.print(F("Stav baterie je "));
client.print(((float)(feedback_napajania-feedback_napajania_min)/(feedback_napajania_max-feedback_napajania_min))*100);
client.print(F("%."));
}
else if(cmd[0] == "bateriasecret")
{
client.print(F("Hodnota feedbacku baterie je "));
client.print(feedback_napajania);
client.print(F("."));
}
else if(cmd[0] == "bateriaodpojenie")
{
const __FlashStringHelper* bezpecnostText = (F("Bezpecnostne odpojenie baterie "));
if(cmd[1] == "0" || cmd[1] == "false")
{
feedback_napajania_DEACTIVATED = true;
digitalWrite(pin_vypnutie_napajania,0);
client.print(bezpecnostText);
client.print(F("DEAKTIVOVANE."));
}
else
{
feedback_napajania_DEACTIVATED = false;
client.print(bezpecnostText);
client.print(F("aktivovane."));
}
}
else if(cmd[0] == "webcam")
{
if(cmd[1] == "0" || cmd[1] == "false")
{
webcam_enabled=false;
client.print(F("Webkamera ODPOJENA."));
}
else
{
webcam_enabled=true;
client.print(F("Webkamera pripojena."));
}
}
}//koniec password_correct or no password
else if(cmd[0] == "p" || cmd[0] == "password" || cmd[0] == "pass")
{
password_input = cmd[1];
if(password_input==password)
{
password_correct = true;
}
}
else if(password_input == "" && show_index == false)
{
client.print(F("Nezadane heslo.<br>"));
}
else if(password_input != "" && show_index == false)
{
client.print(F("<font color=\"red\">Nespravne heslo!</font>"));
}

if(cmd[0] == "webcamshow")
{
show_index = true;
if(cmd[1]=="1" || cmd[1]=="true")
{
webcam_show = true;
}
else
{
webcam_show = false;
}
}
else if(cmd[0] == "camadd0")
{
show_index = true;
webcam_address[0] = cmd[1];
}
else if(cmd[0] == "camadd1")
{
show_index = true;
webcam_address[1] = cmd[1];
}
else if(cmd[0] == "camadd2")
{
show_index = true;
webcam_address[2] = cmd[1];
}
else if(cmd[0] == "camadd3")
{
show_index = true;
webcam_address[3] = cmd[1];
}
else if(cmd[0] == "camadd4")
{
show_index = true;
webcam_address[4] = cmd[1];
}
else if(cmd[0] == "index")
{
show_index = true;
}
}

//UDP server, pripojenie cez Processing klienta
void udp_server()
{
int packetsize = udp.parsePacket();
//Ak prisiel prikaz
if(packetsize)
{
password_correct = false; //heslo potrebne zadat pri kazdom pripojeni
password_input = "";

char packet[UDP_TX_PACKET_MAX_SIZE];
udp.read(packet,UDP_TX_PACKET_MAX_SIZE);

//Vykona kazdy prikaz v String objekte client_get
int get_cmd_index = 0;
boolean last_cmd = false;
while(!last_cmd)
{
if(!(get_cmd_index = get_cmd(packet,get_cmd_index)))
{
//Vykonat posledny prikaz
last_cmd = true;
}
//Vykonat vsetky UDP podporovany prikaz ak je spravne heslo
if(password_correct || password == "")
{
if(cmd[0] == "cmd")
{
for(int cmd_i=0;cmd_i<cmd[1].length();cmd_i++)
{
ovladanie(cmd[1].charAt(cmd_i));
}
}
else if(cmd[0] == "lat")
{
unsigned long lat=0;
for(int lat_i=cmd[1].length();lat_i>0;lat_i--)
{
lat+=(unsigned long)(cmd[1].charAt(cmd[1].length()-lat_i)-48)*my_pow(10,lat_i-1);
}

lat=lat/20;
motor_wait=lat;
riadenie_wait=lat;
trubenie_wait=lat;
}
else if(cmd[0] == "c" || cmd[0] == "changepass" || cmd[0] == "changepassword")
{
password = cmd[1];
password_input = cmd[1];
}
}//koniec password_correct or no password
else if(cmd[0] == "p" || cmd[0] == "password" || cmd[0] == "pass")
{
password_input = cmd[1];
if(password_input==password)
{
password_correct = true;
}
}//koniec vykonavania konkretneho UDP prikazu
}
}//koniec packetsize > 0
}

//Načítanie novej hodnoty zo sonického senzora
void sonic()
{
//Nacitat novu vzdialenost od prekazky - striedat medzi senzormi
if(sonic_smer==DOPREDU)
{
digitalWrite(pin_sonic_trigger_dopredu,0);
delayMicroseconds(2);
digitalWrite(pin_sonic_trigger_dopredu,1);
delayMicroseconds(10);
sonic_meranie_dopredu = pulseIn(pin_sonic_echo_dopredu,1,10000)/58.2; //využije cca. 10 ms behu programu
}
else if(sonic_smer==DOZADU)
{
digitalWrite(pin_sonic_trigger_dozadu,0);
delayMicroseconds(2);
digitalWrite(pin_sonic_trigger_dozadu,1);
delayMicroseconds(10);
sonic_meranie_dozadu = pulseIn(pin_sonic_echo_dozadu,1,10000)/58.2; //využije cca. 10 ms behu programu
}

//obratit smer pre nasledujuce meranie
if(sonic_smer==DOZADU)
{
sonic_smer=DOPREDU;
}
else
{
sonic_smer=DOZADU;
}
//motor potrebuje 2ms, 18ms ostava pre ostatne funkcie v loop_falling, okrem tejto funkcie cca. 8ms
}

//Hlavný loop po zbežnej hrane motora (funkcie môžu obsahovať delay spolu max. 18ms)
void loop_falling()
{
//Kontrola stavu baterie, poslat signal pre regulator
/*
feedback_napajania_history[4]=feedback_napajania_history[3];
feedback_napajania_history[3]=feedback_napajania_history[2];
feedback_napajania_history[2]=feedback_napajania_history[1];
feedback_napajania_history[1]=feedback_napajania_history[0];
feedback_napajania_history[0] = analogRead(pin_feedback_napajania);
//priemer z poslednych 5 stavov
feedback_napajania = (feedback_napajania_history[0]+feedback_napajania_history[1]+
feedback_napajania_history[2]+feedback_napajania_history[3]+
feedback_napajania_history[4]) / 5;
*/
feedback_napajania = analogRead(pin_feedback_napajania);
if(feedback_napajania_DEACTIVATED == false) //ak nie je funkcia deaktivovana
{
if(feedback_napajania < feedback_napajania_min)
{
feedback_napajania_i++;
if(feedback_napajania_i>feedback_napajania_i_max)
{
digitalWrite(pin_vypnutie_napajania,1);
}
}
/* Ak je potrebna aj vrchna hranica napatia
else if(feedback_napajania > feedback_napajania_max)
{
feedback_napajania_i++;
if(feedback_napajania_i>feedback_napajania_i_max)
{
digitalWrite(pin_vypnutie_napajania,1);
}
}
*/
else
{
feedback_napajania_i=0;
digitalWrite(pin_vypnutie_napajania,0);
}
}

//Nameranie novej hodnoty teplomera kazdych 1000 ms do premennej thermometer_celsius
if(thermometer_allowed && thermometer_found)
{
thermometer();
}

//Odmerat vzdialenost od prekazky sonickym senzorom
sonic();

//Skontrolovat ci niekto posiela novy prikaz a odpovedat klientom web servera
//- viac krat v kazdom cykle pre pripad ak by prislo vela prikazov naraz
web_server();
for(int i=0;i<3;i++)
{
udp_server();
}

if(trubenie)
{
digitalWrite(pin_trubenie,1);
//analogWrite(pin_trubenie,trubenie_freq);
}
else
{
digitalWrite(pin_trubenie,0);
//analogWrite(pin_trubenie,0);
}

if(webcam_enabled)
{
digitalWrite(pin_webcam,1);
}
else
{
digitalWrite(pin_webcam,0);
}

//Vykonat operacie s premennymi po kazdom cykle
pocitanie_servo();
}

Share

Komentárov   

0 #4 Duane 2020-07-15 02:52
I am sure this piece of writing has touched all the
internet viewers, its really really good piece of writing on building up new website.


My web page game of
thrones season 8: [censored]
Citovať
0 #3 Troy 2017-04-02 16:22
Heya i'm for the first time here. I came across this board
and I find It really useful & it helped me out a lot.

I hope to give something back and aid others like you aided
me.

my web-site - [censored]
Citovať
0 #2 lolatoys.com 2015-01-31 08:04
You are so awesome! I do not think I've read a single thing like this before.
So wonderful to find another person with a few original thoughts on this
issue. Really.. many thanks for starting this up.
This web site is one thing that's needed on the internet, someone with a little originality!
Citovať
0 #1 lolatoys.com 2014-11-28 13:38
Hi, I do believe this is an excellent web site. I stumbledupon it ;) I
am going to come back once again since i have saved as a favorite it.
Money and freedom is the best way to change, may you be rich and continue to help others.
Citovať

Pridať komentár


Bezpečnostný kód
Obnoviť