Kinova API Documentation
KINOVAAPIUSBCOMMANDLAYER_API int SendJoystickCommand ( JoystickCommand  joystickCommand)

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:
joystickCommandThe command that you need to send to the robotical arm.
#include <iostream>
#include <dlfcn.h> //Ubuntu
#include <vector>
#include "KinovaTypes.h"
//Note that under windows, you may/will have to perform other #include

using namespace std;

int main()
{
        int result;

        cout << "SendJoystickCommand function example" << endl;

        //Handle for the library's command layer.
        void * commandLayer_handle;

        //Function pointers to the functions we need
        int (*MyInitAPI)();
        int (*MyCloseAPI)();
        int (*MySendJoystickCommand)(JoystickCommand command);
        int (*MyStartControlAPI)();
        int (*MyMoveHome)();

        //We load the library (Under Windows, use the function LoadLibrary)
        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");
        MySendJoystickCommand = (int (*)(JoystickCommand)) dlsym(commandLayer_handle,"SendJoystickCommand");
        MyStartControlAPI = (int (*)()) dlsym(commandLayer_handle,"StartControlAPI");
        MyMoveHome = (int (*)()) dlsym(commandLayer_handle,"MoveHome");

        //If the was loaded correctly
        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)();

                //We prepare the virtual joystick command that will be sent to the robotic arm.
                JoystickCommand virtualCommand;

                //Initializing the command.
                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;
                //Every 1 ms we send a new virtual joystick command
                for(int i = 0; i < 400; i++)
                {
                        (*MySendJoystickCommand)(virtualCommand);

                        usleep(1000);
                }

                //Waiting 3 seconds
                cout << "The robotic arm will now move backward from where it comes." << endl;

                //we send the command backward
                virtualCommand.Rotate = -1;

                cout << "Sending the command backward to the robotic arm." << endl;
                //Every 1 ms we send a new virtual joystick command
                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;
}
 All Classes Files Functions Variables Enumerations Enumerator Defines