This function sends a virtual joystick command to the robotical arm. the behaviour of the robotical arm is determined by the the control mapping associated with the API. (index 2) In the example, we assume that the robotical arm use the default mapping of the API and that it is in mode B0(Joystick translation). Assuming that, the robotical arm should move along the Z axis.
- Parameters:
-
| joystickCommand | The command that you need to send to the robotical arm. |
#include <iostream>
#include <dlfcn.h>
#include <vector>
#include "KinovaTypes.h"
using namespace std;
int main()
{
int result;
cout << "SendJoystickCommand function example" << endl;
void * commandLayer_handle;
int (*MyInitAPI)();
int (*MyCloseAPI)();
int (*MySendJoystickCommand)(JoystickCommand command);
int (*MyStartControlAPI)();
int (*MyMoveHome)();
commandLayer_handle = dlopen("Kinova.API.USBCommandLayerUbuntu.so",RTLD_NOW|RTLD_GLOBAL);
MyInitAPI = (int (*)()) dlsym(commandLayer_handle,"InitAPI");
MyCloseAPI = (int (*)()) dlsym(commandLayer_handle,"CloseAPI");
MySendJoystickCommand = (int (*)(JoystickCommand)) dlsym(commandLayer_handle,"SendJoystickCommand");
MyStartControlAPI = (int (*)()) dlsym(commandLayer_handle,"StartControlAPI");
MyMoveHome = (int (*)()) dlsym(commandLayer_handle,"MoveHome");
if((MyInitAPI == NULL) || (MyCloseAPI == NULL) || (MySendJoystickCommand == NULL) || (MyStartControlAPI == 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;
cout << "We take control of the robotic arm." << endl;
result = (*MyStartControlAPI)();
JoystickCommand virtualCommand;
for(int i = 0; i < JOYSTICK_BUTTON_COUNT; i++)
{
virtualCommand.ButtonValue[i] = 0;
}
virtualCommand.InclineForwardBackward = 0;
virtualCommand.InclineLeftRight = 0;
virtualCommand.MoveForwardBackward = 0;
virtualCommand.MoveLeftRight = 0;
virtualCommand.PushPull = 0;
virtualCommand.Rotate = 0;
virtualCommand.Rotate = 0;
(*MyMoveHome)();
(*MySendJoystickCommand)(virtualCommand);
virtualCommand.Rotate = 1;
cout << "Sending the command to the robotic arm." << endl;
for(int i = 0; i < 400; i++)
{
(*MySendJoystickCommand)(virtualCommand);
usleep(1000);
}
cout << "The robotic arm will now move backward from where it comes." << endl;
virtualCommand.Rotate = -1;
cout << "Sending the command backward to the robotic arm." << endl;
for(int i = 0; i < 400; i++)
{
(*MySendJoystickCommand)(virtualCommand);
usleep(1000);
}
virtualCommand.Rotate = 0;
(*MySendJoystickCommand)(virtualCommand);
cout << endl << "Calling the method CloseAPI()" << endl;
result = (*MyCloseAPI)();
cout << "result of CloseAPI() = " << result << endl;
}
return 0;
}