From 73310d73a84b93fd6d6551d759cf53b4066c4740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20Hern=C3=A1ndez?= <shernand@iri.upc.edu> Date: Sun, 22 Jun 2014 10:19:09 +0000 Subject: [PATCH] Removed some files no longer necessary. They have been moved to a new fodler. --- src/bin/CMakeLists.txt | 7 -- src/bin/bin_file_parser.cpp | 79 -------------- src/bin/bin_file_parser.h | 55 ---------- src/mtn/CMakeLists.txt | 34 ------ src/mtn/mtn_file.l | 37 ------- src/mtn/mtn_file.y | 157 ---------------------------- src/mtn/mtn_file_parser.cpp | 92 ----------------- src/mtn/mtn_file_parser.hpp | 33 ------ src/mtn/mtn_file_scanner.hpp | 35 ------- src/parser/CMakeLists.txt | 33 ------ src/parser/mtn_file.cpp | 154 --------------------------- src/parser/mtn_file.h | 36 ------- src/parser/mtn_file.l | 37 ------- src/parser/mtn_file.y | 157 ---------------------------- src/parser/mtn_file_parser.cpp | 92 ----------------- src/parser/mtn_file_parser.hpp | 31 ------ src/parser/mtn_file_scanner.hpp | 35 ------- src/parser/mtn_page.cpp | 178 -------------------------------- src/parser/mtn_page.h | 42 -------- src/parser/mtn_step.cpp | 86 --------------- src/parser/mtn_step.h | 25 ----- 21 files changed, 1435 deletions(-) delete mode 100644 src/bin/CMakeLists.txt delete mode 100644 src/bin/bin_file_parser.cpp delete mode 100644 src/bin/bin_file_parser.h delete mode 100644 src/mtn/CMakeLists.txt delete mode 100644 src/mtn/mtn_file.l delete mode 100644 src/mtn/mtn_file.y delete mode 100644 src/mtn/mtn_file_parser.cpp delete mode 100644 src/mtn/mtn_file_parser.hpp delete mode 100644 src/mtn/mtn_file_scanner.hpp delete mode 100644 src/parser/CMakeLists.txt delete mode 100644 src/parser/mtn_file.cpp delete mode 100644 src/parser/mtn_file.h delete mode 100644 src/parser/mtn_file.l delete mode 100644 src/parser/mtn_file.y delete mode 100644 src/parser/mtn_file_parser.cpp delete mode 100644 src/parser/mtn_file_parser.hpp delete mode 100644 src/parser/mtn_file_scanner.hpp delete mode 100644 src/parser/mtn_page.cpp delete mode 100644 src/parser/mtn_page.h delete mode 100644 src/parser/mtn_step.cpp delete mode 100644 src/parser/mtn_step.h diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt deleted file mode 100644 index 6cee083..0000000 --- a/src/bin/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -SET(bin_SRCS bin_file_parser.cpp ../mtn_file.cpp ../mtn_page.cpp ../mtn_step.cpp) - -include_directories(.) -include_directories(../) - -add_library(bin_parser SHARED ${bin_SRCS}) - diff --git a/src/bin/bin_file_parser.cpp b/src/bin/bin_file_parser.cpp deleted file mode 100644 index 392de6d..0000000 --- a/src/bin/bin_file_parser.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "bin_file_parser.h" -#include <fstream> -#include <string.h> -#include <iostream> -#include <stdlib.h> - -CBinFileParser::CBinFileParser() -{ - memset(this->pages,0x00,sizeof(this->pages)); -} - -void CBinFileParser::parse(const char *filename) -{ - std::vector<unsigned short int> angles; - std::string motion_type="motion",name; - std::vector<unsigned int> compliance; - std::ifstream in_file(filename); - int length=0,i=0,j=0,k=0; - CMtnPage *page; - CMtnStep *step; - - if(!in_file.good()) - { - std::cout << " File << " << filename << " not found" << std::endl; - exit(EXIT_FAILURE); - } - in_file.seekg (0, in_file.end); - length = in_file.tellg(); - in_file.seekg (0, in_file.beg); - if(length!=sizeof(this->pages)) - { - std::cout << "Invalid binary motion file" << std::endl; - exit(EXIT_FAILURE); - } - in_file.read((char *)this->pages,length); - in_file.close(); - // initialize the CMtnFile class - this->motions.set_type(motion_type); - this->motions.set_version(1.0); - this->motions.set_num_servos(PAGE_MAX_NUM_SERVOS); - for(i=0;i<MAX_NUM_PAGES;i++) - { - page=new CMtnPage(PAGE_MAX_NUM_SERVOS); - name=std::string((char *)this->pages[i].header.name); - page->set_name(name); - compliance.resize(PAGE_MAX_NUM_SERVOS); - for(j=0;j<PAGE_MAX_NUM_SERVOS;j++) - compliance[j]=this->pages[i].header.slope[j]; - page->set_compliances(compliance); - page->set_next_page(this->pages[i].header.next); - page->set_exit_page(this->pages[i].header.exit); - page->set_repetitions(this->pages[i].header.repeat); - page->set_speed_rate(this->pages[i].header.speed); - page->set_inertial(this->pages[i].header.accel); - for(j=0;j<this->pages[i].header.stepnum;j++) - { - step=new CMtnStep(PAGE_MAX_NUM_SERVOS); - step->set_pause_time(this->pages[i].steps[j].pause); - step->set_step_time(this->pages[i].steps[j].time); - angles.resize(PAGE_MAX_NUM_SERVOS); - for(k=0;k<PAGE_MAX_NUM_SERVOS;k++) - angles[k]=this->pages[i].steps[j].position[k]; - step->set_angles(angles); - page->add_step(step); - } - this->motions.add_page(page); - } -} - -CMtnFile *CBinFileParser::get_motions(void) -{ - return &(this->motions); -} - -CBinFileParser::~CBinFileParser() -{ - memset(this->pages,0x00,sizeof(this->pages)); -} - diff --git a/src/bin/bin_file_parser.h b/src/bin/bin_file_parser.h deleted file mode 100644 index ba2e673..0000000 --- a/src/bin/bin_file_parser.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _BIN_FILE_PARSER_H -#define _BIN_FILE_PARSER_H - -#include "mtn_file.h" - -#define MAX_NUM_PAGES 256 -#define PAGE_MAX_NUM_SERVOS 31 -#define POSE_NUMBER_OF_POSES_PER_PAGE 7 - -typedef struct // Header Structure (total 64unsigned char) -{ - unsigned char name[13]; // Name 0~13 - unsigned char reserved1; // Reserved1 14 - unsigned char repeat; // Repeat count 15 - unsigned char schedule; // schedule 16 - unsigned char reserved2[3]; // reserved2 17~19 - unsigned char stepnum; // Number of step 20 - unsigned char reserved3; // reserved3 21 - unsigned char speed; // Speed 22 - unsigned char reserved4; // reserved4 23 - unsigned char accel; // Acceleration time 24 - unsigned char next; // Link to next 25 - unsigned char exit; // Link to exit 26 - unsigned char reserved5[4]; // reserved5 27~30 - unsigned char checksum; // checksum 31 - unsigned char slope[PAGE_MAX_NUM_SERVOS]; // CW/CCW compliance slope 32~62 - unsigned char reserved6; // reserved6 63 -} TPageHeader; - -typedef struct // Step Structure (total 64unsigned char) -{ - unsigned short int position[PAGE_MAX_NUM_SERVOS]; // Joint position 0~61 - unsigned char pause; // Pause time 62 - unsigned char time; // Time 63 -} TStep; - -typedef struct // Page Structure (total 512unsigned char) -{ - TPageHeader header; // Page header 0~64 - TStep steps[POSE_NUMBER_OF_POSES_PER_PAGE]; // Page step 65~511 -} TPage; - -class CBinFileParser -{ - private: - CMtnFile motions; - TPage pages[MAX_NUM_PAGES]; - public: - CBinFileParser(); - void parse(const char *filename); - CMtnFile *get_motions(void); - ~CBinFileParser(); -}; - -#endif diff --git a/src/mtn/CMakeLists.txt b/src/mtn/CMakeLists.txt deleted file mode 100644 index c79dab9..0000000 --- a/src/mtn/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# Create target for the parser -FIND_PACKAGE(BISON REQUIRED) -FIND_PACKAGE(FLEX REQUIRED) - -SET(BisonOutput mtn_parser.cpp) -IF(BISON_FOUND) - ADD_CUSTOM_COMMAND( - OUTPUT ${BisonOutput} - COMMAND ${BISON_EXECUTABLE} - --output=${BisonOutput} - ${CMAKE_CURRENT_SOURCE_DIR}/mtn_file.y - COMMENT "Generating mtn_parser.cpp" - ) -ENDIF() - -FIND_PACKAGE(FLEX REQUIRED) -SET(FlexOutput mtn_scanner.cpp) -IF(FLEX_FOUND) - ADD_CUSTOM_COMMAND( - OUTPUT ${FlexOutput} - COMMAND ${FLEX_EXECUTABLE} - --outfile=${FlexOutput} - ${CMAKE_CURRENT_SOURCE_DIR}/mtn_file.l - COMMENT "Generating mtn_scanner.cpp" - ) -ENDIF() - -SET(mtn_SRCS mtn_file_parser.cpp ../mtn_file.cpp ../mtn_page.cpp ../mtn_step.cpp) - -include_directories(.) -include_directories(..) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) -add_library(mtn_parser SHARED ${BisonOutput} ${FlexOutput} ${mtn_SRCS}) - diff --git a/src/mtn/mtn_file.l b/src/mtn/mtn_file.l deleted file mode 100644 index 3527fd8..0000000 --- a/src/mtn/mtn_file.l +++ /dev/null @@ -1,37 +0,0 @@ -%{ -/* Implementation of yyFlexScanner */ -#include "mtn_file_scanner.hpp" -#include "mtn_parser.hpp" - -/* typedef to make the returns for the tokens shorter */ -typedef MTN::MTN_Parser::token token; - -%} - -%option debug -%option nodefault -%option yyclass="MTN_File_Scanner" -%option noyywrap -%option c++ -%option yylineno - -%% -[ \t\n] ; -"type" { return token::TYPE; } -"version" { return token::VERSION; } -"enable" { return token::ENABLE; } -"motor_type" { return token::MOTOR_TYPE; } -"page_begin" { return token::BEGIN_PAGE; } -"name" { return token::NAME; } -"compliance" { return token::COMPLIANCE; } -"play_param" { return token::PLAY_PARAMS; } -"step" { return token::STEP; } -"page_end" { return token::END_PAGE; } -"=" { return token::EQUAL; } -[0-9]+"."[0-9]+ { yylval->fval=atof(yytext); return token::FLOAT; } -[0-9]+ { yylval->ival=atoi(yytext); return token::INT; } -[a-zA-Z0-9]+|_ { yylval->sval=new std::string(yytext); - return token::STRING; } -. { std::cout << "bad input character " << yytext << " at line " << yylineno << std::endl; } -%% - diff --git a/src/mtn/mtn_file.y b/src/mtn/mtn_file.y deleted file mode 100644 index 020d8f9..0000000 --- a/src/mtn/mtn_file.y +++ /dev/null @@ -1,157 +0,0 @@ -%skeleton "lalr1.cc" -%require "2.5" -%debug -%defines -%define namespace "MTN" -%define parser_class_name "MTN_Parser" - -%code requires -{ - namespace MTN - { - class MTN_File_Parser; - class MTN_File_Scanner; - } -} - -%lex-param { MTN_File_Scanner &scanner } -%parse-param { MTN_File_Scanner &scanner } - -%lex-param { MTN_File_Parser &parser } -%parse-param { MTN_File_Parser &parser } - -%code -{ - #include <iostream> - #include <cstdlib> - #include <fstream> - /* include for all driver functions */ - #include "mtn_file_parser.hpp" - - /* motion files variables */ - int num_servos=0; - std::vector<bool> enables; - std::vector<int> motor_types; - CMtnPage *page; - std::vector<unsigned int> compliances; - std::string motion_name; - CMtnStep *step; - std::vector<unsigned short int> angles; - - /* this is silly, but I can't figure out a way around */ - static int yylex(MTN::MTN_Parser::semantic_type *yylval,MTN::MTN_File_Scanner &scanner,MTN::MTN_File_Parser &parser); -} - -/* token types */ -%union { - int ival; - float fval; - std::string *sval; -} - -%token TYPE VERSION ENABLE MOTOR_TYPE BEGIN_PAGE END_PAGE -%token NAME COMPLIANCE PLAY_PARAMS STEP -%token EQUAL -%token <ival> INT -%token <fval> FLOAT -%token <sval> STRING - -/* destructor rule for <sval> objects */ -%destructor { if ($$) { delete ($$); ($$) = NULL; } } <sval> - -%% -motion_file: type version enables motor_types pages - ; - -type: TYPE EQUAL STRING { parser.set_type(*($3)); } - ; - -version: VERSION EQUAL FLOAT { parser.set_version($3); } - ; - -enables: ENABLE EQUAL enable { parser.set_num_servos(num_servos); - parser.set_enables(enables); - std::cout << num_servos << std::endl;} - ; - -enable: enable INT { num_servos++; - enables.push_back($2); } - | INT { num_servos++; - enables.push_back($1); } - ; - -motor_types: - | MOTOR_TYPE EQUAL motor_type { parser.set_motor_types(motor_types); } - ; - -motor_type: motor_type INT { motor_types.push_back($2); } - | INT { motor_types.push_back($1); } - ; - -pages: pages page - | page - ; - -page: BEGIN_PAGE name compliances params steps END_PAGE { parser.add_page(page); - motion_name=""; - compliances.clear(); } - | BEGIN_PAGE name compliances params END_PAGE { parser.add_page(page); - motion_name=""; - compliances.clear(); } - ; - -name: NAME EQUAL { page=new CMtnPage(num_servos); - motion_name=""; - page->set_name(motion_name); } - | NAME EQUAL strings { page=new CMtnPage(num_servos); - page->set_name(motion_name); } - ; - -strings: strings STRING { motion_name+=" "+*($2); } - | STRING { motion_name+=*($1); } - ; - -compliances: COMPLIANCE EQUAL compliance { page->set_compliances(compliances); } - ; - -compliance: compliance INT { compliances.push_back($2); } - | INT { compliances.push_back($1); } - ; - -params: PLAY_PARAMS EQUAL INT INT INT FLOAT INT { page->set_next_page($3); - page->set_exit_page($4); - page->set_repetitions($5); - page->set_speed_rate($6); - page->set_inertial($7); } - ; - -steps: steps step - | step - ; - - -step: STEP EQUAL angles FLOAT FLOAT { step=new CMtnStep(num_servos); - step->set_angles(angles); - angles.clear(); - step->set_pause_time($4); - step->set_step_time($5); - page->add_step(step); } - ; - -angles: angles INT { angles.push_back($2); } - | INT { angles.push_back($1); } - ; -%% -void -MTN::MTN_Parser::error(const MTN::MTN_Parser::location_type &l,const std::string &err_message ) -{ - std::cerr << "Error: " << err_message << "\n"; -} - -/* include for access to scanner.yylex */ -#include "mtn_file_scanner.hpp" - -static int yylex(MTN::MTN_Parser::semantic_type *yylval,MTN::MTN_File_Scanner &scanner,MTN::MTN_File_Parser &parser) -{ - return(scanner.yylex(yylval)); -} diff --git a/src/mtn/mtn_file_parser.cpp b/src/mtn/mtn_file_parser.cpp deleted file mode 100644 index 7d33019..0000000 --- a/src/mtn/mtn_file_parser.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include <cctype> -#include <fstream> -#include <cassert> - -#include "mtn_file_parser.hpp" -#include "mtn_parser.hpp" - -MTN::MTN_File_Parser::MTN_File_Parser() -{ - this->scanner=NULL; - this->parser=NULL; -} - -MTN::MTN_File_Parser::~MTN_File_Parser() -{ - if(this->scanner!=NULL) - { - delete this->scanner; - this->scanner=NULL; - } - if(this->parser!=NULL) - { - delete this->parser; - this->parser=NULL; - } -} - -void MTN::MTN_File_Parser::parse(const char *filename) -{ - std::ifstream in_file(filename); - if(!in_file.good()) - exit( EXIT_FAILURE ); - if(this->scanner!=NULL) - delete this->scanner; - try - { - scanner=new MTN::MTN_File_Scanner(&in_file); - }catch(std::bad_alloc &ba){ - std::cerr << "Failed to allocate scanner: (" << ba.what() << "), exiting!!\n"; - exit( EXIT_FAILURE ); - } - if(this->parser!=NULL) - delete this->parser; - try - { - parser = new MTN::MTN_Parser((*scanner),(*this)); - }catch(std::bad_alloc &ba){ - std::cerr << "Failed to allocate parser: (" << ba.what() << "), exiting!!\n"; - exit( EXIT_FAILURE ); - } - - const int accept(0); - if(parser->parse()!=accept) - { - std::cerr << "Parse failed!!\n"; - } -} - -void MTN::MTN_File_Parser::set_type(std::string &type) -{ - this->motions.set_type(type); -} - -void MTN::MTN_File_Parser::set_version(double version) -{ - this->motions.set_version(version); -} - -void MTN::MTN_File_Parser::set_num_servos(unsigned int num_servos) -{ - this->motions.set_num_servos(num_servos); -} - -void MTN::MTN_File_Parser::set_enables(std::vector<bool> &enables) -{ - this->motions.set_enables(enables); -} - -void MTN::MTN_File_Parser::set_motor_types(std::vector<int> &motor_types) -{ - this->motions.set_motor_types(motor_types); -} - -void MTN::MTN_File_Parser::add_page(CMtnPage *page) -{ - this->motions.add_page(page); -} - -CMtnFile *MTN::MTN_File_Parser::get_motions(void) -{ - return &(this->motions); -} diff --git a/src/mtn/mtn_file_parser.hpp b/src/mtn/mtn_file_parser.hpp deleted file mode 100644 index 3c2df7d..0000000 --- a/src/mtn/mtn_file_parser.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _MTN_FILE_PARSER_HPP -#define _MTN_FILE_PARSER_HPP - -#include <string> -#include "mtn_file_scanner.hpp" -#include "mtn_file.h" - -namespace MTN -{ - class MTN_File_Parser - { - friend class MTN_Parser; - private: - MTN::MTN_Parser *parser; - MTN::MTN_File_Scanner *scanner; - CMtnFile motions; - protected: - // motion files functions - void set_type(std::string &type); - void set_version(double version); - void set_num_servos(unsigned int num_servos); - void set_enables(std::vector<bool> &enables); - void set_motor_types(std::vector<int> &motor_types); - void add_page(CMtnPage *page); - public: - MTN_File_Parser(); - void parse(const char *filename); - virtual ~MTN_File_Parser(); - CMtnFile *get_motions(void); - }; -} - -#endif diff --git a/src/mtn/mtn_file_scanner.hpp b/src/mtn/mtn_file_scanner.hpp deleted file mode 100644 index eb944ed..0000000 --- a/src/mtn/mtn_file_scanner.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _MTN_FILE_SCANNER_HPP -#define _MTN_FILE_SCANNER_HPP - -#if !defined(yyFlexLexerOnce) -#include <FlexLexer.h> -#endif - -#undef YY_DECL -#define YY_DECL int MTN::MTN_File_Scanner::yylex() - -#include "mtn_parser.hpp" - -namespace MTN -{ - class MTN_File_Scanner : public yyFlexLexer - { - public: - MTN_File_Scanner(std::istream *in) : yyFlexLexer(in), yylval( NULL ) - { - }; - int yylex(MTN::MTN_Parser::semantic_type *lval) - { - yylval = lval; - return( yylex() ); - } - - private: - /* hide this one from public view */ - int yylex(); - /* yyval ptr */ - MTN::MTN_Parser::semantic_type *yylval; - }; -} /* end namespace MC */ - -#endif diff --git a/src/parser/CMakeLists.txt b/src/parser/CMakeLists.txt deleted file mode 100644 index 2c36ec5..0000000 --- a/src/parser/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# Create target for the parser -FIND_PACKAGE(BISON REQUIRED) -FIND_PACKAGE(FLEX REQUIRED) - -SET(BisonOutput mtn_parser.cpp) -IF(BISON_FOUND) - ADD_CUSTOM_COMMAND( - OUTPUT ${BisonOutput} - COMMAND ${BISON_EXECUTABLE} - --output=${BisonOutput} - ${CMAKE_CURRENT_SOURCE_DIR}/mtn_file.y - COMMENT "Generating mtn_parser.cpp" - ) -ENDIF() - -FIND_PACKAGE(FLEX REQUIRED) -SET(FlexOutput mtn_scanner.cpp) -IF(FLEX_FOUND) - ADD_CUSTOM_COMMAND( - OUTPUT ${FlexOutput} - COMMAND ${FLEX_EXECUTABLE} - --outfile=${FlexOutput} - ${CMAKE_CURRENT_SOURCE_DIR}/mtn_file.l - COMMENT "Generating mtn_scanner.cpp" - ) -ENDIF() - -SET(mtn_SRCS mtn_file_parser.cpp mtn_file.cpp mtn_page.cpp mtn_step.cpp) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) -add_library(mtn_parser SHARED ${BisonOutput} ${FlexOutput} ${mtn_SRCS}) - diff --git a/src/parser/mtn_file.cpp b/src/parser/mtn_file.cpp deleted file mode 100644 index 7fe8e0d..0000000 --- a/src/parser/mtn_file.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include "mtn_file.h" - -CMtnFile::CMtnFile() -{ - this->type=""; - this->version=0.0; - this->enable.clear(); - this->motor_type.clear(); - this->pages.clear(); -} - -void CMtnFile::set_type(std::string &type) -{ - this->type=type; -} - -void CMtnFile::set_version(double version) -{ - this->version=version; -} - -void CMtnFile::set_num_servos(unsigned int num_servos) -{ - this->enable.resize(num_servos); - this->motor_type.resize(num_servos); -} - -void CMtnFile::set_enable(unsigned int servo,bool enable) -{ - if(servo>this->enable.size()) - { - /* handle errors */ - } - else - this->enable[servo]=enable; -} - -void CMtnFile::set_enables(std::vector<bool> &enables) -{ - unsigned int i=0; - - if(this->enable.size()!=enables.size()) - { - /* handle errors */ - } - else - for(i=0;i<this->enable.size();i++) - this->enable[i]=enables[i]; -} - -void CMtnFile::set_motor_type(unsigned int servo, int motor_type) -{ - if(servo>this->motor_type.size()) - { - /* handle errors */ - } - else - this->motor_type[servo]=motor_type; -} - -void CMtnFile::set_motor_types(std::vector<int> &motor_types) -{ - unsigned int i=0; - - if(this->motor_type.size()!=motor_types.size()) - { - /* handle errors */ - } - else - for(i=0;i<this->motor_type.size();i++) - this->motor_type[i]=motor_types[i]; -} - -void CMtnFile::add_page(CMtnPage *page) -{ - this->pages.push_back(page); -} - -std::string CMtnFile::get_type(void) -{ - return this->type; -} - -double CMtnFile::get_version(void) -{ - return this->version; -} - -unsigned int CMtnFile::get_num_servos(void) -{ - return this->enable.size(); -} - -bool CMtnFile::get_enable(unsigned int servo) -{ - if(servo>this->enable.size()) - { - /* handle errors */ - } - else - return this->enable[servo]; -} - -std::vector<bool> CMtnFile::get_enables(void) -{ - return this->enable; -} - -int CMtnFile::get_motor_type(unsigned int servo) -{ - if(servo>this->motor_type.size()) - { - /* handle errors */ - } - else - return this->motor_type[servo]; -} - -std::vector<int> CMtnFile::get_motor_types(void) -{ - return this->motor_type; -} - -unsigned int CMtnFile::get_num_pages(void) -{ - return this->pages.size(); -} - -CMtnPage *CMtnFile::get_page(unsigned int page) -{ - if(page>this->pages.size()) - { - /* handle errors */ - } - else - return this->pages[page]; -} - -CMtnFile::~CMtnFile() -{ - unsigned int i=0; - - this->type=""; - this->version=0.0; - this->enable.clear(); - this->motor_type.clear(); - for(i=0;i<this->pages.size();i++) - { - delete this->pages[i]; - this->pages[i]=NULL; - } - this->pages.clear(); -} - diff --git a/src/parser/mtn_file.h b/src/parser/mtn_file.h deleted file mode 100644 index edd2f55..0000000 --- a/src/parser/mtn_file.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _MTN_FILE_H -#define _MTN_FILE_H - -#include "mtn_page.h" - -class CMtnFile -{ - private: - std::string type; - double version; - std::vector<bool> enable; - std::vector<int> motor_type; - std::vector<CMtnPage *> pages; - public: - CMtnFile(); - void set_type(std::string &type); - void set_version(double version); - void set_num_servos(unsigned int num_servos); - void set_enable(unsigned int servo,bool enable); - void set_enables(std::vector<bool> &enables); - void set_motor_type(unsigned int servo, int motor_type); - void set_motor_types(std::vector<int> &motor_types); - void add_page(CMtnPage *page); - std::string get_type(void); - double get_version(void); - unsigned int get_num_servos(void); - bool get_enable(unsigned int servo); - std::vector<bool> get_enables(void); - int get_motor_type(unsigned int servo); - std::vector<int> get_motor_types(void); - unsigned int get_num_pages(void); - CMtnPage *get_page(unsigned int page); - ~CMtnFile(); -}; - -#endif diff --git a/src/parser/mtn_file.l b/src/parser/mtn_file.l deleted file mode 100644 index 3527fd8..0000000 --- a/src/parser/mtn_file.l +++ /dev/null @@ -1,37 +0,0 @@ -%{ -/* Implementation of yyFlexScanner */ -#include "mtn_file_scanner.hpp" -#include "mtn_parser.hpp" - -/* typedef to make the returns for the tokens shorter */ -typedef MTN::MTN_Parser::token token; - -%} - -%option debug -%option nodefault -%option yyclass="MTN_File_Scanner" -%option noyywrap -%option c++ -%option yylineno - -%% -[ \t\n] ; -"type" { return token::TYPE; } -"version" { return token::VERSION; } -"enable" { return token::ENABLE; } -"motor_type" { return token::MOTOR_TYPE; } -"page_begin" { return token::BEGIN_PAGE; } -"name" { return token::NAME; } -"compliance" { return token::COMPLIANCE; } -"play_param" { return token::PLAY_PARAMS; } -"step" { return token::STEP; } -"page_end" { return token::END_PAGE; } -"=" { return token::EQUAL; } -[0-9]+"."[0-9]+ { yylval->fval=atof(yytext); return token::FLOAT; } -[0-9]+ { yylval->ival=atoi(yytext); return token::INT; } -[a-zA-Z0-9]+|_ { yylval->sval=new std::string(yytext); - return token::STRING; } -. { std::cout << "bad input character " << yytext << " at line " << yylineno << std::endl; } -%% - diff --git a/src/parser/mtn_file.y b/src/parser/mtn_file.y deleted file mode 100644 index 020d8f9..0000000 --- a/src/parser/mtn_file.y +++ /dev/null @@ -1,157 +0,0 @@ -%skeleton "lalr1.cc" -%require "2.5" -%debug -%defines -%define namespace "MTN" -%define parser_class_name "MTN_Parser" - -%code requires -{ - namespace MTN - { - class MTN_File_Parser; - class MTN_File_Scanner; - } -} - -%lex-param { MTN_File_Scanner &scanner } -%parse-param { MTN_File_Scanner &scanner } - -%lex-param { MTN_File_Parser &parser } -%parse-param { MTN_File_Parser &parser } - -%code -{ - #include <iostream> - #include <cstdlib> - #include <fstream> - /* include for all driver functions */ - #include "mtn_file_parser.hpp" - - /* motion files variables */ - int num_servos=0; - std::vector<bool> enables; - std::vector<int> motor_types; - CMtnPage *page; - std::vector<unsigned int> compliances; - std::string motion_name; - CMtnStep *step; - std::vector<unsigned short int> angles; - - /* this is silly, but I can't figure out a way around */ - static int yylex(MTN::MTN_Parser::semantic_type *yylval,MTN::MTN_File_Scanner &scanner,MTN::MTN_File_Parser &parser); -} - -/* token types */ -%union { - int ival; - float fval; - std::string *sval; -} - -%token TYPE VERSION ENABLE MOTOR_TYPE BEGIN_PAGE END_PAGE -%token NAME COMPLIANCE PLAY_PARAMS STEP -%token EQUAL -%token <ival> INT -%token <fval> FLOAT -%token <sval> STRING - -/* destructor rule for <sval> objects */ -%destructor { if ($$) { delete ($$); ($$) = NULL; } } <sval> - -%% -motion_file: type version enables motor_types pages - ; - -type: TYPE EQUAL STRING { parser.set_type(*($3)); } - ; - -version: VERSION EQUAL FLOAT { parser.set_version($3); } - ; - -enables: ENABLE EQUAL enable { parser.set_num_servos(num_servos); - parser.set_enables(enables); - std::cout << num_servos << std::endl;} - ; - -enable: enable INT { num_servos++; - enables.push_back($2); } - | INT { num_servos++; - enables.push_back($1); } - ; - -motor_types: - | MOTOR_TYPE EQUAL motor_type { parser.set_motor_types(motor_types); } - ; - -motor_type: motor_type INT { motor_types.push_back($2); } - | INT { motor_types.push_back($1); } - ; - -pages: pages page - | page - ; - -page: BEGIN_PAGE name compliances params steps END_PAGE { parser.add_page(page); - motion_name=""; - compliances.clear(); } - | BEGIN_PAGE name compliances params END_PAGE { parser.add_page(page); - motion_name=""; - compliances.clear(); } - ; - -name: NAME EQUAL { page=new CMtnPage(num_servos); - motion_name=""; - page->set_name(motion_name); } - | NAME EQUAL strings { page=new CMtnPage(num_servos); - page->set_name(motion_name); } - ; - -strings: strings STRING { motion_name+=" "+*($2); } - | STRING { motion_name+=*($1); } - ; - -compliances: COMPLIANCE EQUAL compliance { page->set_compliances(compliances); } - ; - -compliance: compliance INT { compliances.push_back($2); } - | INT { compliances.push_back($1); } - ; - -params: PLAY_PARAMS EQUAL INT INT INT FLOAT INT { page->set_next_page($3); - page->set_exit_page($4); - page->set_repetitions($5); - page->set_speed_rate($6); - page->set_inertial($7); } - ; - -steps: steps step - | step - ; - - -step: STEP EQUAL angles FLOAT FLOAT { step=new CMtnStep(num_servos); - step->set_angles(angles); - angles.clear(); - step->set_pause_time($4); - step->set_step_time($5); - page->add_step(step); } - ; - -angles: angles INT { angles.push_back($2); } - | INT { angles.push_back($1); } - ; -%% -void -MTN::MTN_Parser::error(const MTN::MTN_Parser::location_type &l,const std::string &err_message ) -{ - std::cerr << "Error: " << err_message << "\n"; -} - -/* include for access to scanner.yylex */ -#include "mtn_file_scanner.hpp" - -static int yylex(MTN::MTN_Parser::semantic_type *yylval,MTN::MTN_File_Scanner &scanner,MTN::MTN_File_Parser &parser) -{ - return(scanner.yylex(yylval)); -} diff --git a/src/parser/mtn_file_parser.cpp b/src/parser/mtn_file_parser.cpp deleted file mode 100644 index 7d33019..0000000 --- a/src/parser/mtn_file_parser.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include <cctype> -#include <fstream> -#include <cassert> - -#include "mtn_file_parser.hpp" -#include "mtn_parser.hpp" - -MTN::MTN_File_Parser::MTN_File_Parser() -{ - this->scanner=NULL; - this->parser=NULL; -} - -MTN::MTN_File_Parser::~MTN_File_Parser() -{ - if(this->scanner!=NULL) - { - delete this->scanner; - this->scanner=NULL; - } - if(this->parser!=NULL) - { - delete this->parser; - this->parser=NULL; - } -} - -void MTN::MTN_File_Parser::parse(const char *filename) -{ - std::ifstream in_file(filename); - if(!in_file.good()) - exit( EXIT_FAILURE ); - if(this->scanner!=NULL) - delete this->scanner; - try - { - scanner=new MTN::MTN_File_Scanner(&in_file); - }catch(std::bad_alloc &ba){ - std::cerr << "Failed to allocate scanner: (" << ba.what() << "), exiting!!\n"; - exit( EXIT_FAILURE ); - } - if(this->parser!=NULL) - delete this->parser; - try - { - parser = new MTN::MTN_Parser((*scanner),(*this)); - }catch(std::bad_alloc &ba){ - std::cerr << "Failed to allocate parser: (" << ba.what() << "), exiting!!\n"; - exit( EXIT_FAILURE ); - } - - const int accept(0); - if(parser->parse()!=accept) - { - std::cerr << "Parse failed!!\n"; - } -} - -void MTN::MTN_File_Parser::set_type(std::string &type) -{ - this->motions.set_type(type); -} - -void MTN::MTN_File_Parser::set_version(double version) -{ - this->motions.set_version(version); -} - -void MTN::MTN_File_Parser::set_num_servos(unsigned int num_servos) -{ - this->motions.set_num_servos(num_servos); -} - -void MTN::MTN_File_Parser::set_enables(std::vector<bool> &enables) -{ - this->motions.set_enables(enables); -} - -void MTN::MTN_File_Parser::set_motor_types(std::vector<int> &motor_types) -{ - this->motions.set_motor_types(motor_types); -} - -void MTN::MTN_File_Parser::add_page(CMtnPage *page) -{ - this->motions.add_page(page); -} - -CMtnFile *MTN::MTN_File_Parser::get_motions(void) -{ - return &(this->motions); -} diff --git a/src/parser/mtn_file_parser.hpp b/src/parser/mtn_file_parser.hpp deleted file mode 100644 index 5768ba6..0000000 --- a/src/parser/mtn_file_parser.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _MTN_FILE_PARSER_HPP -#define _MTN_FILE_PARSER_HPP - -#include <string> -#include "mtn_file_scanner.hpp" -#include "mtn_file.h" - -namespace MTN -{ - class MTN_File_Parser - { - public: - MTN_File_Parser(); - void parse(const char *filename); - virtual ~MTN_File_Parser(); - // motion files functions - void set_type(std::string &type); - void set_version(double version); - void set_num_servos(unsigned int num_servos); - void set_enables(std::vector<bool> &enables); - void set_motor_types(std::vector<int> &motor_types); - void add_page(CMtnPage *page); - CMtnFile *get_motions(void); - private: - MTN::MTN_Parser *parser; - MTN::MTN_File_Scanner *scanner; - CMtnFile motions; - }; -} - -#endif diff --git a/src/parser/mtn_file_scanner.hpp b/src/parser/mtn_file_scanner.hpp deleted file mode 100644 index eb944ed..0000000 --- a/src/parser/mtn_file_scanner.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _MTN_FILE_SCANNER_HPP -#define _MTN_FILE_SCANNER_HPP - -#if !defined(yyFlexLexerOnce) -#include <FlexLexer.h> -#endif - -#undef YY_DECL -#define YY_DECL int MTN::MTN_File_Scanner::yylex() - -#include "mtn_parser.hpp" - -namespace MTN -{ - class MTN_File_Scanner : public yyFlexLexer - { - public: - MTN_File_Scanner(std::istream *in) : yyFlexLexer(in), yylval( NULL ) - { - }; - int yylex(MTN::MTN_Parser::semantic_type *lval) - { - yylval = lval; - return( yylex() ); - } - - private: - /* hide this one from public view */ - int yylex(); - /* yyval ptr */ - MTN::MTN_Parser::semantic_type *yylval; - }; -} /* end namespace MC */ - -#endif diff --git a/src/parser/mtn_page.cpp b/src/parser/mtn_page.cpp deleted file mode 100644 index ea95321..0000000 --- a/src/parser/mtn_page.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include "mtn_page.h" - -CMtnPage::CMtnPage(unsigned int num_servos) -{ - this->name=""; - this->compliance.resize(num_servos); - this->next_page=-1; - this->exit_page=-1; - this->repetitions=0; - this->speed_rate=0; - this->inertial=-1; - this->steps.clear(); -} - -void CMtnPage::set_name(std::string &name) -{ - this->name=name; -} - -void CMtnPage::set_compliance(unsigned int servo,unsigned int compliance) -{ - if(servo>this->compliance.size()) - { - /* handle errors */ - } - else - this->compliance[servo]=compliance; -} - -void CMtnPage::set_compliances(std::vector<unsigned int> compliances) -{ - unsigned int i=0; - - if(this->compliance.size()!=compliances.size()) - { - /* handle errors */ - } - else - { - for(i=0;i<this->compliance.size();i++) - this->compliance[i]=compliances[i]; - } -} - -void CMtnPage::set_next_page(unsigned int page) -{ - if(page>=256) - { - /* handle errors */ - } - else - this->next_page=page; -} - -void CMtnPage::set_exit_page(unsigned int page) -{ - if(page>=256) - { - /* handle errors */ - } - else - this->exit_page=page; -} - -void CMtnPage::set_repetitions(unsigned int num) -{ - if(num>=256) - { - /* handle errors */ - } - else - this->repetitions=num; -} - -void CMtnPage::set_speed_rate(double rate) -{ - this->speed_rate=rate; -} - -void CMtnPage::set_inertial(unsigned int inertia) -{ - if(inertia>=256) - { - /* handle errors */ - } - else - this->inertial=inertia; -} - -void CMtnPage::add_step(CMtnStep *step) -{ - if(this->steps.size()>=7) - { - /* handle errors */ - } - else - this->steps.push_back(step); -} - -std::string CMtnPage::get_name(void) -{ - return this->name; -} - -unsigned int CMtnPage::get_compliance(unsigned int servo) -{ - if(servo>this->compliance.size()) - { - /* handle errors */ - } - else - return this->compliance[servo]; -} - -std::vector<unsigned int> CMtnPage::get_compliances(void) -{ - return this->compliance; -} - -unsigned int CMtnPage::get_next_page(void) -{ - return this->next_page; -} - -unsigned int CMtnPage::get_exit_page(void) -{ - return this->exit_page; -} - -unsigned int CMtnPage::get_repetitions(void) -{ - return this->repetitions; -} - -double CMtnPage::get_speed_rate(void) -{ - return this->speed_rate; -} - -unsigned int CMtnPage::get_inertial(void) -{ - return this->inertial; -} - -unsigned int CMtnPage::get_num_steps(void) -{ - return this->steps.size(); -} - -CMtnStep *CMtnPage::get_step(unsigned int step) -{ - if(step>this->steps.size()) - { - /* handle error */ - } - else - return this->steps[step]; -} - -CMtnPage::~CMtnPage() -{ - unsigned int i=0; - - this->name.clear(); - this->compliance.clear(); - this->next_page=-1; - this->exit_page=-1; - this->repetitions=0; - this->speed_rate=0; - this->inertial=-1; - for(i=0;i<this->steps.size();i++) - { - delete this->steps[i]; - this->steps[i]=NULL; - } - this->steps.clear(); -} - diff --git a/src/parser/mtn_page.h b/src/parser/mtn_page.h deleted file mode 100644 index 22549e1..0000000 --- a/src/parser/mtn_page.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _MTN_PAGE_H -#define _MTN_PAGE_H - -#include "mtn_step.h" -#include <string> - -class CMtnPage -{ - private: - std::string name; - std::vector<unsigned int> compliance; - unsigned int next_page; - unsigned int exit_page; - unsigned int repetitions; - double speed_rate; - unsigned int inertial; - std::vector<CMtnStep *> steps; - public: - CMtnPage(unsigned int num_servos); - void set_name(std::string &name); - void set_compliance(unsigned int servo,unsigned int compliance); - void set_compliances(std::vector<unsigned int> compliances); - void set_next_page(unsigned int page); - void set_exit_page(unsigned int page); - void set_repetitions(unsigned int num); - void set_speed_rate(double rate); - void set_inertial(unsigned int inertia); - void add_step(CMtnStep *step); - std::string get_name(void); - unsigned int get_compliance(unsigned int servo); - std::vector<unsigned int> get_compliances(void); - unsigned int get_next_page(void); - unsigned int get_exit_page(void); - unsigned int get_repetitions(void); - double get_speed_rate(void); - unsigned int get_inertial(void); - unsigned int get_num_steps(void); - CMtnStep *get_step(unsigned int step); - ~CMtnPage(); -}; - -#endif diff --git a/src/parser/mtn_step.cpp b/src/parser/mtn_step.cpp deleted file mode 100644 index 377cf35..0000000 --- a/src/parser/mtn_step.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "mtn_step.h" - -CMtnStep::CMtnStep(unsigned int num_servos) -{ - this->angles.resize(num_servos); - this->pause_time=0.0; - this->step_time=0.0; -} - -void CMtnStep::set_angle(unsigned int servo,unsigned short int angle) -{ - if(servo>this->angles.size()) - { - /* handle errors */ - } - else - this->angles[servo]=angle; -} - -void CMtnStep::set_angles(std::vector<unsigned short int> &angles) -{ - unsigned int i=0; - - if(angles.size()!=this->angles.size()) - { - /* handle errors */ - } - else - { - for(i=0;i<angles.size();i++) - this->angles[i]=angles[i]; - } -} - -void CMtnStep::set_pause_time(double time) -{ - if(time<0.0) - { - /* handle errors */ - } - else - this->pause_time=time; -} - -void CMtnStep::set_step_time(double time) -{ - if(time<0.0) - { - /* handle errors */ - } - else - this->step_time=time; -} - -unsigned short int CMtnStep::get_angle(unsigned int servo) -{ - if(servo>this->angles.size()) - { - /* handler errors */ - } - else - return this->angles[servo]; -} - -std::vector<unsigned short int> CMtnStep::get_angles(void) -{ - return this->angles; -} - -double CMtnStep::get_pause_time(void) -{ - return this->pause_time; -} - -double CMtnStep::get_step_time(void) -{ - return this->step_time; -} - -CMtnStep::~CMtnStep() -{ - this->angles.clear(); - this->pause_time=0.0; - this->step_time=0.0; -} - diff --git a/src/parser/mtn_step.h b/src/parser/mtn_step.h deleted file mode 100644 index f85b4f1..0000000 --- a/src/parser/mtn_step.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _MTN_STEP_H -#define _MTN_STEP_H - -#include <vector> - -class CMtnStep -{ - private: - std::vector<unsigned short int> angles; - double pause_time; - double step_time; - public: - CMtnStep(unsigned int num_servos); - void set_angle(unsigned int servo,unsigned short int angle); - void set_angles(std::vector<unsigned short int> &angles); - void set_pause_time(double time); - void set_step_time(double time); - unsigned short int get_angle(unsigned int servo); - std::vector<unsigned short int> get_angles(void); - double get_pause_time(void); - double get_step_time(void); - ~CMtnStep(); -}; - -#endif -- GitLab