-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
129 lines (119 loc) · 2.81 KB
/
Copy pathmain.cpp
File metadata and controls
129 lines (119 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//============================================================================
// Name : Quad.cpp
// Author : Amr Mohammed Kamal
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
// using 9 buttons the quad will move foreward backward right left , up and down
// eac resolution is 20 Cm , also roll pitch yaw with 10 degree resoultion
//https://github.com/metachris/RPIO/tree/master/source/c_pwm
//the fork() Function. The fork() function is used to create a new process by duplicating the existing process
//from which it is called. The existing process from which this function is called
//becomes the parent process and the newly created process becomes the child process
//============================================================================
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pigpio.h>
#include <sched.h>
#include "control_v2.h"
#include "sensing.h"
#include "ESCdriver.h"
//http://abyz.co.uk/rpi/pigpio/cif.html
//http://arma.sourceforge.net/docs.html
//http://eigen.tuxfamily.org/index.php?title=Main_Page
//http://www.simunova.com/node/33
int airborn=0;
int ison=0;
using namespace std;
int main(){
int volatile button=42;
init();
fstream reader("/var/www/html/text.txt");
//flag to readings.txt called ofile
fstream ofile;
//open readings.tx/var/www/html/text.txtt
string line;
while (1){
ofile.open("/home/pi/Desktop/webips.txt", ios::in );
//read data from file readings.txt
getline(ofile, line) ;
button=atoi(line.c_str());
//close file
ofile.close();
//open file again and clear its previos contents
ofile.open("/home/pi/Desktop/webips.txt", ios::out|ios::trunc);
//write data to the file
ofile << "42";
//close the file
ofile.close();
switch (button){
// get button from php to call this code and execute the function
case 1 :
standard_forward();
usleep(760000); //sleeping for the time needed to travel 0.5 meter
hover_q();
break;
case 2 :
standard_left();
usleep(760000);
hover_q();
break;
case 3 :
standard_right();
usleep(760000);
hover_q();
break;
case 4 :
standard_backward();
usleep(760000);
hover_q();
break;
case 5 :
standard_yaw();
break;
case 6 :
standard_up();
usleep(76000);
hover_q();
break;
case 7 :
standard_down();
usleep(76000);
hover_q();
break;
case 8 :
u1offest++;
hover_q();
usleep(10000); //overwrting protection remaining the control loop at frequency
break;
case 9 :
u1offest--;
hover_q();
usleep(10000);
break;
/*case 10 :
//changing range
global_pwmhov=(get_pwmR()*global_pwmhov)/100;
set_motorSettings(100);
break; */
/*case 11 :
break; */
/*case 12 :
break; */
case 13:
hover_q();
usleep(760000);
case 14:
stop();
break;
case 42:
break;
}
}
return 0;
}