mykni.cpp
Go to the documentation of this file.
00001 
00002 // mykni.cpp
00003 // demo program training 
00005 #include "kniBase.h"
00006 #include <iostream>
00007 #include <cstdio>
00008 #include <memory>
00009 #include <vector>
00010 #include <fstream>
00012 #ifdef WIN32
00013 #       include <conio.h>
00014 #else //LINUX
00015 #include "keyboard.h"
00016 #endif
00017 #define LEFT false
00018 #define RIGHT true
00019 
00020 //Katana structs:
00021 struct TPoint {
00022         double X, Y, Z;
00023         double phi, theta, psi;
00024 };
00025 struct TCurrentMot {
00026         int idx;
00027         bool running;
00028         bool dir;
00029 };
00030 struct Tpos{
00031         static std::vector<int> x,y,z,u,v,w;
00032         static const int xArr[], yArr[], zArr[], uArr[], vArr[], wArr[];
00033 };
00035 //Katana obj.
00036 std::auto_ptr<CLMBase> katana;
00037 int retVal = 0;
00038 const double PI = 3.14159265358979323846;
00040 int main(int argc, char *argv[]) {
00041         if (argc != 3) {
00042                 std::cout << "---------------------------------\n";
00043                 std::cout << "usage for socket connection: socketcontrol CONFIGFILE IP_ADDR\n";
00044                 std::cout << "---------------------------------\n";
00045                 return 0;
00046         }
00047         std::cout << "--------------------------\n";
00048         std::cout << "SOCKETCONTROL DEMO STARTED\n";
00049         std::cout << "--------------------------\n";
00050         std::auto_ptr<CCdlSocket> device;
00051         std::auto_ptr<CCplSerialCRC> protocol;
00052         try {
00053                 int port = 5566;
00054                 device.reset(new CCdlSocket(argv[2], port));
00055                 std::cout << "-------------------------------------------\n";
00056                 std::cout << "success:  port " << port << " open\n";
00057                 std::cout << "-------------------------------------------\n";
00058                 protocol.reset(new CCplSerialCRC());
00059                 std::cout << "-------------------------------------------\n";
00060                 std::cout << "success: protocol class instantiated\n";
00061                 std::cout << "-------------------------------------------\n";
00062                 protocol->init(device.get()); //fails if no response from Katana
00063                 std::cout << "-------------------------------------------\n";
00064                 std::cout << "success: communication with Katana initialized\n";
00065                 std::cout << "-------------------------------------------\n";
00066                 katana.reset(new CLMBase());
00067                 katana->create(argv[1], protocol.get());
00068         } catch(Exception &e) {
00069                 std::cout << "ERROR: " << e.message() << std::endl;
00070                 return -1;
00071         }
00072         std::cout << "-------------------------------------------\n";
00073         std::cout << "success: katana initialized\n";
00074         std::cout << "-------------------------------------------\n";
00075         std::vector<int> encoders(katana->getNumberOfMotors(), 0);
00076         TCurrentMot mot[6];
00077         for (int i = 0; i< 6; i++){
00078                 mot[i].running = false;
00079                 mot[i].idx = i;
00080                 mot[i].dir = true;
00081                 mot[i].dir = RIGHT;
00082         }
00083         //set linear velocity to 60
00084         try{
00085                 katana->setMaximumLinearVelocity(60);
00086                 katana->calibrate();
00087                 //....continue here
00088         }
00089         catch(...){
00090                 std::cout << "-------------------------------------------\n";
00091                 std::cout << "An exception occurred while communicating with the Katana.\n";
00092                 std::cout << "-------------------------------------------\n";
00093         }
00094         return 0;
00095 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


kni
Author(s): Neuronics AG (see AUTHORS.txt); ROS wrapper by Martin Günther
autogenerated on Tue May 28 2013 14:52:54