00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019
00020
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
00030 #ifdef WIN32
00031 # include <conio.h>
00032 #else //LINUX
00033 # include "keyboard.h"
00034 #endif
00035
00036
00037 void printInterface(std::string _interface);
00039
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
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