Maritime-Robotics-Student-Society / sailing-robot

Southampton sailing robot
http://www.sotonsailrobot.org
Other
88 stars 46 forks source link

Maximise number of computers we can use with ROS, rosbag etc. #149

Closed smaria closed 7 years ago

smaria commented 8 years ago

We want to run as many tasks as possible for students to play with ROS. Since we cannot assume they will all have everything set up on their machines from the start, we should have as many machines as possible available for them.

takluyver commented 8 years ago

Hopefully rviz segfaulting is something peculiar to my VM, and not a general bug in the ROS VM image!

Nanoseb commented 8 years ago

By changing the port ros uses one can launch several instances of ROS on the same computer, maybe this can be used (see http://answers.ros.org/question/11395/can-multiple-instances-of-gazebo-andor-roscore-run-in-parallel ). One computer has several copies of the repo and several roscore running, then people can ssh to it to run their tests (however to run rviz in this context one will have to use x forwarding).

EDIT: to change the port ros uses you just have to set a bash variable. If needed I can make a small script to set this port depending on the ssh connection, so that the user don't have anything to do.

EDIT2: to do that one can just add this to his bashrc after sourcing the ros environment:

ip=$(echo $SSH_CLIENT | awk '{print $1}' | sed 's/\.//g')

if [ -z "$SSH_CLIENT"  ] || [ "$ip" = "127001" ]
then
  port=11311
else
  port=$((11312 + (ip % 1024)))
fi
echo ROS port: $port
export ROS_MASTER_URI=http://127.0.0.1:$port/
smaria commented 8 years ago

we need to test this with tabarly on thursday. this looks like an excellent plan!

Nanoseb commented 8 years ago

and the same script using the mac address instead of the ip to be able to keep it even after disconnection of the network. However this will not work properly if there is any router between the server and the client.

ip=$(awk '{print $1}' <<< $SSH_CLIENT)

if [ -z "$SSH_CLIENT"  ] || [ "$ip" = "127.0.0.1" ]
then
  port_mac=11311
  port_ip=11311
else
  ip_hash=$(sed 's/\.//g' <<< $ip)
  mac_hash=$(arp -a | grep "$ip" | awk '{print $4}' | sed 's/://g;s/[a-z]/1/g;s/^0*//g')
  port_ip=$((11312 + (ip_hash % 2000)))
  port_mac=$((11312 + (mac_hash % 2000)))
fi
echo ROS port ip: $port_ip
echo ROS port mac: $port_mac
export ROS_MASTER_URI=http://127.0.0.1:$port_mac/