-
Notifications
You must be signed in to change notification settings - Fork 1
/
turn_demo.cpp
60 lines (47 loc) · 1.2 KB
/
turn_demo.cpp
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
#include <stdio.h>
#include <unistd.h>
#include "iqmotor.h"
void copyState();
#define MOTOR0_PORT "/dev/ttyUSB0"
#define MOTOR1_PORT "/dev/ttyUSB1"
#define UPDATE_RATE 50 // in ms
int main() {
struct iqMotor *motor0;
struct iqMotor *motor1;
/// setup console terminal prooperties
setup_console();
/// now setup motor controller terminal properties
motor0 = iqCreateMotor( MOTOR0_PORT );
if( motor0 == NULL )
return 1;
motor1 = iqCreateMotor( MOTOR1_PORT );
if( motor1 == NULL )
return 1;
iqSetCoast( motor0 ); // motor0 is the input, so put it in "coast"
printf( "Press enter to break.\n" );
while (1) {
double angle;
// kbhit code
if( kb_hit() )
break;
iqSetAngle(motor1, 0, 2000);
sleep(2);
iqSetAngle(motor1, 6.28, 2000); // radians: ~6.28 = 360 degrees
sleep(2);
iqSetAngle(motor1, 0, 2000);
sleep(2);
iqSetAngle(motor1, 6.28 * 2, 2000);
sleep(2);
iqSetAngle(motor1, 0, 2000);
sleep(2);
iqSetAngle(motor1, 6.28 * 3, 2000);
sleep(2);
iqSetAngle(motor1, 0, 2000);
sleep(2);
iqSetAngle(motor1, 6.28 * 10, 2000);
sleep(2);
iqSetAngle(motor1, 0, 2000);
sleep(2);
}
return 0;
}