RoboSumo Troubleshooting Clinic: 3:30pm – 5:00pm, Friday 24th Nov

To facilitate teams who are having problems with their final preparations for next week’s RoboSumo tournament, I (Ted) will be holding a “troubleshooting clinic” from 3:30pm to 5:00pm tomorrow (Friday 24th Nov) in room KEG-036. That’s the same room that Shannon, Catherine and I normally have our RoboSumo lab, down one of the small side corridors off the main ground floor corridor of the main building in Kevin St.

One or both of the practice RoboSumo arenas will be available in the room for testing. I will be there to assist teams who are having major problems getting their robot working, but depending on the level of demand I may or may not have time to help every team that attends.

Another class is scheduled in KEG-036 until 3:30pm, so please do not go into the room until that class is finished.

Advertisements
Posted in Uncategorized | Leave a comment

Day 11 Tutorial

Info on the bubble ranking system and also the assessment scheme for RoboSlam:

Instructions about what you need to do and submit on tournament day, just after the competition:

Posted in Uncategorized | Leave a comment

Day 10 Tutorial

Hand dryer coding example to help you program your robot. Similar rationale needed….

Info on the RoboSlam arena and set up:

Today’s main lecture on code for a hand dryer:

Posted in Uncategorized | Leave a comment

State Machine, version 2

This was the second example from today’s class. In this structure, each state is given its own while loop with the Arduino loop function. Once the flow of control enters one of these loops, it continues within that loop until the state changes.

Note that each state’s loop must include statements to update the relevant sensor variables.

//
// State machine example 2: loops inside loop
//

int state = 1;
unsigned long start_time;

void setup()
{
  // Green LEDs on D2, D3, D4
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  
  // Red LEDs on D5, D6, D7
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

  // White LED on D8
  pinMode(8, OUTPUT);
}

void loop()
{
  int colour;

  while (state == 1) // WAITING
  {
    // Read sensors
    colour = analogRead(0);
  
    // Actuators
    green(0);
    red(1);
    white(0);

    // Change state?
    if (colour > 200) gotoState(2);
  }
  
  while (state == 2) // FAN ON
  {
    // Read sensors
    colour = analogRead(0);
  
    // Actuators
    green(1);
    red(0);
    white(1);

    // Change state?
    if (colour < 200) gotoState(3);
  }
  
  while (state == 3) // FAN ON WITH TIMEOUT
  {
    // Read sensors
    colour = analogRead(0);
  
    // Actuators
    green(1);
    red(1);
    white(1);

    // Change state?
    if (colour > 200) gotoState(2);
    if (millis() - start_time > 2000) gotoState(1);
  }
}

void gotoState(int new_state)
{
  state = new_state;
  start_time = millis();
}

void green(int on_off)
{
  if (on_off == 0)
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }
  else
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
}

void red(int on_off)
{
  if (on_off == 0)
  {
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }
  else
  {
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
  }
}

void white(int on_off)
{
  if (on_off == 0)
  {
    digitalWrite(8, LOW);
  }
  else
  {
    digitalWrite(8, HIGH);
  }
}
Posted in Uncategorized | Leave a comment

State Machine, version 1

This was the first version of the state machine example we looked at in today’s lecture. This structure uses an extended if-else-if statement in the loop function to select the code for the current state each time the function repeats.

//
// State machine example 1: if-else-if inside loop
//

int state = 1;
unsigned long start_time;

void setup()
{
  // Green LEDs on D2, D3, D4
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  
  // Red LEDs on D5, D6, D7
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

  // White LED on D8
  pinMode(8, OUTPUT);
}

void loop()
{
  int colour;
  colour = analogRead(0);
  
  if (state == 1) // WAITING
  {
    // Actuators
    green(0);
    red(1);
    white(0);

    // Change state?
    if (colour > 200) gotoState(2);
  }
  else if (state == 2) // FAN ON
  {
    // Actuators
    green(1);
    red(0);
    white(1);

    // Change state?
    if (colour < 200) gotoState(3);
  }
  else if (state == 3) // FAN ON WITH TIMEOUT
  {
    // Actuators
    green(1);
    red(1);
    white(1);

    // Change state?
    if (colour > 200) gotoState(2);
    if (millis() - start_time > 2000) gotoState(1);
  }
}

void gotoState(int new_state)
{
  state = new_state;
  start_time = millis();
}

void green(int on_off)
{
  if (on_off == 0)
  {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  }
  else
  {
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
}

void red(int on_off)
{
  if (on_off == 0)
  {
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }
  else
  {
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
  }
}

void white(int on_off)
{
  if (on_off == 0)
  {
    digitalWrite(8, LOW);
  }
  else
  {
    digitalWrite(8, HIGH);
  }
}
Posted in Uncategorized | Leave a comment

Code is a mass noun

THIS IS A PUBLIC INFORMATION MESSAGE CONCERNING THE CORRECT USE OF THE WORD “CODE”.

I’ve read many RoboSumo blog posts over the last couple of days that use the word “code” incorrectly. When speaking about programming, “code” is generally used as a mass noun rather than a count noun. To see the difference between mass nouns and count nouns, let’s look at examples of each.

A count noun is a noun (the name of a person, place or thing) that you can put a number in front of to specify a certain quantity. Words like “a” or “an” might also precede a count noun if there’s only one object.

Count noun Example sentence
Apple I ate three apples.
Bicycle I bought a new bicycle yesterday.
Book I own hundreds of books.
Robot At the end of the semester each robot competes in a sumo tournament.

A mass noun is a noun that you don’t put a number in front of to specify a quantity.

Mass noun Something you can say Something you can’t say
Water I drank a glass of water. The jug contained a water.
Sunshine We enjoyed the sunshine yesterday. There were many sunshines yesterday.
Petrol I put some petrol in my car. There are few petrols in my car.
Code I wrote the code for my team’s robot. I downloaded a code onto my team’s robot.

Some important points:

  • In programming, the word “code” is used as a mass noun, which means you don’t say “a code” or “codes”.
  • In the English language, “code” can certainly be used as a count noun in other contexts. For example, spies might communicate using a secret code.
  • Frequently, I see “code” written where the word “program” would be more appropriate. For example, I might see “I wrote a code for my team’s robot” when it should say “I wrote a program for my team’s robot”.
  • The word “program” can be used as a count noun or as a verb, but never as a mass noun. For example, you can say “I wrote a program” or “I program the robot”, but not “I wrote a lot of program for our robot.”

Quiz

Finally, to test your understanding of the use of the word “code”, here are ten example sentences. Five are right and five are wrong. Can you tell which are which? (Scroll down for the answers.)

  1. I enjoy writing code for the robot.
  2. There were problems with the robot because of errors in the codes.
  3. Over the course of the semester, we wrote a lot of program.
  4. Whenever I rewire the circuit, I write a new code for the robot too.
  5. Poorly commented code is difficult to understand.
  6. I enjoyed programming the robot.
  7. In order to try out different strategies for our robot, we wrote three different codes.
  8. There are over 100 lines of code in our final program.
  9. We all worked together to write a new code for the robot.
  10. C code is terse.

Answers

1. I enjoy writing code for the robot. Correct …because “code” is used as a mass noun.
2. There were problems with the robot because of errors in the codes. Incorrect …because “codes” is used as a count noun (due to the “s” on the end).
3. Over the course of the semester, we wrote a lot of program. Incorrect …because “program” is used as a mass noun.
4. Whenever I rewire the circuit, I write a new code for the robot too. Incorrect …because “code” is used as a count noun – “a new code”.
5. Poorly commented code is difficult to understand. Correct …because “code” is used as a mass noun.
6. I enjoyed programming the robot. Correct …because “programming” is used as a verb.
7. In order to try out different strategies for our robot, we wrote three different codes. Incorrect …because “codes” is used as a count noun – “three different codes”.
8. There are over 100 lines of code in our final program. Correct …because “code” is used as a mass noun. Note that the number 100 applies to the word “lines” rather than “code”.
9. We all worked together to write a new code for the robot. Incorrect …because “code” is used as a count noun – “a new code”.
10. C code is terse. Correct …because “code” is used as a mass noun. Also, C code really can be terse!
Posted in Uncategorized | Leave a comment

Tips and Tutorial Day 8

Ted provided some helpful details during lab. I’m also providing video on the potentiometer as well as the video of Ted’s lecture.

Posted in Uncategorized | 1 Comment