Robotics StackExchange | Archived questions

How to configure tcp server

Hi,

I have built a robot with ESP32 module communicating over WiFi to control the robot. The robot is working well and I am able to send cmd_vel from pc to robot and it seems to be driving well.

const char* ssid = "my_ssid";
const char* password = "my_pwd";
IPAddress server(192, 168, 0, 110); // ip of ROS server
client.connect(server, 11411);

How do I make it truly mobile where in I go to a different location, another WiFi and still able to connect to this robot without reprogramming the robot with ssid and password?

Secondly, once I rebooted, the IP address of my PC changed (on VM). I understand that I can use ROS_MASTER to configure server, but some servers have 192.168.0.xxx while others have 192.168.1.xxx.

Lastly, "11411" port, is this universal that I can keep it stored always on the robot controller, or will that also change if I install ROS on a different system?

Thank you for any support provided. -Praveen

Asked by praveen_khm on 2022-09-20 06:45:37 UTC

Comments

Answers

Hello praveen, If I understand you correctly you want to be able to communicate with your robot without changing the network settings of your robot. The only thing which is required here is a common network on which you and your robot both can connect. I need a few more details here to help you

  1. Does your robot has an onboard PC on which you can run ros master?
  2. Are you using your PC as ROS master and only sending velocity commands to robot with esp node?

Edit 1

If they are on same network then only problem we have is to make sure server takes up same ip every time. This can be done by allocating a static ip to your PC in network settings and then telling rosmaster to pick that ip every time. Taking a static ip on network is easy part for making rosmaster to take a particular ip. You’ll need to write these lines in your pc’s ~/.bashrc file

export ROS_MASTER_URI=http://pc_ip:11311 export ROS_IP=pc_ip export ROS_HOSTNAME=pc_ip Then source the bashrc and run code from that terminal

Asked by tomarRobin on 2022-09-20 21:14:51 UTC

Comments

Hi,

Thank you for the response.

That is exactly what I want to do. Make sure the robot communicates with pc irrespective of change of ip on pc. I have a way to configure the said and password of esp32 and so it will be a common network. But ipaddress of server is kind of bothering.

  1. Yes, it has an esp32 onboard. It does not have Ros, but connects via wifi as a Ros node.
  2. Yes. PC is used to send velocity commands and receive encoded counts from esp node.

Asked by praveen_khm on 2022-09-21 00:22:53 UTC

Try the steps in edited answer. And make sure to replace the pc_ip with actual static ip of your pc

Asked by tomarRobin on 2022-09-21 01:44:14 UTC

Well, this is where the problem starts. The PC or laptop will not be on the same network always. If I go to a different location, the ip address changes. I can feed that ip to master, but not on the robot. On the robot, I can feed ssid and password remotely, but not the IPAddress server. Is there a way I can make IPAddress server static on robot such that it connects to master irrespective of network? Just a small misunderstanding I had; same I meant common across both network robot and pc; but the actual network can be either my home of office network.

Asked by praveen_khm on 2022-09-21 01:45:53 UTC

I will try to explain it more clearly.

Suppose I am at home where the IP address is http://192.168.0.100:11311 with ssid1 and password1. I will feed ssid1 and password1 on robot and laptop. Now when I go to office, the IP address on the laptop will be http://192.168.1.105:11311 with ssid2 and password2. I will still be able to feed the robot and laptop with ssid and password credentials. However, I need the robot to get ipaddress of server directly.

Say for example, I feed an alias as "http://10.10.10.1" ( or Hostname) on the PC irrespective of any network it connects to. Now the robot should always connect to this IPaddress which is the master so that I dont have to change it / or program it everytime.

If I follow this advice:

export >ROS_MASTER_URI=http://pc_ip:11311 
export ROS_IP=pc_ip 
export ROS_HOSTNAME=pc_ip 

I will still be linked to a particular IP. In this case, I still need to change IPaddress on robot when I change the network.

Asked by praveen_khm on 2022-09-21 01:56:47 UTC

Firstly, You can only run the rosmaster on an IP if that ip is actually used by your system , if you have a static ip of 192.168.1.xx and you try to set rosmaster ip to be 192.168.1.yy then server will not start. Secondly, there is no way for esp to know on which ip in this current network is my rosmaster running so the only way to keep communicating is to have same static ip on any network. Is there any problem in having same static ip in a different network?

Asked by tomarRobin on 2022-09-21 03:11:32 UTC

I have no control over outside network. This simply means that if I go to any location, I should be able to connect to a wifi network there and make the robot work.

https://answers.ros.org/question/228706/set-ros_master_uri-on-remote-robots/?answer=228710#post-id-228710

This posts kind of answers the requirement. The OP there has a similar requirement, but I am not sure how it is solved.

Asked by praveen_khm on 2022-09-21 04:10:01 UTC

As much as i could understand from the answer you pointed, Since you have no control over the network as you mentioned, that solution will not work for you as well because that would require you to configure the DNS server of the network and tell it that anyone trying to look for name “xyz” should be directed to my pc ip. Where xyz could be your ros master hostname.

Asked by tomarRobin on 2022-09-21 08:59:27 UTC

Can you please point me in how to configure dns? If that is a possibility, i will try to configure the dns, if it's a one time job.

Asked by praveen_khm on 2022-09-21 10:05:45 UTC