kni_wrapper_demo.cpp
Go to the documentation of this file.
1 /**********************************************************************************
2  * Katana Native Interface - A C++ interface to the robot arm Katana.
3  * Copyright (C) 2005-2008 Neuronics AG
4  * Check out the AUTHORS file for detailed contact information.
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  **********************************************************************************/
18 // kni_wrapper.cpp
19 // demo program for the kni C wrapper dll
20 // PKE/JHA/TPE 2008
22 #include "kniBase.h"
24 #include "kniBase.h"
25 #include <iostream>
26 #include <cstdio>
27 #include <memory>
29 //defines
30 #ifdef WIN32
31 # include <conio.h>
32 #else //LINUX
33 # include "keyboard.h"
34 #endif
35 //prototypes
37 void printInterface(std::string _interface);
39 //globals:
40 int enc[10], targetenc[10];
41 const int ENC_TOLERANCE = 10;
42 const int DEFAULT_ACCELERATION = 2;
43 const int DEFAULT_SPEED = 100;
44 const int POSITIONAL_OFFSET = 10000;
47 int main(int argc, char *argv[]) {
48  if (argc != 4) {
49  std::cout << "usage: kni_wrapper CONFIGFILE IP_ADDR CYCLES" << std::endl;
50  return 0;
51  }
52  int numberOfCycles = atoi(argv[3]);
53  try {
54  initKatana(argv[1], argv[2]);
55  calibrate(0);
56 
57  } catch(Exception &e) {
58  std::cout << "ERROR: " << e.message() << std::endl;
59  return -1;
60  }
61  std::cout << "-------------------------------------------" << std::endl;
62  std::cout << "success: katana initiated" << std::endl;
63  std::cout << "starting to call KNI interfaces" << std::endl;
64  std::cout << "interfaces in brackets[] are only being called implicitly" << std::endl;
65  std::cout << "-------------------------------------------" << std::endl;
67  try{
68  int value = 0;
69  for(int loops = 0; loops < numberOfCycles; loops++){
70  printInterface("IO_readInput(char output, int value)\n");
71  IO_readInput(1, value);
72  std::cout << "Read Input 1. Value: " << value << std::endl;
74  printInterface("[moveMot(int axis, int enc, int speed, int accel)],\n \
75  getEncoder(int axis),\n \
76  [waitForMot(int axis, int targetpos=0, int tolerance=0)]\n \
77  moveMotAndWait(int axis, int targetpos, int tolerance=0)\n");
78  for(int i = 1; i <= getNumberOfMotors(); i++){
79  getEncoder(i, value);
80  enc[i-1] = value;
81  if(enc[i-1] > 0){
82  targetenc[i-1] = enc[i-1] - POSITIONAL_OFFSET;
83  }
84  else{
85  targetenc[i-1] = enc[i-1] + POSITIONAL_OFFSET;
86  }
89  }
91  printInterface("[motorOff(int axis)],\n \
92  [motorOn(int axis)],\n \
93  allMotorsOff()\n \
94  allMotorsOn()\n");
95  allMotorsOff();
96  allMotorsOn();
97  calibrate(0);
99  printInterface("closeGripper(), openGripper()\n");
100  closeGripper();
101  openGripper();
103  printInterface("moveToPosEnc(int enc1, int enc2, int enc3, int enc4, int enc5, int enc6, int velocity, int acceleration, int tolerance)\n");
104  for(int i = 0; i < getNumberOfMotors(); i++){
105  std::cout << "startencoder: "<<enc[i]<<",\ttargetenc: "<<targetenc[i]<< std::endl;
106  }
110  printInterface("getPosition(struct TPos &pos), moveToPos(struct TPos pos)\n");
111 
112  current_position = (struct TPos*)malloc(sizeof(TPos));
113  target_position = (struct TPos*)malloc(sizeof(TPos));
114  getPosition(current_position);
115 
117  getPosition(target_position);
119  moveToPos(target_position,80, 1);
120  moveToPos(current_position,80, 1);
122  printInterface("moveToPosLin(struct TPos startPos, struct TPos targetPos)\n");
123  //moveToPos(target_position, 80, DEFAULT_ACCELERATION);
124  moveToPosEnc( 6355, -13513, -27931, 8500, 19832, 30420, DEFAULT_SPEED, DEFAULT_ACCELERATION, ENC_TOLERANCE, true);
125  TPos *tmpPos;
126  tmpPos = (struct TPos*)malloc(sizeof(TPos));
127  getPosition(tmpPos);
128  tmpPos->Y = tmpPos->Y - 160.0;
129  moveToPosLin(tmpPos, 100, DEFAULT_ACCELERATION);
130  tmpPos->X = tmpPos->X - 300.0;
131  moveToPosLin(tmpPos, 100, DEFAULT_ACCELERATION);
132  tmpPos->Z = tmpPos->Z + 150;
133  moveToPosLin(tmpPos, 100, DEFAULT_ACCELERATION);
134  moveToPos(current_position, 100, DEFAULT_ACCELERATION);
136  printInterface("IO_setOutput(char output, int value)\n");
137  IO_setOutput(0, 1);
139  printInterface("IO_readInput(char output, int value)\n");
140  IO_readInput(1, value);
141  std::cout << "Read Input 1. Value: " << value << std::endl;
143  }
144  }
145  catch(Exception &e) {
146  std::cout << "ERROR: " << e.message() << std::endl;
147  return -1;
148  }
149  return 0;
150 }
152 void printInterface(std::string _interface){
153  std::cout << "Calling interface: "<< _interface << std::endl;
154 }
156 
157 
158 
int targetenc[10]
TPos * target_position
moveMotAndWait
Definition: KNI.py:160
TPos * current_position
getPosition
Definition: KNI.py:152
allMotorsOn
Definition: KNI.py:142
std::string message() const
getEncoder
Definition: KNI.py:181
const int DEFAULT_SPEED
IO_setOutput
Definition: KNI.py:155
const int ENC_TOLERANCE
initKatana
Definition: KNI.py:154
const int POSITIONAL_OFFSET
extern C because we want to access these interfaces from anywhere:
Definition: kni_wrapper.h:49
double Z
Definition: kni_wrapper.h:51
IO_readInput
Definition: KNI.py:183
calibrate
Definition: KNI.py:143
moveToPos
Definition: KNI.py:161
moveToPosLin
Definition: KNI.py:163
const int DEFAULT_ACCELERATION
closeGripper
Definition: KNI.py:145
getNumberOfMotors
Definition: KNI.py:151
double X
The position in cartesian space.
Definition: kni_wrapper.h:51
int enc[10]
allMotorsOff
Definition: KNI.py:141
double Y
Definition: kni_wrapper.h:51
void printInterface(std::string _interface)
int main(int argc, char *argv[])
openGripper
Definition: KNI.py:164
moveToPosEnc
Definition: KNI.py:162


kni
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:16