-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesc.cpp
More file actions
60 lines (52 loc) · 1.15 KB
/
esc.cpp
File metadata and controls
60 lines (52 loc) · 1.15 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
#include <Arduino.h>
#include <Servo.h>
#include "config.h"
#include "main.h"
Servo esc;
/************************************
* Name : init_esc
* Purpuse : Init ESC
* Inputs : None
* Outputs : None
* Returns : None
************************************/
void init_esc()
{
esc.attach(PWM_PIN);
esc.writeMicroseconds(ESC_OFF);
}
/************************************
* Name : stop_esc
* Purpuse : stop ESC
* Inputs : None
* Outputs : None
* Returns : None
************************************/
void stop_esc()
{
esc.writeMicroseconds(ESC_OFF);
}
/************************************
* Name : set_esc
* Purpuse : Set esc value
* Inputs : val - in persentage (0..100)
* Outputs : None
* Returns : Written value in MS, or -1 if invald value given.
************************************/
int set_esc(float val)
{
if ((val < 0) && (val > 100))
{
ASSERT(false, "set_esc: val out of range");
return -1;
}
int valms = ESC_MIN + val*(ESC_MAX-ESC_MIN)/100;
/*
Serial.print("set_esc - ");
Serial.print(val);
Serial.print(" - ");
Serial.println(valms);
*/
esc.writeMicroseconds(valms);
return valms;
}