Robot Controller (Code.org)

Get the Sample Robot Controller App

Follow-the steps below to get a sample Robot Controller App in your code.org account.

1

Step 1: Sign-in to code.org

Go to code.org and click on 'Sign In' (top right). Then, choose Continue with Google and use your school account to login.

2

Step 2: Goto Sample Robot Controller App

Once you are signed in to code.org, click here for the Sample Robot Controller App. You will then click on View Code (NOT 'Make my Own').

3

Step 3: Copy the sample app to your account

Click on the Remix button to copy the sample app into your own account. (When you have done this - the name of the app will be Remix: Robot Controller V3. Feel free to rename it if you wish. This is now your own copy of the app to use and modify.)

4

Step 4: Modify the sample app username and usercode

You now need to change the username and usercode to the values Mr. Hogg has given you. (Make sure to keep the double quotes around these values when you change them!) You now have a robot controller app in your code.org account. You can use the Test Robot screen for basic testing. You will then need to create your own controller screen on the controlrobot screen.

Building (Modifying) your Robot Controller App

Once you have completed the above steps, you SHOULD be able to control the robot during mission challenges! NOW you can modify the app to better control the app and give you greater control.

Using the Sample Robot App you will need to create a good robot controller. You can modify the screen with id controlrobot to create your controller.

Note that the runRobotCommand runs the instruction(s) you set in the variable robotCommand. The next section below describes all the possible instructions. Note that you can provide multiple instructions at once by separating the instructions with commas.

Example

robotCommand = "FWD-255-1000,TURNR-150-2000"; runRobotCommand();

This example is calling the runRobotCommand with two instructions. The first instruction FWD-255-1000 says to go forward at full speed (255) for 1 seconds (1000 ms).

The second instruction (separated by comma) TURNR-150-2000 says to turn right at medium speed (150) for 2 seconds (2000 ms).

Robot Instructions

Note that XXX below refers to SPEED and must be between 0 (stopped) and 255 (full speed). YYY is the time for the motor to be on (in milliseconds, so 1000 is 1 seconds)

Motor CommandDescription
FWD-XXX-YYYGo Foward
BACK-XXX-YYYGo Back
TURNL-XXX-YYYTurn Left
TURNR-XXX-YYYTurn Right
TURNFWDL-XXX-YYYTurn Left (While Moving Forward)
TURNFWDR-XXX-YYYTurn Right (While Moving Forward)

Note that ZZZ below is a time (in ms)

Robot Instruction Calibration

ExampleHow far robot moves
FWD-255-100017 cm forward
BACK-255-100017 cm backward
TURNL-150-4000Turns in place about 90 degrees
TURNR-150-4000Turns in place about 90 degrees
TURNFWDL-200-500
TURNFWDR-200-500

Typical Challenge Sequence

  1. Challenge name is given and you will need to set this in your app.
  2. ONCE Challenge is open for registration, you will need to register as a user (calls the function registerRobotUser).
  3. Challenge registration will be closed. You can not do anything.
  4. Challenge will be set to run. You can NOW send commands (call runRobotCommand after setting the variable robotCommand). Remember that one command can include multiple instructions.
  5. Depending on the challenge, you may have limits on number of simultaneous commands, length of allowed run time, etc.
  6. You and your team (if applicable) will then need to drive your robot to victory!

Robot Problems

To be succesful at a mission, you want to move your robot as quickly as possible. However, more commands more quickly means you are 'driving blind' and may end up causing your robot to get stuck or fall off a 'cliff'. To make things worse, you may find your robot a bit unreliable. A given command may not result in the robot moving exactly the same each time. This problem is called repeatability and reliability.

The following table summarizes some of the reasons why your robot may not respond as expected. Can you think of more? Can you think of ways of changing how you control your robot so it completes a mission efficiently, but not fail due to these issues?

Problem Uneven surface Description The uneven surface may cause a given command to not behave completely as expected. This is particularly a problem with the sharp turn commands (TURNL, TURNR) as they are more sensitive to the amount of friction on the rover wheels.
Problem Robot Hardware Description Your job on these missions is to develop software (app) and use that software to control your robot. Of course, a robot includes BOTH hardware and software. If you are driving the robot from home, you have no way to fix hardware issues or even the design of the robot and you must rely on the engineers whose job was robot design (or in this case - on Mr. Hogg). Note that this is exactly what happens for space missions where often an error in design or manufacturing must be cleverly handled (not fixed) through software
Problem Network Issues Description Just like NASA Engineers driving real robots on Mars, you may encounter issues with network connectivity. You are ACTUALLY driving robots over the internet, so its possible a command may get lost or your network may go down. Note that while this is possible - it is definitely NOT the most likely reason for issues. Network issues happen, but generally networks are fairly reliable. Note that the various networks used to control your robot include your own internet (if working from home), the code.org servers, the robot controller server, the school network, and then bluetooth connections to the individual robots. Lots of tech means lots of ways for problems to show up!

Related Pages on teacherhogg.info