-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-2.cpp
More file actions
45 lines (35 loc) · 880 Bytes
/
11-2.cpp
File metadata and controls
45 lines (35 loc) · 880 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
45
#include <iostream>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <rc/time.h>
#include <rc/encoder.h>
#include <rc/motor.h>
using namespace std ;
int main(int argc, char* [])
{
int ch_encoder = 2 ;
int ch_motor = 1 ;
int pos = 0 ;
int status ;
double speed = 0.0 ;
status = rc_encoder_init() ;
cout << status << endl ;
if (status < 0) return -1 ;
status = rc_motor_init() ;
cout << status << endl ;
if (status < 0) return -1 ;
rc_encoder_write(ch_encoder, pos) ;
cout << "input speed : " ;
cin >> speed ;
rc_motor_set(ch_motor, speed) ;
while (1) {
pos = rc_encoder_read(ch_encoder) ;
printf("\r%5d", pos) ;
fflush(stdout) ;
rc_usleep(1000 * 100) ;
}
rc_encoder_cleanup() ;
rc_motor_cleanup() ;
return 0 ;
}