This function get the position and the current of all actuators.
#include <iostream>
#include <dlfcn.h>
#include <vector>
#include "KinovaTypes.h"
using namespace std;
int main()
{
int result;
cout << "GetPositionCurrentActuators function example" << endl;
void * commandLayer_handle;
int (*MyInitAPI)();
int (*MyCloseAPI)();
int (*MyGetPositionCurrentActuators)(std::vector<float> &data);
commandLayer_handle = dlopen("Kinova.API.USBCommandLayerUbuntu.so",RTLD_NOW|RTLD_GLOBAL);
MyInitAPI = (int (*)()) dlsym(commandLayer_handle,"InitAPI");
MyCloseAPI = (int (*)()) dlsym(commandLayer_handle,"CloseAPI");
MyGetPositionCurrentActuators = (int (*)(std::vector<float> &)) dlsym(commandLayer_handle,"GetPositionCurrentActuators");
if((MyInitAPI == NULL) || (MyCloseAPI == NULL) || (MyGetPositionCurrentActuators == NULL))
{
cout << "Unable to initialize the command layer." << endl;
}
else
{
cout << "The command has been initialized correctly." << endl << endl;
cout << "Calling the method InitAPI()" << endl;
result = (*MyInitAPI)();
cout << "result of InitAPI() = " << result << endl << endl;
std::vector<float> data;
(*MyGetPositionCurrentActuators)(data);
if(data.size() >= 12)
{
cout << "Actuator 1's position : " << data[0] << endl;
cout << "Actuator 2's position : " << data[1] << endl;
cout << "Actuator 3's position : " << data[2] << endl;
cout << "Actuator 4's position : " << data[3] << endl;
cout << "Actuator 5's position : " << data[4] << endl;
cout << "Actuator 6's position : " << data[5] << endl;
cout << "Actuator 1's current : " << data[6] << endl;
cout << "Actuator 2's current : " << data[7] << endl;
cout << "Actuator 3's current : " << data[8] << endl;
cout << "Actuator 4's current : " << data[9] << endl;
cout << "Actuator 5's current : " << data[10] << endl;
cout << "Actuator 6's current : " << data[11] << endl;
}
else
{
cout << "Missing some actuators or communication error.";
}
cout << endl << "Calling the method CloseAPI()" << endl;
result = (*MyCloseAPI)();
cout << "result of CloseAPI() = " << result << endl;
}
return 0;
}