Skip to content

Practical Robot Programming Setup

Peter Kuan-Ting Yu edited this page Nov 7, 2016 · 8 revisions

How different it is from normal programming

In most programming task, you sit in front of your laptop or desktop equipped with a monitor of appropriate size, mouse and keyboard. However in many robots it is impossible to put a screen that is good for programming for long time because of space constraint, like our robot base. And in the most cases there is no screen but a computer on the robot. Also, the robot moves when you test it. It will be painful to chase your robot while you are programming. So here we list 2 common setups for robot programming besides the one that we did in the previous labs (physically connect monitor and keyboard/mouse to the robot).

Setups

The idea is to edit files and run commands through network connection. The robot can connect to the me212net router through wifi or Ethernet. Ask TA if you need a wifi dongle. On the other hand, you connect your desktop or laptop also to the router. Then you can use IP address for communication.

Connect through ssh inside the lab

ssh is a very powerful tool to remote login another computer and transfer files securely through unsecure network with an IP address and a port number (by default is 22).

  1. find the local IP address of the robot with command
ifconfig

If it is connected with the ethernet cable then the ip should be 192.168.1.X, where X is robot number + 10. If it is connected with wifi, then it will be random value. It is possible to have both connections exist at the same time. They will have different addresses.

  1. On the other computer that is connected to me212net router (a desktop in lab or your laptop), type
ssh robot@ip -X  # -X means with GUI

It may ask for password. It is written around the battery area in the lab. Now you can use all the commands that you normally run on the robot:

  1. run geany [Filename] to edit files remotely.
  2. run rosrun, roslaunch.
  3. run pman to start processes. Be careful of what commands that you send to the robot. You can only run one pman at a time.
  4. run open . to open a gui for the current folder. There are many more things that can be done through ssh.
  5. run meld file1 file2, meld folder1 folder2. This helps you compare and merge files.
  6. run filezilla. This help you transfer files. Remember to add port number e.g. 22.

Connect through ssh from outside the lab

This allows you to program the robot outside the lab. Ask Ryan or Peter to set it up for you. You will need a power supply for your robot instead of using the battery.

To connect ssh, you will use an external port number 22XX and the router's internet IP address (18.38.?.?, written on the white board) to connect to your robot. The router will connect the external port to the internal port 22 on the local IP address 192.168.1.XX.

ssh robot@18.38.?.? -p 22XX -X 

Getting RVIZ to work over multiple computers

Sometimes when we test the robot, we want to use rviz on the desktop computer to monitor the robot. To do this we need to set the local computer to locate the remote MASTER NODE in order to display the right information.

Assume:

  • IP: 192.168.1.0 // remote computer (robot)
  • IP: 192.168.1.1 // local computer (host)

*** ssh into remote computer ***

  1. ssh -X robot@192.168.1.0
  2. At the remote terminal: export ROS_MASTER_URI=http://192.168.1.0:11311 #this ensures that we do not use localhost, but the real IP address as master node
  3. export ROS_IP=192.168.1.0 #this ensures that ROS knows that we cannot use hostname directly (due to DHCP firewall issues)
  4. roscore

At the local terminal:

  1. export ROS_MASTER_URI=http://192.168.1.0:11311 //tells local computer to look for the remote here
  2. export ROS_IP=192.168.1.1 //this ensures that ROS knows that we cannot use hostname directly (due to DHCP firewall issues)
  3. rosrun rviz rviz // fires up rviz on local computer. It will attach to the master node of the remote computer

** Note, everytime a new terminal is open on the local/remote computer, we have to call the 2 exports commands. To make this permanent, edit the ~/.bashrc file:

  1. gedit ~/.bashrc //add the two export commands at the end of the file.
  2. source ~/.bashrc //and restart terminal

Adapted from here

Robot is a rare resource

Normally all the major development should be done without the robot and on other machines. Team members will schedule robot time of < 1 hr (e.g. use google calendar) to test your program or log some data to process offline. The development flow looks like the following

  1. Get some data from the robot: to understand the format and data received.
  2. Do your development on other machine: you create a git branch e.g. object_detection, to implement a component. Test as much as possible with visualization tools or simulation.
  3. Test it on the robot: you push your git branch to github, and then on the robot do git pull and git checkout the code. (Here the git instruction is handwavy)
  4. Do some small modification and push to your branch.
  5. If it is successful, then merge the branch to master. Otherwise, still commit and push to your branch, work more offline and test it again.

Experienced engineers can use very little robot time in the flow. Two tips:

  1. Test more things virtually without the robot in step 2. For example, when developing the navigation, the visualization should make sure all the way points are correct. No typo and logic is correct.
  2. Identify key experiments to conduct on the robots. Most of them require real physics such as testing whether or not the gripper can grasp an item.