-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
146 lines (113 loc) · 5.12 KB
/
main.cpp
File metadata and controls
146 lines (113 loc) · 5.12 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
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
#include <iostream>
#include <dlfcn.h>
#include <vector>
#include "Kinova.API.CommLayerUbuntu.h"
#include "Kinova.API.UsbCommandLayerUbuntu.h"
#include "KinovaTypes.h"
#include <stdio.h>
#include <unistd.h>
using namespace std;
int main()
{
int result;
CartesianPosition currentCommand;
//Handle for the library's command layer.
void * commandLayer_handle;
//Function pointers to the functions we need
int (*MyInitAPI)();
int (*MyCloseAPI)();
int (*MySendBasicTrajectory)(TrajectoryPoint command);
int (*MyGetDevices)(KinovaDevice devices[MAX_KINOVA_DEVICE], int &result);
int (*MySetActiveDevice)(KinovaDevice device);
int (*MyMoveHome)();
int (*MyInitFingers)();
int (*MyGetQuickStatus)(QuickStatus &);
int (*MyGetCartesianCommand)(CartesianPosition &);
//We load the library
commandLayer_handle = dlopen("Kinova.API.USBCommandLayerUbuntu.so",RTLD_NOW|RTLD_GLOBAL);
//We load the functions from the library (Under Windows, use GetProcAddress)
MyInitAPI = (int (*)()) dlsym(commandLayer_handle,"InitAPI");
MyCloseAPI = (int (*)()) dlsym(commandLayer_handle,"CloseAPI");
MyMoveHome = (int (*)()) dlsym(commandLayer_handle,"MoveHome");
MyInitFingers = (int (*)()) dlsym(commandLayer_handle,"InitFingers");
MyGetDevices = (int (*)(KinovaDevice devices[MAX_KINOVA_DEVICE], int &result)) dlsym(commandLayer_handle,"GetDevices");
MySetActiveDevice = (int (*)(KinovaDevice devices)) dlsym(commandLayer_handle,"SetActiveDevice");
MySendBasicTrajectory = (int (*)(TrajectoryPoint)) dlsym(commandLayer_handle,"SendBasicTrajectory");
MyGetQuickStatus = (int (*)(QuickStatus &)) dlsym(commandLayer_handle,"GetQuickStatus");
MyGetCartesianCommand = (int (*)(CartesianPosition &)) dlsym(commandLayer_handle,"GetCartesianCommand");
if((MyInitAPI == NULL) || (MyCloseAPI == NULL) ||
(MyGetQuickStatus == NULL) || (MySendBasicTrajectory == NULL) ||
(MySendBasicTrajectory == NULL) || (MyMoveHome == NULL) || (MyInitFingers == NULL) ||
(MyGetCartesianCommand == NULL))
{
cout << "* * * E R R O R D U R I N G I N I T I A L I Z A T I O N * * *" << endl;
}
else
{
cout << "I N I T I A L I Z A T I O N C O M P L E T E D" << endl << endl;
result = (*MyInitAPI)();
cout << "Initialization's result :" << result << endl;
KinovaDevice list[MAX_KINOVA_DEVICE];
int devicesCount = MyGetDevices(list, result);
for(int i = 0; i < devicesCount; i++)
{
cout << "Found a robot on the USB bus (" << list[i].SerialNumber << ")" << endl;
//Setting the current device as the active device.
MySetActiveDevice(list[i]);
cout << "Send the robot to HOME position" << endl;
MyMoveHome();
cout << "Initializing the fingers" << endl;
MyInitFingers();
TrajectoryPoint pointToSend;
pointToSend.InitStruct();
//We specify that this point will be used an angular(joint by joint) velocity vector.
pointToSend.Position.Type = CARTESIAN_VELOCITY;
pointToSend.Position.CartesianPosition.X = 0;
pointToSend.Position.CartesianPosition.Y = -0.15; //Move along Y axis at 20 cm per second
pointToSend.Position.CartesianPosition.Z = 0;
pointToSend.Position.CartesianPosition.ThetaX = 0;
pointToSend.Position.CartesianPosition.ThetaY = 0;
pointToSend.Position.CartesianPosition.ThetaZ = 0;
pointToSend.Position.Fingers.Finger1 = 0;
pointToSend.Position.Fingers.Finger2 = 0;
pointToSend.Position.Fingers.Finger3 = 0;
for(int i = 0; i < 200; i++)
{
//We send the velocity vector every 5 ms as long as we want the robot to move along that vector.
MySendBasicTrajectory(pointToSend);
usleep(5000);
}
pointToSend.Position.CartesianPosition.Y = 0;
pointToSend.Position.CartesianPosition.Z = 0.1;
for(int i = 0; i < 200; i++)
{
//We send the velocity vector every 5 ms as long as we want the robot to move along that vector.
MySendBasicTrajectory(pointToSend);
usleep(5000);
}
cout << "Send the robot to HOME position" << endl;
MyMoveHome();
//We specify that this point will be an angular(joint by joint) position.
pointToSend.Position.Type = CARTESIAN_POSITION;
//We get the actual angular command of the robot.
MyGetCartesianCommand(currentCommand);
pointToSend.Position.CartesianPosition.X = currentCommand.Coordinates.X;
pointToSend.Position.CartesianPosition.Y = currentCommand.Coordinates.Y - 0.1f;
pointToSend.Position.CartesianPosition.Z = currentCommand.Coordinates.Z;
pointToSend.Position.CartesianPosition.ThetaX = currentCommand.Coordinates.ThetaX;
pointToSend.Position.CartesianPosition.ThetaY = currentCommand.Coordinates.ThetaY;
pointToSend.Position.CartesianPosition.ThetaZ = currentCommand.Coordinates.ThetaZ;
cout << "*********************************" << endl;
cout << "Sending the first point to the robot." << endl;
MySendBasicTrajectory(pointToSend);
pointToSend.Position.CartesianPosition.Z = currentCommand.Coordinates.Z + 0.1f;
cout << "Sending the second point to the robot." << endl;
MySendBasicTrajectory(pointToSend);
cout << "*********************************" << endl << endl << endl;
}
cout << endl << "C L O S I N G A P I" << endl;
result = (*MyCloseAPI)();
}
dlclose(commandLayer_handle);
return 0;
}