#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <QSerialPort>
#include <stdio.h>
#include <math.h>

#define BUFFMAX 1000

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    float delta_calcForward(float theta1, float theta2, float theta3);
    float delta_calcAngleYZ(float x0, float y0, float z0);

public slots:
    void update (void);

    void updates(void);

    void LeerPuerto(void);

    void automode(void);

private slots:
    void on_horizontalSlider_valueChanged(int value);

    void on_InitStop_clicked();

    void on_transmit_clicked();

    void on_transmitStop_clicked();

    void on_verticalSlider_valueChanged(int value);

    void on_verticalSlider_2_valueChanged(int value);

    void on_InitStop_2_clicked();

    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
    QTimer *_timer;
    QTimer *_timer2;    
    QTimer *_timer3;

    int _initbyte=0;
    int _servo;
    int _pos=90;
    int _pos2=90;
    int _pos3=90;
    char _posi;
    QSerialPort *_port;
    int _transmit=0;
    int counter = 1;
    int _objx;
    int _objy;
    int _signature;
    int _inicio;
    int _final;
    char _buffer[BUFFMAX];
    bool _ManualCam = false;

    // robot geometry
    // (look at pics above for explanation)
    const float e = 64;//115.0;     // end effector
    const float f = 220;//457.3;     // base
    const float re = 175;//232.0;
    const float rf = 50;//112.0;

    // trigonometric constants
    const float sqrt3 = sqrt(3.0);
    const float pi = 3.141592653;    // PI
    const float sin120 = sqrt3/2.0;
    const float cos120 = -0.5;
    const float tan60 = sqrt3;
    const float sin30 = 0.5;
    const float tan30 = 1/sqrt3;

    float theta1 = 10;
    float theta2 = 10;
    float theta3 = 10;

    float posX0 = 10;
    float posY0 = 10;
    float posZ0 = 10;

    //auto mode
    int _auto = 0;
    int _color = 0;
    int _estado = 0;
    int _posX;
    int _posY;
};

#endif // MAINWINDOW_H
