Robot-course

View project on GitHub

Intro

This is a short course about robotics, designed to have in about 10 sessions an outcome of team members building robots and experimenting with different setups.

It has been used both in at least four countries in several iterations. It is, of course, far from perfect. But it is something, at least, that tries to give a comprehensive view to beginners about what robots really are and how to create them.

Please help to improve it and it's code by placing an issue on the master branch. You are also welcome to ask for a Pull Request @todocono.

Content

  1. Team Building - Activity
  2. Robotics - Intro
  3. Mechanics Basics
  4. Electronics Basics
  5. Maze Solving - Activity
  6. Software Basics I
  7. Software Basics II
  8. Analog Sensors
  9. Infrared (optional)
  10. Chain Reaction - Activity
  11. Learning Outcomes
  12. Authors & Contributors

0. Instructions for the instructions

This set of instructions go hand in hand with the set of code examples hosted at http://github.com/todocono/robot-course.

The mechanical kit can be purchased at http://multiplo.org and the electronics are based on Arduino UNO & L298N.

It is a good strategy to establish rules about how to use the materials at the beginning. For example, the instructor will only have one rule to ask for the attention of the students. Stating a clear set of expectations always help to focus the group.

1. Team Building - Activity

Any activity would do it. Here is a suggestion of one that it is my favorite.

  1. Receive instructions.
  2. Team up, groups of at least 3 people.
  3. Gather the materials. (marshmallow, 20 spaghetti, 1m of tape, 1m of thread)
  4. Build for 18 minutes. The tallest tower that stands for 1 minute wins.
  5. Watch the video https://www.youtube.com/watch?v=1p5sBzMtB3Q
  6. Answer:
    -  how many people did he test?
    -  where did he test it?
    -  where were the best engineers?
    -  who had the worst performance?
    -  how did kindergarten kids perform?
    -  where do these answers leave us a team?

Notes:

  • There is a video that complements with graphs of why is this happening: https://www.youtube.com/watch?v=vi9CILGF2YQ

  • Detailed instructions are hosted here. You will need them if you are an instructor and this is the first time you run it.

2. Robotics

2.1 Introduction

Provide answers to:

  • when was the first time the word "Robot" was used?
  • what were the first robots in history?
  • what different category of robots do you know?
  • which parts does a robot must have?

2.2 Microcontrollers - Firmware & Upload

Connect the USB cable. Use the Arduino Software. Select the port and the board type under Tools menu.

image

Note: in case you are using W###340 chipset, use the following link for the drivers

2.3 Microcontrollers - Digital Outputs

Use the code example Blink. Press the Upload button. Change the 1000 number into other numbers and answer:

  • what is 1000?
  • how fast our eyes can see? can you test it with an LED?
  • how fast can a microcontroller update an output?

2.4 Microcontrollers - Breadboard & buzzer

Use the code example Tones. Connect the arduino output to the pin 8 to the buzzer. Buzzer to GND:

  • does the buzzer work in any way we connect it?
  • what does GND stand for?
  • how are the lines of the breadboard connected?

image

#define NOTE_C4  262
#define NOTE_D4  294
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_G4  392
#define NOTE_A4  440
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_D5  587

void setup() {
    tone(8, NOTE_C4, 300);
    delay(200);
    tone(8, NOTE_C5, 500);
    delay(200);
    tone(8, NOTE_C4, 300);
    delay(200);
    noTone(8);
  }
}

void loop() {
  // no need to repeat the melody.
}

2.5 Control Structures: while & for

Use the following information:

https://www.arduino.cc/en/Reference/For https://www.arduino.cc/en/Reference/while

Answer:

  • what is the difference between setup() and loop() ?
  • what happens if the buzzer instructions go to loop() ?
  • how to use for() inside of the setup()?
  • how to use for() inside of the loop()?

2.6 Serial Communication

We will use the Serial Terminal to read information from the microcontroller. Use the following tool to open it:

image

Use this example and mix it with the previous one to show different outputs: https://www.arduino.cc/en/Tutorial/ASCIITable

2.7 Control Structures: variables

Use the following information: https://www.arduino.cc/en/Reference/VariableDeclaration

And answer:

  • how to declare a variable ?
  • how to use the variable that drives for() ?
  • can we also use while() for the same ?

3. Mechanics Basics

3.0 Introduction

Read the provided material. Use online resources to answer:

  • what does a "stable structure" mean?
  • what is "the Center of Mass" or "Center of Gravity"?
  • what is a differential robot?

3.1 Materials, fasteners & tools

The instructor will provide examples of:

  • how NOT to use tools
  • what is the proper way to measure tightness with a bolt & nut
  • the use of washers
  • the use of grower washer
  • when to use of double nuts
  • how to lock rivets properly

3.2 Iteration by prototyping and testing

3.3 Assembly

Use the instructions to create the first basic structure. Build on top of that your unique model.

Make sure that, USB motor cables and power can be connected easily. Make the breadboard and the Arduino pins accessible.

4. Electronics Basics

4.1.1 Introduction

Instructor will help to identify the following parts:

  • microcontroller
  • USB chip
  • motor driver
  • motors
  • batteries

4.1.2 Driving motors

image

4.2 Motor driver L298N & batteries

Without disconnecting the buzzer, we will connect the motor driver and the batteries.

image

Note1: detailed datasheet of the L298N motor driver is here

Note2: if the battery polarity is reversed, both the driver and the Arduino will become useless. It is recommended for the instructor to check one by one before switiching ON.

4.2 Code example with digitalWrite

Example:

int EN_M1 = 9;     //M1 Speed Control
int EN_M2 = 3;     //M2 Speed Control
int directionPin_M1A = 6;     //M1 Direction Control
int directionPin_M1B = 7;     //M1 Direction Control
int directionPin_M2A = 4;     //M1 Direction Control
int directionPin_M2B = 5;     //M1 Direction Control

void setup() {                               // Serial initialization
 pinMode(directionPin_M1A, OUTPUT);
 pinMode(directionPin_M1B, OUTPUT);
 pinMode(directionPin_M2A, OUTPUT);
 pinMode(directionPin_M2B, OUTPUT);
 pinMode(EN_M1, OUTPUT);
pinMode(EN_M2, OUTPUT);

 digitalWrite (EN_M2, HIGH);             //no PWM Speed Control yet
 digitalWrite(directionPin_M1A, LOW);
 digitalWrite(directionPin_M1B, HIGH);
 digitalWrite (EN_M1, HIGH);             //no PWM Speed Control yet
 digitalWrite(directionPin_M2A, LOW);
 digitalWrite(directionPin_M2B, HIGH);
 delay(1000);                                  //WAITS FOR 1 SECOND
 digitalWrite (EN_M1, LOW);              //stops the motors
 digitalWrite (EN_M2, LOW);              //
 delay(1000);                                  //WAITS FOR 1 SECOND
 digitalWrite (EN_M2, HIGH);             //no PWM Speed Control yet
 digitalWrite(directionPin_M1A, HIGH);
 digitalWrite(directionPin_M1B, LOW);
 digitalWrite (EN_M1, HIGH);             //no PWM Speed Control yet
 digitalWrite(directionPin_M2A, HIGH);
 digitalWrite(directionPin_M2B, LOW);
 delay(2000);                                  //WAITS FOR 2 SECONDS
}

void loop() {
  //do nothing
}

4.3 Pulse Width Modulation

Read the materials provided and answer:

  • What is the difference between a digital and an analog signal?
  • Which pins can give a P.W.M. output ?
  • How does the A.D.C. module work?
  • How many bits is the maximum output?

image

4.4 Speed control with analogWrite

Read the reference of AnalogWrite

Use this new information to transform your software into a speed controlled one. Make the robot go in a circle.

5. Maze Solving - Activity

5.1 Rules setting

Each team will have a starting point and they need to navigate through fixed obstacles.

5.2 Activity Objectives

All participants will practice sequential programming, becoming more familiar with the challenges of connecting their planned software with the real limitations when testing it.

6. Software Basics I

6.1 Intro

Watch the following video. Darpa challenge 2015: video

Debate:

  • which is the most difficult task?
  • what do the algorithms need to consider?
  • Why is called the "Darpa Challenge"?

6.2 Digital Sensors: Ultrasound - Hardware

As an example of a digital sensor, we have the ultrasonic module HC-SR04 datasheet

Use the following diagram to wire it to your board: image

6.3 Digital Sensors: Ultrasound - Software

Given the following function, read the value in centimeters. :

int trigPin = 11;
int echoPin = 12;
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
// the loop function runs over and over again forever
void loop() {
  int sensorValue = ultraSound();
  Serial.println(sensorValue);
  delay(500);
}
//this is a function that gives back the distance
int ultraSound( void ) {
  long duration;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  long distance = (duration / 2) / 29.1;
  return (int)distance;
}

7. Software Basics II

7.1 IF conditional

Use the reference to understand the IF sentence.

(Reference)[https://www.arduino.cc/en/Reference/If]

if (sensorValue > 350)
{
  // do something here like a tone or a turn a motor ON
}

7.2 Automatic Behaviors: Navigation

int EN_M1 = 9;     //M1 Speed Control
int EN_M2 = 3;     //M2 Speed Control
int directionPin_M1A = 6;     //M1 Direction Control
int directionPin_M1B = 7;     //M1 Direction Control
int directionPin_M2A = 4;     //M1 Direction Control
int directionPin_M2B = 5;     //M1 Direction Control

int trigPin = 11;
int echoPin = 12;

int ultraSound( void ) {
  long duration;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  long distance = (duration / 2) / 29.1;
  return (int)distance;
}

void setup() {                               // Serial initialization
  pinMode(directionPin_M1A, OUTPUT);
  pinMode(directionPin_M1B, OUTPUT);
  pinMode(directionPin_M2A, OUTPUT);
  pinMode(directionPin_M2B, OUTPUT);
  pinMode(EN_M1, OUTPUT);
  pinMode(EN_M2, OUTPUT);
  digitalWrite (EN_M1, LOW);              //stops the motors
  digitalWrite (EN_M2, LOW);
  digitalWrite(directionPin_M1A, LOW);  //SETS DIRECTION FORWARD
  digitalWrite(directionPin_M1B, HIGH);
  digitalWrite(directionPin_M2A, LOW);
  digitalWrite(directionPin_M2B, HIGH);
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);               //INITIATES THE ULTRASOUND PINS
  pinMode(echoPin, INPUT);

}

void loop() {
  //do nothing
  int sensorValue1 = analogRead(A0);
  int sensorValue2 = analogRead(A1);
  int distance = ultraSound();
  Serial.println(distance);
  if (distance > 30) {    //moves
    analogWrite (EN_M1, 200);             //  Speed Control
    analogWrite (EN_M2, 200);             //  Speed Control
    Serial.println("going fast");
  }
  else if (distance > 10) {  //slows down
    analogWrite (EN_M1, 100);             //  Speed Control
    analogWrite (EN_M2, 100);             //  Speed Control
    Serial.println("going slow");
  }
  else if (distance > 5) {  //turns
    digitalWrite(directionPin_M1A, HIGH);   //SETS DIRECTION BACKWARDS
    digitalWrite(directionPin_M1B, LOW);
    digitalWrite(directionPin_M2A, HIGH);
    digitalWrite(directionPin_M2B, LOW);

    analogWrite (EN_M1, 200);             //  Speed Control
    analogWrite (EN_M2, 0);             //  Speed Control

    delay(random(200, 1000));           //ADDS A RANDOM VALUE

    digitalWrite(directionPin_M1A, LOW); //SETS DIRECTION FORWARD
    digitalWrite(directionPin_M1B, HIGH);
    digitalWrite(directionPin_M2A, LOW);
    digitalWrite(directionPin_M2B, HIGH);

    analogWrite (EN_M1, 200);             //  Speed Control
    analogWrite (EN_M2, 0);             //  Speed Control
    delay(random(200, 1000));

    Serial.println("turning");
  }
  else {
    analogWrite (EN_M1, 0);             //  Speed Control
    analogWrite (EN_M2, 0);             //  Speed Control
    Serial.println("stopping");
  }
  delay(50);                                  //WAIT A BIT TO AVOID OVERFLOW OF SERIAL
}

8. Analog Sensors

8.1 Analog Sensor: 2 resistors

Use the Serial terminal from Arduino.

Connect two resistors and read the input coming from: - 5V - GND - the middle point from both resistors

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
   int sensorValue = analogRead(A0);
   Serial.println(sensorValue);
   delay(500);
}

8.2 Analog Sensors: Light Detection

Use this circuit: image

With this software: https://www.arduino.cc/en/Tutorial/AnalogInput

Your goal is to create a light sensing software.

8.3 Automatic Behavior: Light Navigation with two light sensors

Use the following circuit: image

Try the following software:

int EN_M1 = 9;     //M1 Speed Control
int EN_M2 = 3;     //M2 Speed Control
int directionPin_M1A = 6;     //M1 Direction Control
int directionPin_M1B = 7;     //M1 Direction Control
int directionPin_M2A = 4;     //M1 Direction Control
int directionPin_M2B = 5;     //M1 Direction Control

void setup() {                               // Serial initialization
  pinMode(directionPin_M1A, OUTPUT);
  pinMode(directionPin_M1B, OUTPUT);
  pinMode(directionPin_M2A, OUTPUT);
  pinMode(directionPin_M2B, OUTPUT);
  pinMode(EN_M1, OUTPUT);
  pinMode(EN_M2, OUTPUT);
  digitalWrite (EN_M1, LOW);              //stops the motors
  digitalWrite (EN_M2, LOW);
  digitalWrite(directionPin_M1A, LOW);
  digitalWrite(directionPin_M1B, HIGH);
  digitalWrite(directionPin_M2A, LOW);
  digitalWrite(directionPin_M2B, HIGH);
}

void loop() {
  //do nothing
  int sensorValue1 = analogRead(A0);
  int sensorValue2 = analogRead(A1);

  if (sensorValue1 < 450) {
    digitalWrite (EN_M1, HIGH);             //no PWM Speed Control yet
  }
  else
  {
    digitalWrite (EN_M1, LOW);             //no PWM Speed Control yet
  }
  if (sensorValue2 < 450) {
    digitalWrite (EN_M2, HIGH);             //no PWM Speed Control yet
  }
  else
  {
    digitalWrite (EN_M2, LOW);             //no PWM Speed Control yet
  }
  delay(500);                              //fixes the update rate
}

9 Infrared (optional)

9.1 Software Libraries

Library IRremote installation

9.1 Hardware

image

9.1 Software

//code example goes here

10. Chain Reaction - Activity

10.1 Rules setting

Each robot/machine will receive one input. Each one should have the ability to have one physical movement as an output. All machines should be connected together. No movement can last less than two seconds. No robot can directly touch other robot.

10.2 Activity Objectives

Through this physical challenge, all knowledge is applied by the participants. The collaboration between the teams and the curiosity of how

11. What we can learn from "making" a robot ...

The expected learning outcomes can be stated as some of the following. What we have to add on top of those is that the technological fluency achieved has no limits.

  • Understand fundamentals of computer programming and interactivity
  • Apply and implement coding techniques to solve problems
  • Integrate and associate the techniques used both in software and hardware development
  • Build a mechanical structure and do the electrical connections to make it fully autonomous.
  • Program a microcontroller by writing programs that display messages, remember values, make computations with math operators, and interact with external circuits.
  • Build and adjust an autonomous control system that monitors sensor input and responds with motion output.
  • Identify and apply additional STEM concepts including physics (the light spectrum, frequency, sound, motion) and engineering skills (mechanics, troubleshooting, problem­solving, subsystem testing, and setpoints).

12 Authors and Contributors

You can find the author, Rudi both on wechat, twitter and Github as @todocono .Feel free to open an issue or start a wiki for it and to shoot for a Pull Request if you want to improve the code or the content.

Back in 2012, Julian da Silva @miniBloq and Monica Paves @monicapaves served as an inspiration for this course.

Additional resources were used from numerous graphics and examples, specially from Arduino website: https://www.arduino.cc/en/Tutorial/BuiltInExamples https://www.arduino.cc/en/Reference/HomePage