par
FengyeWuming » 20 juin 2014, 11:35
Je compile le fichier exécutable serveurWeb à partir du fichier .cpp suivant :
[cpp]
#include <stdio.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <term.h>
#include <sys/time.h>
#include <signal.h>
#include <libgen.h>
#include "LinuxDARwIn.h"
#include <math.h>
//#include <ctime>
using namespace Robot;
using namespace std;
#ifdef MX28_1024
#define MOTION_FILE_PATH "../../../Data/motion_1024.bin"
#else
#define MOTION_FILE_PATH "../../../Data/motion_4096.bin"
#endif
#define VERSION "1.000"
#define TCPIP_PORT 6501
#define ROBOPLUS_JOINT_MAXNUM 26
#define ARGUMENT_NAXNUM 30
int _getch()
{
struct termios oldt, newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
string* string_split(string str_org, string str_tok)
{
int cutAt;
int index = 0;
string* str_result = new string[ARGUMENT_NAXNUM];
while((cutAt = str_org.find_first_of(str_tok)) != str_org.npos){
if(cutAt > 0)
str_result[index++] = str_org.substr(0, cutAt);
str_org = str_org.substr(cutAt + 1);
}
if(str_org.length() > 0)
str_result[index++] = str_org.substr(0, cutAt);
return str_result;
}
void sighandler(int sig)
{
exit(0);
}
int main(int argc, char *argv[])
{
signal(SIGABRT, &sighandler);
signal(SIGTERM, &sighandler);
signal(SIGQUIT, &sighandler);
signal(SIGINT, &sighandler);
// Initialization general parametres
int i,j,ch;
int iterFin,iterInit;
struct timeval tv;
char filename[128];
//////////////////// Framework Initialize ////////////////////////////
LinuxCM730 linux_cm730("/dev/ttyUSB0");
CM730 cm730(&linux_cm730);
if(cm730.Connect() == false){
printf("Fail to connect CM-730!\n");
return 0;
}
fprintf(stderr, "\n***********************************************************************\n");
fprintf(stderr, "* Communiquons !!! *\n");
fprintf(stderr, "***********************************************************************\n\n");
/*change_current_dir();
if(argc < 2)
strcpy(filename, MOTION_FILE_PATH); // Set default motion file path
else
strcpy(filename, argv[1]);*/
//////////////////// Framework Initialize ///////////////////////////
if(MotionManager::GetInstance()->Initialize(&cm730) == false){
printf("Fail to initialize Motion Manager!\n");
return 0;
}
MotionManager::GetInstance()->AddModule((MotionModule*)Action::GetInstance());
LinuxMotionTimer *motion_timer = new LinuxMotionTimer(MotionManager::GetInstance());
motion_timer->Stop();
cout << "[Running....]\n";
try{
// Create the socket
LinuxServer new_sock;
LinuxServer server (TCPIP_PORT);
while (true){
cout << "[Waiting..]" << endl;
server.accept (new_sock);
cout << "[Accepted..]" << endl;
try {
while (true){
string data;
Action::PAGE page;
new_sock >> data ;
// Initialization specific variables & parameters
string* p_str_tok = string_split(data, " ");
int ID_Dynamixel = atoi(p_str_tok[0].c_str());
int nbrPeriode = atoi(p_str_tok[1].c_str());
int Tperiode = atoi(p_str_tok[2].c_str());
int Fe = atoi(p_str_tok[3].c_str());
int positionInit = atoi(p_str_tok[4].c_str());
int positionFin = atoi(p_str_tok[5].c_str());
int punch = atoi(p_str_tok[6].c_str());
int correcteurP = atoi(p_str_tok[7].c_str());
int correcteurI = atoi(p_str_tok[8].c_str());
int correcteurD = atoi(p_str_tok[9].c_str());
int Te = 1000000/Fe; //calcul du temps d'échantillonage
int nbrTe = Tperiode*Fe;
int nbrTeTotal = nbrTe*nbrPeriode; //calcul du nombre d'échantillonage total
int addr;
unsigned char DataTable[6];
int position[nbrTeTotal];
uint64_t timestamp[nbrTeTotal];
uint64_t tc,old_tc,old_timestamp,old_transtimestamp,transtimestamp_init,transtimestamp_fin;
int velocity[nbrTeTotal];
int load[nbrTeTotal];
int stepPoint[nbrTeTotal];
int testTime;
int baud_rate = 1;
int return_delay_time = 1;
//Programme ...
for (j=0;j<nbrTeTotal;j++){
new_sock << "" << timestamp[j] << "," << stepPoint[j] << "," << position[j] << "," << velocity[j] << "," << load[j] << ";"<<"\r\n";
}
// End of loop
cout << "Simulation done!!!" << endl;
}
}
catch ( LinuxSocketException& ){
cout << "[Disconnected]" << endl;
if(Action::GetInstance()->IsRunning() == 1){
Action::GetInstance()->Stop();
while(Action::GetInstance()->IsRunning() == 1)
usleep(1);
MotionManager::GetInstance()->SetEnable(false);
//motion_timer->Stop();
}
}
}
}
catch ( LinuxSocketException& e )
{
cout << "Exception was caught:" << e.description() << "\nExiting.\n";
}
return 0;
}
[/cpp]
quand je l'exécute à partir de page php, il me donne cette erreur Fail to connect CM-730!.
cm730 est une classe déclarée dans LinuxDARwIn.h ...
Je compile le fichier exécutable serveurWeb à partir du fichier .cpp suivant :
[cpp]
#include <stdio.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <term.h>
#include <sys/time.h>
#include <signal.h>
#include <libgen.h>
#include "LinuxDARwIn.h"
#include <math.h>
//#include <ctime>
using namespace Robot;
using namespace std;
#ifdef MX28_1024
#define MOTION_FILE_PATH "../../../Data/motion_1024.bin"
#else
#define MOTION_FILE_PATH "../../../Data/motion_4096.bin"
#endif
#define VERSION "1.000"
#define TCPIP_PORT 6501
#define ROBOPLUS_JOINT_MAXNUM 26
#define ARGUMENT_NAXNUM 30
int _getch()
{
struct termios oldt, newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
string* string_split(string str_org, string str_tok)
{
int cutAt;
int index = 0;
string* str_result = new string[ARGUMENT_NAXNUM];
while((cutAt = str_org.find_first_of(str_tok)) != str_org.npos){
if(cutAt > 0)
str_result[index++] = str_org.substr(0, cutAt);
str_org = str_org.substr(cutAt + 1);
}
if(str_org.length() > 0)
str_result[index++] = str_org.substr(0, cutAt);
return str_result;
}
void sighandler(int sig)
{
exit(0);
}
int main(int argc, char *argv[])
{
signal(SIGABRT, &sighandler);
signal(SIGTERM, &sighandler);
signal(SIGQUIT, &sighandler);
signal(SIGINT, &sighandler);
// Initialization general parametres
int i,j,ch;
int iterFin,iterInit;
struct timeval tv;
char filename[128];
//////////////////// Framework Initialize ////////////////////////////
LinuxCM730 linux_cm730("/dev/ttyUSB0");
CM730 cm730(&linux_cm730);
if(cm730.Connect() == false){
printf("Fail to connect CM-730!\n");
return 0;
}
fprintf(stderr, "\n***********************************************************************\n");
fprintf(stderr, "* Communiquons !!! *\n");
fprintf(stderr, "***********************************************************************\n\n");
/*change_current_dir();
if(argc < 2)
strcpy(filename, MOTION_FILE_PATH); // Set default motion file path
else
strcpy(filename, argv[1]);*/
//////////////////// Framework Initialize ///////////////////////////
if(MotionManager::GetInstance()->Initialize(&cm730) == false){
printf("Fail to initialize Motion Manager!\n");
return 0;
}
MotionManager::GetInstance()->AddModule((MotionModule*)Action::GetInstance());
LinuxMotionTimer *motion_timer = new LinuxMotionTimer(MotionManager::GetInstance());
motion_timer->Stop();
cout << "[Running....]\n";
try{
// Create the socket
LinuxServer new_sock;
LinuxServer server (TCPIP_PORT);
while (true){
cout << "[Waiting..]" << endl;
server.accept (new_sock);
cout << "[Accepted..]" << endl;
try {
while (true){
string data;
Action::PAGE page;
new_sock >> data ;
// Initialization specific variables & parameters
string* p_str_tok = string_split(data, " ");
int ID_Dynamixel = atoi(p_str_tok[0].c_str());
int nbrPeriode = atoi(p_str_tok[1].c_str());
int Tperiode = atoi(p_str_tok[2].c_str());
int Fe = atoi(p_str_tok[3].c_str());
int positionInit = atoi(p_str_tok[4].c_str());
int positionFin = atoi(p_str_tok[5].c_str());
int punch = atoi(p_str_tok[6].c_str());
int correcteurP = atoi(p_str_tok[7].c_str());
int correcteurI = atoi(p_str_tok[8].c_str());
int correcteurD = atoi(p_str_tok[9].c_str());
int Te = 1000000/Fe; //calcul du temps d'échantillonage
int nbrTe = Tperiode*Fe;
int nbrTeTotal = nbrTe*nbrPeriode; //calcul du nombre d'échantillonage total
int addr;
unsigned char DataTable[6];
int position[nbrTeTotal];
uint64_t timestamp[nbrTeTotal];
uint64_t tc,old_tc,old_timestamp,old_transtimestamp,transtimestamp_init,transtimestamp_fin;
int velocity[nbrTeTotal];
int load[nbrTeTotal];
int stepPoint[nbrTeTotal];
int testTime;
int baud_rate = 1;
int return_delay_time = 1;
//Programme ...
for (j=0;j<nbrTeTotal;j++){
new_sock << "" << timestamp[j] << "," << stepPoint[j] << "," << position[j] << "," << velocity[j] << "," << load[j] << ";"<<"\r\n";
}
// End of loop
cout << "Simulation done!!!" << endl;
}
}
catch ( LinuxSocketException& ){
cout << "[Disconnected]" << endl;
if(Action::GetInstance()->IsRunning() == 1){
Action::GetInstance()->Stop();
while(Action::GetInstance()->IsRunning() == 1)
usleep(1);
MotionManager::GetInstance()->SetEnable(false);
//motion_timer->Stop();
}
}
}
}
catch ( LinuxSocketException& e )
{
cout << "Exception was caught:" << e.description() << "\nExiting.\n";
}
return 0;
}
[/cpp]
quand je l'exécute à partir de page php, il me donne cette erreur Fail to connect CM-730!.
cm730 est une classe déclarée dans LinuxDARwIn.h ...