Home > OS >  ROS about Ubuntu system environment of network communication problems
ROS about Ubuntu system environment of network communication problems

Time:10-23

I wrote a client in the ROS environment, unable to connect Windows server, consult the ROS with the ROS system is in need of a particular network connection mode, the code is as follows:


#include
//# include & lt; Wifi_get/wifi_nice. H>
#include
#include
#include
#include
#include
#include
 

#include
#include
#include
#include
#include
#include
#include
#include
# include "tf/LinearMath Matrix3x3. H"
# include "geometry_msgs/Quaternion. H"
# define BACKLOG 10
# define MAXSIZE 1024
# define SERVPORT 8000
# define MAXDATASIZE 100
# define SERVER_IP_1 "123.206.94.11
"# define SERVER_IP_2 "127.0.0.1
"# define SERVER_IP_3 "192.168.1.104,
"# define vel_angle_max 5
# define BUFSIZ1 1000
using namespace std;

Int main (int arg c, char * * argv)
{
Int client_sockfd;
Int rec_len send_len;
Int Angle, Angle_flag;
Double vel_angle_ vel_speed;
Struct sockaddr_in remote_addr;//the server network address structure
Char buf [BUFSIZ1];//data transmission buffer
Char buf_send [BUFSIZ1];//data transmission buffer
Char STR [BUFSIZ1];

Char buf_rec [BUFSIZ1];//data transmission buffer
String str_angule str_speed;
String rebackmsg;
String recivemsg;
Printf (" test/n ");
//memset (& amp; Remote_addr, 0, sizeof (remote_addr));//data initialization - reset
Bzero (& amp; Remote_addr, sizeof (remote_addr));
Remote_addr. Sin_family=AF_INET;//set to IP communications
Remote_addr. Sin_addr. S_addr=inet_addr (SERVER_IP_2);//the server IP address
Remote_addr. Sin_port=htons (SERVPORT);//the server port
//remote_addr. Sin_addr. S_addr=inet_addr (" 123.206.94.11 ");//the server IP address
//remote_addr sin_port=htons (8443);//the server port

Printf (" test1/n ");
/* create a client socket, IPv4, connection-oriented communication, TCP protocol */
If ((client_sockfd=socket (PF_INET SOCK_STREAM, 0)) & lt; 0)
//if ((client_sockfd=socket (AF_INET SOCK_STREAM, 0)) & lt; 0)
{
perror("socket");
Return 1;
}
Printf (" creat socket ok!/n ");
/* to bind the socket to the server on the network address of */
If (connect (client_sockfd, (struct sockaddr *) & amp; Remote_addr, sizeof (struct sockaddr) & lt; 0)
{
Printf (" always connect a sever!/n ");
perror("connect");
return 1;
}
//write (sockfd_1, DATA, sizeof (DATA));
Printf (" connected to the server/n ");
Rec_len=recv (client_sockfd, buf, BUFSIZ1, 0);//receiving server information
Buf [rec_len]='\ 0';
Printf (" % s ", buf);//print server information


//used to resolve ROS parameters, the third argument for this node name
Ros: : init (arg c, argv, "APP_Client");
Ros: : NodeHandle handle_;
Ros: : Publisher vel_pub_;
Geometry_msgs: : Twist controlVel_;
Vel_pub_=handle_. Advertise ("/cmd_vel ", 1);
Ros: : what loop_rate (2);

ControlVel_. Presents. Z=0;
ControlVel_. Linear. X=0;
ControlVel_. Linear. Y=0;
ControlVel_. Linear. Z=0;

Vel_speed=1.5;
Rebackmsg="";
Angle_flag=0;

While (1)
{

Printf (" connected to the server/n ");
If (rebackmsg!="")
{
Strcpy (buf_send, rebackmsg c_str ());
Send_len=send (client_sockfd buf_send, strlen (buf_send), 0).
Rebackmsg="";
}

Rec_len=recv (client_sockfd buf_send, BUFSIZ1, 0).
Recivemsg=buf_send;

If (recivemsg!="")
{
Printf (" % s ", buf_send);
}

If (recivemsg. Find (" SetAngle ")!=1)
{
Strcpy (STR, recivemsg c_str ());
Char * p=STRSTR (STR, "SetAngle_");
Sscanf (p + strlen (" SetAngle_ "), "% d", & amp; Angle);
Angle_flag=1;


}

If (recivemsg. Find (" SetSpeedHIGH ")!=1)
{
Vel_speed=1.5;
Rebackmsg="RESPABBSETAGVSPEED# FBYAAH2WV7V4VNPGUHY1 SetSpeedHIGHOK *";

}
Else if (recivemsg. Find (" SetSpeedMEDIUM ")!=1)
{
Vel_speed=2.5;
Rebackmsg="RESPABBSETAGVSPEED# FBYAAH2WV7V4VNPGUHY1 SetSpeedHIGHOK *";

}
Else if (recivemsg. Find (" SetSpeedLOW ")!=1)
{
Vel_speed=3.5;
Rebackmsg="RESPABBSETAGVSPEED# FBYAAH2WV7V4VNPGUHY1 SetSpeedHIGHOK *";

}

If (recivemsg!="")
{
Recivemsg="";
}

If (Angle_flag)
{
If (Angle & gt; 180)
{
Int angle_change;
Angle_change=Angle - 360;
Angle=angle_change;
}
Vel_angle_=vel_angle_max * (Angle/180);
ControlVel_. Presents. Z=vel_angle_;
ControlVel_. Linear. X=vel_speed;
ControlVel_. Linear. Y=0;
ControlVel_. Linear. Z=0;
Vel_pub_. The publish (controlVel_);
Angle=0;
Angle_flag=0;
}



//according to the previously defined frequency, sleep 1 s
Loop_rate. Sleep ();
}
return 0;
}



CodePudding user response:

Less of the Windows firewall

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related