fs100_cmd.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * C++ class for continous trajectory point streaming using FS100 controller mh5l robot
00004  * Author: Asger Winther-Jørgensen (awijor@elektro.dtu.dk)
00005  *
00006  * Software License Agreement (LGPL License)
00007  *
00008  *  Copyright (c) 2014, Technical University of Denmark
00009  *  All rights reserved.
00010  
00011  *  This program is free software; you can redistribute it and/or modify  
00012  *  it under the terms of the GNU Lesser General Public License as        
00013  *  published by the Free Software Foundation; either version 2 of the    
00014  *  License, or (at your option) any later version.                       
00015  *                                                                        
00016  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00017  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00018  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00019  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00020  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00022  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00024  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00026  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  *  POSSIBILITY OF SUCH DAMAGE.
00028  *********************************************************************/
00029 #ifndef FS100CMD_H
00030 #define FS100CMD_H
00031 
00032 
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <unistd.h> //for time
00036 #include <time.h>
00037 #include <string.h>
00038 #include <sys/types.h>
00039 #include <sys/socket.h>
00040 #include <netinet/in.h>
00041 #include <netinet/ip.h>
00042 #include <netinet/tcp.h>
00043 #include <netdb.h> 
00044 #include <queue>
00045 #include <pthread.h>
00046 
00047 #include "motoman_direct_message.h"
00049 
00052 typedef struct{
00053         float pos[6]; 
00054         float vel[6];
00055         float time;
00056 }cmd;
00057 
00059 
00062 class Fs100Cmd{
00063 private:
00064     //private variables and functions
00065     const char* IP;
00066     int sockfd, portno, n, i,run_thread;
00067     volatile int seq;
00068     unsigned int thread_sleep;
00069     float abs_time;
00070     volatile bool stop_all;
00071 
00072     
00073     
00074     struct sockaddr_in serv_addr;
00075     struct hostent *server;
00076     pthread_t cmdthreadID;
00077     SimpleMsg joint_data,motion_rpl; //deserialized data in human readable format
00078     char raw_data[255]; 
00079     char traj_buffer[152];
00080     char motion_reply_buffer[76];
00081     static void *cmdPushThread(void *This);
00082     std::queue<cmd> cmdList;
00083     
00084     
00085     void cmdPush();
00086     void socketError(const char *msg);
00087     void byteSwap(char* data,int length);
00088     void serialize(SimpleMsg *msg, char *data,int size);
00089     void deserializeMotionReply(char *data,SimpleMsg *msg);
00090     int buildTrajPos(SimpleMsg *tm,float pos[6],float time,int seq);
00091     int buildTrajFull(SimpleMsg *tm,float pos[6],float vel[6],float time,int seq);
00092     void motionReady(SimpleMsg *msg);
00093     void trajectoryStart(SimpleMsg *msg);
00094     void trajectoryStop(SimpleMsg *msg);
00095     void printErrorCodeMsg(SimpleMsg *msg);
00096     void printMotionReply(SimpleMsg *msg);
00097     void printTrajFull(SimpleMsg *msg);
00098     int getLength(char* data);
00099     
00100     
00101 
00102 public:
00103     //public variables and functions
00105 
00108     Fs100Cmd(const char* ip){
00109     IP = ip;
00110     portno = 50240;
00111     i = 1;
00112     pthread_mutex_t mut_lock = PTHREAD_MUTEX_INITIALIZER;
00113     }
00115 
00118     int init();
00119     
00121 
00124     int makeConnect();
00125     
00127 
00131     int start(int retry);
00132 
00133     
00135 
00139     bool resetTrajectory(int *retry);
00140     
00142 
00149     bool pushTraj(float pos[6],float vel[6],float time,int seq);
00151 
00156     bool addCmdToQueue(cmd cmd_point);
00158 
00164     bool addPointToQueue(float pos[6],float vel[6],float time);
00165     
00167 
00170     void pgmClose();
00171 };
00172 
00173 
00174 
00175 #endif //FS100CMD


fs100_motoman
Author(s): Asger Winther-Jørgensen (Technical Univeristy of Denmark)
autogenerated on Fri Aug 28 2015 10:42:16