-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9-3.cpp
More file actions
57 lines (45 loc) · 1.22 KB
/
9-3.cpp
File metadata and controls
57 lines (45 loc) · 1.22 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
#include <iostream>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h> // for atoi
#include <signal.h>
#include <rc/time.h>
#include <rc/adc.h>
#include <rc/dsm.h>
#include <rc/servo.h>
using namespace std ;
int main(int argc, char* [])
{
int ch = 1 ;
int status ;
status = rc_adc_init() ;
cout << "adc_init " << status << endl ;
status = rc_adc_batt() ;
cout << "adc batt " << status << endl ;
rc_adc_cleanup() ;
status = rc_servo_init() ;
cout << "servo init " << status << endl ;
rc_servo_power_rail_en(1) ; // power enable
// rc_servo_send_pulse_us(ch, 1300) ;
// rc_usleep(1000 * 1000) ;
// rc_servo_send_pulse_us(ch, 1500) ;
// rc_usleep(1000 * 1000) ;
// rc_servo_send_pulse_us(ch, 1800) ;
// rc_usleep(1000 * 1000) ;
int i = 1300 ;
int r = 1 ;
while (1) {
rc_servo_send_pulse_us(ch, i) ;
rc_usleep(1000 * 20) ;
cout << i << endl ;
i += r * 10 ;
if (i > 1800 || i < 1200) {
r *= -1 ;
}
}
// rc_servo_send_pulse_normalized(ch, 0.0) ;
// rc_usleep(1000 * 1000) ;
rc_servo_power_rail_en(0) ;
rc_servo_cleanup() ;
return 0 ;
}