kni_wrapper_demo.cpp
Go to the documentation of this file.
00001 /**********************************************************************************
00002  *   Katana Native Interface - A C++ interface to the robot arm Katana.
00003  *   Copyright (C) 2005-2008 Neuronics AG
00004  *   Check out the AUTHORS file for detailed contact information.
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *   You should have received a copy of the GNU General Public License
00014  *   along with this program; if not, write to the Free Software
00015  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016  **********************************************************************************/
00018 // kni_wrapper.cpp
00019 // demo program for the kni C wrapper dll       
00020 // PKE/JHA/TPE 2008
00022 #include "kniBase.h"
00023 #include "kni_wrapper/kni_wrapper.h"
00024 #include "kniBase.h"
00025 #include <iostream>
00026 #include <cstdio>
00027 #include <memory>
00029 //defines
00030 #ifdef WIN32
00031 #       include <conio.h>
00032 #else //LINUX
00033 #       include "keyboard.h"
00034 #endif
00035 
00036 //prototypes
00037 void printInterface(std::string _interface);
00039 //globals:
00040 int enc[10], targetenc[10];
00041 const int ENC_TOLERANCE = 10;
00042 const int DEFAULT_ACCELERATION = 2;
00043 const int DEFAULT_SPEED = 100;
00044 const int POSITIONAL_OFFSET = 10000;
00045 TPos *current_position, *target_position;
00047 int main(int argc, char *argv[]) {
00048         if (argc != 4) {
00049                 std::cout << "usage: kni_wrapper CONFIGFILE IP_ADDR CYCLES" << std::endl;
00050                 return 0;
00051         }
00052         int numberOfCycles = atoi(argv[3]);
00053         try {
00054                 initKatana(argv[1], argv[2]);
00055                 calibrate(0);
00056 
00057         } catch(Exception &e) {
00058                 std::cout << "ERROR: " << e.message() << std::endl;
00059                 return -1;
00060         }
00061         std::cout << "-------------------------------------------" << std::endl;
00062         std::cout << "success: katana initiated" << std::endl;
00063         std::cout << "starting to call KNI interfaces" << std::endl;
00064         std::cout << "interfaces in brackets[] are only being called implicitly" << std::endl;
00065         std::cout << "-------------------------------------------" << std::endl;
00067         try{
00068                 int value = 0;
00069                 for(int loops = 0; loops < numberOfCycles; loops++){
00070                         printInterface("IO_readInput(char output, int value)\n");
00071                         IO_readInput(1, value);
00072                         std::cout << "Read Input 1. Value: " << value << std::endl;
00074                         printInterface("[moveMot(int axis, int enc, int speed, int accel)],\n \
00075                                         getEncoder(int axis),\n \
00076                                         [waitForMot(int axis, int targetpos=0, int tolerance=0)]\n \
00077                                         moveMotAndWait(int axis, int targetpos, int tolerance=0)\n");
00078                         for(int i = 1; i <= getNumberOfMotors(); i++){
00079                                 getEncoder(i, value);
00080                                 enc[i-1] = value;
00081                                 if(enc[i-1] > 0){
00082                                         targetenc[i-1] = enc[i-1] - POSITIONAL_OFFSET;
00083                                 }
00084                                 else{
00085                                         targetenc[i-1] = enc[i-1] + POSITIONAL_OFFSET;
00086                                 }
00087                                 moveMotAndWait(i, targetenc[i-1], ENC_TOLERANCE);
00088                                 moveMotAndWait(i, enc[i-1], ENC_TOLERANCE);
00089                         } 
00091                         printInterface("[motorOff(int axis)],\n \
00092                                         [motorOn(int axis)],\n \
00093                                         allMotorsOff()\n \
00094                                         allMotorsOn()\n");
00095                         allMotorsOff();
00096                         allMotorsOn();
00097                         calibrate(0);
00099                         printInterface("closeGripper(), openGripper()\n");
00100                         closeGripper();
00101                         openGripper();
00103                         printInterface("moveToPosEnc(int enc1, int enc2, int enc3, int enc4, int enc5, int enc6, int velocity, int acceleration, int tolerance)\n");
00104                         for(int i = 0; i < getNumberOfMotors(); i++){
00105                                 std::cout << "startencoder: "<<enc[i]<<",\ttargetenc: "<<targetenc[i]<< std::endl;
00106                         }
00107                         moveToPosEnc(targetenc[0],  targetenc[1],  targetenc[2],  targetenc[3],  targetenc[4], targetenc[5], DEFAULT_SPEED, DEFAULT_ACCELERATION, ENC_TOLERANCE, true);
00108                         moveToPosEnc(enc[0],  enc[1],  enc[2],  enc[3],  enc[4], enc[5], DEFAULT_SPEED, DEFAULT_ACCELERATION, ENC_TOLERANCE, true);
00110                         printInterface("getPosition(struct TPos &pos), moveToPos(struct TPos pos)\n");
00111 
00112                         current_position = (struct TPos*)malloc(sizeof(TPos));
00113                         target_position = (struct TPos*)malloc(sizeof(TPos));
00114                         getPosition(current_position);
00115 
00116                         moveToPosEnc(targetenc[0],  targetenc[1],  targetenc[2],  targetenc[3],  targetenc[4], targetenc[5], DEFAULT_SPEED, DEFAULT_ACCELERATION, ENC_TOLERANCE, true);
00117                         getPosition(target_position);
00118                         moveToPosEnc(enc[0],  enc[1],  enc[2],  enc[3],  enc[4], enc[5], DEFAULT_SPEED, DEFAULT_ACCELERATION, ENC_TOLERANCE, true);
00119                         moveToPos(target_position,80, 1);
00120                         moveToPos(current_position,80, 1);
00122                         printInterface("moveToPosLin(struct TPos startPos, struct TPos targetPos)\n");
00123                         //moveToPos(target_position, 80, DEFAULT_ACCELERATION);
00124                         moveToPosEnc( 6355, -13513, -27931, 8500, 19832, 30420, DEFAULT_SPEED, DEFAULT_ACCELERATION, ENC_TOLERANCE, true);
00125                         TPos *tmpPos;
00126                         tmpPos = (struct TPos*)malloc(sizeof(TPos));
00127                         getPosition(tmpPos);
00128                         tmpPos->Y = tmpPos->Y - 160.0;
00129                         moveToPosLin(tmpPos, 100, DEFAULT_ACCELERATION);
00130                         tmpPos->X = tmpPos->X - 300.0;
00131                         moveToPosLin(tmpPos, 100, DEFAULT_ACCELERATION);
00132                         tmpPos->Z = tmpPos->Z + 150;
00133                         moveToPosLin(tmpPos, 100, DEFAULT_ACCELERATION);
00134                         moveToPos(current_position, 100, DEFAULT_ACCELERATION);
00136                         printInterface("IO_setOutput(char output, int value)\n");
00137                         IO_setOutput(0, 1);
00139                         printInterface("IO_readInput(char output, int value)\n");
00140                         IO_readInput(1, value);
00141                         std::cout << "Read Input 1. Value: " << value << std::endl;
00143                 }
00144         }
00145         catch(Exception &e) {
00146                 std::cout << "ERROR: " << e.message() << std::endl;
00147                 return -1;
00148         }
00149         return 0;
00150 }
00152 void printInterface(std::string _interface){
00153         std::cout << "Calling interface: "<< _interface << std::endl;
00154 }
00156 
00157 
00158 


kni
Author(s): Martin Günther
autogenerated on Thu Aug 27 2015 13:40:07