In this lab you will familiarize yourself with pyrobot, a tool for controlling both simulated and physical robots, that is written in python. You will also learn how to use the conx library for experimenting with neural networks.
You will go over an extended example demonstrating how you collect
data for a robot task, train a network, and then test the resulting
weights on the robot. You will then create a robot with a neural
network brain and train it to do phototaxis (moving in response to
light).
One method for teaching a neural network to control a robot is called offline training and involves the following steps. First hand code a robot controller. Use this controller to collect data to be used to train a neural network. Next train a neural network with the collected data. Finally use the trained network to control the robot and test its performance. Follow the steps below to train a neural network to control a robot to do a wall following task.
%pyrobot -s PyrobotSimulator -w Tutorial.py -r PyrobotRobot60000 -b wallFollow.pyThe -s flag specifies which simulator you would like to use. Each simulator has a number of different worlds, which are specified by the -w flag. The simulator can control multiple robots simultaneously. Each robot has a name specified by the -r flag. Finally the robot is controlled by a brain, which is specified by the -b flag.
This will open two windows: one the pyrobot control window and the other the simulator window. In the simulator window, select the View menu and choose Trail, to see the robot's path. In the pyrobot window, push the Run button to start the robot. Every 200 steps the program will report the average distance of the robot from the wall on its left side. We will use data collected from a program running a controller like this to train a neural network.
To quit, first press the Stop button in the pyrobot window to suspend the brain. Then go to the Robot menu and select Unload Robot. Finally, go to the File menu and select Exit. If the pyrobot window fails to close, then in a terminal window do: killall -9 pyrobot.
%pyrobot -s PyrobotSimulator -w Tutorial.py -r PyrobotRobot60000 -b collectData.pyWhen you see a message that the data collection is done. Stop the robot and exit from pyrobot. You should now have two files called sensorInputs.dat and motorTargets.dat saved in your directory.
%python trainNetwork.pyThis will take several minutes to complete. It will execute 1000 epochs of training on the collected data. Watch the error and percent correct during training. Does error consistently go down? Does percent correct consistently go up? After training is complete, you will have a new file in your directory called wallFollow.wts containing the weights and biases of the most successful version of the trained neural network. You will also have a log file showing the progress of learning throughout training.
%pyrobot -s PyrobotSimulator -w Tutorial.py -r PyrobotRobot60000 -b testNetwork.pyBe sure to "View" the robot's "Trail" in the simulator window before pressing the "Run" button in the pyrobot window. How does the neural network controlled robot perform compared to the hand-coded teacher program? In what ways does the neural network controlled robot behave differently from the teacher?
You will go through the same series of steps as above, but this time using your own hand-coded program for teaching a robot to orient and approach a light source.
You should use the Braitenberg.py world as the basis for
your task. When collecting data be sure to start the robot from many
different initial conditions (with the light straight ahead, to the
right, to the left, behind the robot). You can use
the Simulation device, which is discussed in
the pyrobot overview, to programmatically
reposition the robot after it has successfully reached the light
source.
Put all of the files you created in the cs81/labs/1 directory. In the SUMMARY file provided, describe what your teacher program does, how you trained the network, and your results.
When you are done, run handin81 to turn in your completed lab work.