Running your program

We now need to learn how to deploy and run our program on the robot.  The first step is to connect your WiFi to the robot.  The hotspot you are looking for is MiniBot and the password is raspberry.

Once connected to the MiniBot’s WiFi, you need to start the Pi Driver Station which we will use to control the robot.  To launch the driver station, navigate to the PiDriverStation directory under the RaspberryPi directory and double click on the PiDriverStation.cmd file.  The following window should be displayed:

RobotMinibotDriverStation

Now before we can run our program, we must start the remote launcher on the Raspberry Pi.  To do this we launch the remote terminal program Putty and have it log in and start the programs we need. We will eventually be able to do this from the driver station, but we must configure the Putty software first.  Double click on the putty.exe program that is in the PiDriverStation directory you were just in.  We need to configure a session for connecting to the MiniBot.  In the Host Name (or IP address) field, enter the IP address of the MiniBot, which is 172.24.1.1.  Then let’s name this session MiniBot Run.  The PuTTY configuration window should look like:

Putty1

Before we go any further, let’s check to see if we can connect to the MiniBot.  First click the Save button to save this configuration, and then click the Open button.  The following window should be displayed:

PuttyLogin

Log in using the user name pi and password raspberry.  Once you get this working, close the PuTTY window.  We now want to configure the session so that it automatically logs in and starts the remote launcher program on the pi. Once again, double click on the putty.exe program. Then click on the MiniBot Run session and click Load.  Now click on the Connection/Data option on the left and enter pi in the Auto-login username field like this:

Putty2

Now click on the Connection/SSH option on the left and enter ./runall in the Remote command field, as follows:

RobotMinibotPuttyRunall

Finally, click on the Session option on the left and then click Save to save this session.  Now test this out by clicking the Open button.  If everything is set up correctly, the terminal window should open and ask for your password.  Enter raspberry as the password, and you should then see the following:

RobotMinibotPuttyRunning

When you have this working, close the PuTTY window.

Now that we have the proper PuTTY session set up, we can configure our driver station so that we can launch the PuTTY terminal remotely. Start up the Pi Driver Station again, click the settings button and enter the following information.  Then click OK.

RobotMinibotSettings

Now if you click the Launch Putty button in the driver station, the PuTTY terminal should start and run the remote launcher on the pi.

RobotMinibotPuttyTerminal

Once the remote launcher is running on the pi, we are ready to deploy and run our program.  To do this, we will need to set up the run configuration for the MiniBot.  In Eclipse, choose the Run Configuration option from the Run menu.  In the dialog box click on the New Launch Configuration button as shown below:

EclipsNewLaunchConfigButton

Then on the Main tab set the Name of the configuration to MyMinibot. Click on the Browse button and choose the MyMinibot project. Finally, click on the Search button and choose org.ah.java.remotevmlauncher.client.LaunchRemote for the Main class.  The run configuration dialog should now look like:

RobotMinibotRunConfigurations

Now click on the Arguments tab and enter the following into the Program arguments field, and then click Apply.

 EclipsRunConfigArgs

We are now ready to run our program.  Make sure that the PuTTY terminal is still open and the remote launcher is running and then click the Run button in the Run Configurations dialog.  Your program should start and you should see the following output in the Console tab at the bottom of the Eclipse window:

EclipseConsoleOutput

 The output that we see is the output from our program, specifically the logging output due to the calls to Logger.Log(…) function that we mentioned earlier.  The first number of each line represents the time, in milliseconds, that the log was made.  The next string, is the tag for that particular log, which is typically the module name.  The number in the parenthesis specifies the logging level, final string is the logged data.  Which tag, and what logging levels are output can be controlled, allowing us to determine exactly what we see in the log.

Note that the little red square button at the top of the Console window shows that our program is currently running.  If we wish to terminate the program, we can click on that button.

The program is now running, but it does not seem to be doing anything!  This is because our robot code will not be executed until the robot has been enabled.  Now switch to the Pi Driver Station window and click the Connect button. This should connect the driver station to the robot and the Connect button should change to Disconnect indicating that we are now connected.  If we wish to disconnect from the robot, we would simply click this button.

On the driver station control panel there are three radio buttons which specify what mode we click the Enable button.  By default Teleop is selected.  Noww click the Enable button, to begin teleop operation.  When we do that, we see the following output in the Console window:

EclipseConsoleOutput2

Here we can see that the teleopInit() function of our Robot class has been called.  There does not appear to be anything else happening, but rest assured, our teleopPeriodic() function is not being called over and over again.  We are not seeing any output from that routine because the logging level is currently set to 0 (by default), and the logging level for the teleopPeriodic function is set to -1.  If we wish to see logs for this function, we either need to change the current logging level, or increase the logging level of that particular call.  Let’s do the latter.  Change the teleopPeriodic() function to look like:

	@Override
    public void teleopPeriodic()
	{
		Logger.Log("Robot", 0, "teleopPeriodic()");
		
		Scheduler.getInstance().run();
		
		Sleep(10);
    }

Note that we have changed the logging level for this line to 0.  This means that if we have our current logging level also set to 0 (the default), then this line will output its message each time it is called.  However, care must be taken when logging data in functions that are called repeatedly, because a very large amount of output can be generated.  Note that in teleopPeriodic we are sleeping for 10 ms each time it is called.  This will limit the rate at which this function is called to less than or equal to 100 times per second.  This means that as long as our teleop mode is enabled, we will be printing about 100 lines of output to the console every second.  Note that without the Sleep call, the rate would be significantly higher.

Now lets run our program again.  Click the little red square button at the top of the Console window to stop the current program.  Since we have previously run this configuration, we can run it again by opening the run menu and choosing the MyMinibot item as shown below:

RobotMinibotRun

Doing so will then start out program again.  Now bring up the driver station and connect to the robot.  Once connected, we are going to enable the robot for a short time.  Remember, that as long as it is enabled, it will be outputting to the console at a very fast rate.  Now press the Enable button, wait about a second, and then press the Disable button.  The console window should now show the following:

EclipseConsoleOutput3

Note that there are now a whole bunch of lines telling us that the teleopPeriodic() function has been called repeatedly, and we can see from the time stamps that it is being called about every 10 ms, which is what we would expect given that we are pausing 10 ms each time we are called.  Before we go on, we will want to change the logging level for that line back to -1 so we don’t get all of that output during teleop.

	@Override
    public void teleopPeriodic()
	{
		Logger.Log("Robot", -1, "teleopPeriodic()");
		
		Scheduler.getInstance().run();
		
		Sleep(10);
    }

Now that we now how to create, deploy and run programs, we are ready to start programming our robot for the task at hand.

One final note before we go. When you want to turn your robot off, it is best if your shut it down properly. Not doing so could potentially corrupt the file system. It is like removing a thumb drive from your computer, it is best to eject the drive first.

To force the robot to shut down, simply press the Shutdown Pi button on the Driver Station. Note that this will open a terminal window that will seem to just hang. That is OK, it is because when you shut the robot down your computer loses connection to the robot. Just close the window. Then give the robot about 10 seconds or so to finish shutting down before you turn the power off.

If you forget and don’t shut it down before you turn it off, don’t fret. Like removing the thumb drive without ejecting, most of the time it will not cause problems. However it is ideal if you can remember to shut it down first.

Next: Drive Subsystem