-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
179 lines (158 loc) · 5.57 KB
/
test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include "iklib.h"
#include <chrono>
using namespace std;
using namespace chrono;
#define PX_MAX 2
#define PX_MIN -2
#define PY_MAX 2
#define PY_MIN -2
#define PZ_MAX 2
#define PZ_MIN 0
#define ROLL_MAX PI
#define ROLL_MIN -PI
#define PITCH_MAX PI
#define PITCH_MIN -PI
#define YAW_MAX PI
#define YAW_MIN -PI
void print_vector3(char *name, v3_t *v)
{
int i;
printf("%-11s = [", name);
printf("%16.8lf, ", v->v0);
printf("%16.8lf, ", v->v1);
printf("%16.8lf]\n", v->v2);
}
int main(void)
{
ik_state_t ik_state;
ik_input_t ik_input;
char menu;
int sign, rand_temp, i;
type_t temp;
system_clock::time_point start;
system_clock::time_point end;
nanoseconds nanosec;
clock_t start_clk, end_clk;
srand((unsigned)time(NULL));
for (;;)
{
printf("0: test_values, 1:manual, 2: exit, others:rand with URDF > ");
scanf("%c", &menu);
getchar();
if (menu == '0')
{
ik_input.target_pos.v0 = 0.49792;
ik_input.target_pos.v1 = 1.3673;
ik_input.target_pos.v2 = 2.4988;
ik_input.mkdh_rpy.v0 = 0;
ik_input.mkdh_rpy.v1 = -PI / 2;
ik_input.mkdh_rpy.v2 = PI;
ik_input.target_rpy.v0 = 0.366;
ik_input.target_rpy.v1 = -0.078;
ik_input.target_rpy.v2 = 2.561;
}
else if (menu == '1')
{
printf("target position (px py pz) : ");
scanf("%lf %lf %lf", &ik_input.target_pos.v0, &ik_input.target_pos.v1, &ik_input.target_pos.v2);
getchar();
printf("target rpy (roll pitch yaw) : ");
scanf("%lf %lf %lf", &ik_input.target_pos.v0, &ik_input.target_pos.v1, &ik_input.target_pos.v2);
getchar();
printf("1:URDF, others:others > ");
menu = ' ';
scanf("%c", &menu);
getchar();
if (menu == '1')
{
// URDF(ROS)->DH frame(Cur System)
ik_input.mkdh_rpy.v0 = 0;
ik_input.mkdh_rpy.v1 = -PI / 2;
ik_input.mkdh_rpy.v2 = PI;
}
else
{
printf("mkdh_rpy (mkdh_roll mkdh_pitch mkdh_yaw) : ");
scanf("%lf %lf %lf", &ik_input.mkdh_rpy.v0, &ik_input.mkdh_rpy.v1, &ik_input.mkdh_rpy.v2);
getchar();
}
}
else if (menu == '2')
{
printf("Exit\n");
break;
}
else
{
ik_input.mkdh_rpy.v0 = 0;
ik_input.mkdh_rpy.v1 = -PI / 2;
ik_input.mkdh_rpy.v2 = PI;
rand_temp = rand();
temp = (rand_temp / (type_t)RAND_MAX) * (type_t)((PX_MAX - PX_MIN) / 2);
rand_temp = rand();
sign = pow(-1, rand_temp);
ik_input.target_pos.v0 = (PX_MAX + PX_MIN) / 2.0 + temp * sign;
rand_temp = rand();
temp = (rand_temp / (type_t)RAND_MAX) * (type_t)((PY_MAX - PY_MIN) / 2);
rand_temp = rand();
sign = pow(-1, rand_temp);
ik_input.target_pos.v1 = (PY_MAX + PY_MIN) / 2.0 + temp * sign;
rand_temp = rand();
temp = (rand_temp / (type_t)RAND_MAX) * (type_t)((PZ_MAX - PZ_MIN) / 2);
rand_temp = rand();
sign = pow(-1, rand_temp);
ik_input.target_pos.v2 = (PZ_MAX + PZ_MIN) / 2.0 + temp * sign;
rand_temp = rand();
temp = (rand_temp / (type_t)RAND_MAX) * (type_t)((ROLL_MAX - ROLL_MIN) / 2);
rand_temp = rand();
sign = pow(-1, rand_temp);
ik_input.target_rpy.v0 = (ROLL_MAX + ROLL_MIN) / 2.0 + temp * sign;
rand_temp = rand();
temp = (rand_temp / (type_t)RAND_MAX) * (type_t)((PITCH_MAX - PITCH_MIN) / 2);
rand_temp = rand();
sign = pow(-1, rand_temp);
ik_input.target_rpy.v0 = (PITCH_MAX + PITCH_MIN) / 2.0 + temp * sign;
rand_temp = rand();
temp = (rand_temp / (type_t)RAND_MAX) * (type_t)((YAW_MAX - YAW_MIN) / 2);
rand_temp = rand();
sign = pow(-1, rand_temp);
ik_input.target_rpy.v0 = (YAW_MAX + YAW_MIN) / 2.0 + temp * sign;
}
printf("\n<input>\n");
print_vector3((char *)"target_pos", &ik_input.target_pos);
print_vector3((char *)"target_rpy", &ik_input.target_rpy);
print_vector3((char *)"mkdh_rpy", &ik_input.mkdh_rpy);
init_ik_lib(&ik_state, &ik_input);
printf("\n<output>\n");
get_6joint_angles(&ik_state);
printf("free var qi = [");
for (i = 1; i < 6; i++)
{
printf("%16.8lf, ", get_q(i));
}
printf("%16.8lf]\n", get_q(i));
printf("joint angle = [");
for (i = 1; i < 6; i++)
{
printf("%16.8lf, ", get_theta(i));
}
printf("%16.8lf]\n", get_q(i));
printf("\n");
// for accurate measurement
start = system_clock::now();
get_6joint_angles(&ik_state);
end = system_clock::now();
// for accurate measurement
start_clk = clock();
get_6joint_angles(&ik_state);
end_clk = clock();
nanosec = end - start;
printf("<elapsed time>\n%lf ms\n", nanosec.count() / 1000000.0);
printf("%lu clocks\n", end_clk - start_clk);
printf("\n\n");
}
}