-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathESCdriver.cpp
More file actions
44 lines (37 loc) · 846 Bytes
/
Copy pathESCdriver.cpp
File metadata and controls
44 lines (37 loc) · 846 Bytes
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
#include "ESCdriver.h"
using namespace std;
//int run=1;
//int step[NUM_GPIO];
int E[5]={4,E1,E2,E3,E4};
int width[NUM_GPIO];
int used[NUM_GPIO];
//Initializing the 4 ESC's
void init ()
{
int g;
if (gpioInitialise() < 0) cout<<"GPIO Not Initialised\n"; //initalise the library at first
else
{
for (g=1; g<5; g++) { gpioServo(E[g], MIN_WIDTH); } //esc should be initalised with minmum value
}
usleep(20000);
}
//Changing The ESC Speed
//ESC : the ESC's Number
//speed : the ESC's percentage
void pwm (int ESC, double w)
{
w= (w*MIN_WIDTH/wmax)+MIN_WIDTH
int speed= int(w);
if(ESC<1 || ESC>4) cout<<"invalid ESC num\n";
else
{
gpioServo(E[ESC], speed);
}
}
//Stopping the 4 ESC's
void stop ()
{
int g;
for (g=1; g<5; g++) {gpioServo(E[g], MIN_WIDTH); } //forcing full stop
}