Skip to content

GradBot Student Assignments

hannahbattreal edited this page Mar 5, 2023 · 32 revisions

Lab 1: Project Grad Robotics

Introduction

In this assignment, you will construct a function that will allow you to easily set your robot’s translational and rotational speeds. This function will be a handy function, and we will make use of it throughout future lab assignments.


Recall that the kinematic model of our robot consists of the following equations:

  1. x translational speed in m/s $$V_{x}= \frac{r}{2}(S_{left}+S_{right})$$

  1. yaw rotational speed in radians/s $$V_{yaw}= \frac{r}{L}(S_{left}-S_{right})$$

  1. motor speed in radians per second $$S_{m}= \frac{(Power⋅6.80)}{100}$$

  1. r=0.065 m, L=0.238 m

Procedure

  1. Working as a class, solve the equations so that given a desired Vx and Vyaw, we can compute a corresponding power setting for the motors.

  2. Type in the following skeleton of a function:

function setSpeed(vx, vyaw) {
    const r = 0.065;    //wheel radius
    const l = 0.238;    //axel length
    var sleft;          //left speed
    var sright;         //right speed
    var lpower;         //left power
    var rpower;         //right power
    
    // Compute lpower and rpower
    // YOUR CODE HERE

    left.setPower(lpower);
    right.setPower(rpower);
}
  1. Complete the function by implementing the math that you developed in step 1 in the part that says “YOUR CODE HERE”.

  2. Use your function to perform the following actions:

       a. Have your robot roll forward 1 meter.

       b. Have your robot roll in a circle that is 2 meters in diameter.

       c. Have your robot stop after completing the circle.

  1. Open notepad and create a file on your flash drive called “functions.txt”, copy the setSpeed function into this file so we can use it again later.

  2. Download your robot.txt file from the robot simulator and submit your file on https://tinyurl.com/robotics-turnin. For “assignment” put “Lab 1”. You may also want to save your robot on your flash drive for later.


Lab 2: Turtle Graphics

Introduction

In this lab, we will be implementing turtle graphics. Turtle graphics is a classic way to introduce programming and robotics. The idea is that your robot will use a marker to draw on the floor as it moves, and you will write programs to draw creative images.


Preparing the Robot

  1. Add a marker to your robot. The best place for the marker to be is in the center of your robot, so don’t move it once you add it. The final robot should look something like this:

image

  1. Rename the marker part to “marker” as shown above.

Coding the Turtle Functions

  1. Enter the functions as shown in the section titled "Turtle Functions" in Lab 2.
  2. Copy all your new functions into the “functions.txt” file on your flash drive. These may prove useful!
  3. Take a look at the function “toRadians”

Note: Turtle graphics uses degrees, not radians in their commands as this is easier to think of while drawing shapes.

  1. Take a look at the four basic turtle commands:

       a. forward(d)

       b. back(d)

       c. turnLeft(d)

       d. turnRight(d)

  1. Take a look at the reference for the marker. You can raise and lower the pen, and you can change its color.

Draw a Square

  1. Enter the following code below the line of slashes:
marker.penUp();
await forward(5);
await turnRight(90);
await forward(5);
await turnLeft(90);
marker.penDown();

for(var i=1; i <= 4; i = i+1) {
  await forward(2);
  await turnRight(90);
}
  1. Look at the “for” loop and note how it repeats its contents a fixed number of times.

  2. Alter the code so that your turtle makes left-hand turns instead of right-hand turns.

  3. Alter the code so that your turtle moves backward instead of forward.


Getting Creative and Submitting your Assignment

Write a program to draw your own interesting figures. This could be a scene of some kind, or a geometric shape. The key thing is that you experiment with what your robot can do! The best pictures will be awarded a certificate at the end of the summer institute.

To submit your assignment, email a screenshot of your picture and your robot.txt file to relowe@pstcc.edu. Make the message’s subject: “Your Name Lab 2”


Turtle Functions

function setSpeed(vx, vyaw) {
  const r = 0.065;    //wheel radius
  const l = 0.238;    //axle length
  var sleft;          //left speed
  var sright;         //right speed
  var lpower;         //left power
  var rpower;         //right power
  
  // Compute lpower and rpower
  sright = 1/r * vx - l/(2*r) * vyaw;
  sleft = 2/r * vx - sright;
  lpower = 100/6.8 * sleft;
  rpower = 100/6.8 * sright;

  left.setPower(lpower);
  right.setPower(rpower);
}

// Turtle Graphics
const tspeed=0.4;  //rolling speed
const trot=0.25;   //rotation speed

async function forward(d) 
{
  // calculate move time
  var t = d/tspeed;

  // move for the specified time
  setSpeed(tspeed, 0);
  await delay(t*1000);
  setSpeed(0, 0);
}

async function back(d) 
{
  // calculate move time
  var t = d/tspeed;
  
  // move for the specified time
  setSpeed(-tspeed, 0);
  await delay(t*1000);
  setSpeed(0, 0);
}

function toRadians(deg) 
{
  return Math.PI * deg / 180.0;
}

async function turnLeft(d) 
{
  // calculate move time
  var t = toRadians(d) / trot;
  
  // move for the specified time
  setSpeed(0, -trot);
  await delay(t*1000);
  setSpeed(0, 0);
}

async function turnRight(d)
{
  // calculate move time
  var t = toRadians(d) / trot;
  
  // move for the specified time
  setSpeed(0, trot);
  await delay(t*1000);
  setSpeed(0, 0);
}
//////////////////////////////////////

image


Lab 3: Braitenberg Vehicles

Introduction

In this lab, we will be replicating some of the famous “Braitenberg Vehicles” as described in Valentino Braitenberg’s classic book Vehicles: Experiments in Synthetic Psychology (MIT Press 1984). This lab is an exploration of simple stimulus and response control, and we should see that intelligent behavior can emerge from rather simple control schemes.

Because this lab is mainly about observation, you will need to create a word document. In each problem, add your answers to the document. This is the document you will submit at the end of the assignment.


Getting Started

The first thing to do is connect to the robot simulator at: https://relowe.github.io/gradbot/

Note: The robot simulator may have changed since the last time you opened it, so please be sure to refresh the page by holding shift while you click reload. This will make sure your locally cached version of the program is up to date.


Vehicle 1-Getting Started

The first vehicle is called “Getting Around.” Braitenberg’s diagram of this vehicle is:

image

The idea is we have a single light sensor connected to a single motor. Of course, we can’t have just one motor in our simulator, but we can have one light sensor and connect it to both motors!

Construction of Vehicle 1

  1. Add a single light sensor to your robot.
  2. Change the name of the light sensor to “light”

Lab 4: Obstacle Avoidance

Introduction

In this lab, we will continue to explore sensor based control. This lab centers around using our range finder part. This part is an analog to the HC-SR04 Ultrasonic Rangefinder. This part is very common in hobby robotics as it is a relatively inexpensive part and yet it gives a very precise range to the nearest target. The two parts of the rangefinder are a speaker and a microphone. The speaker emits a burst of ultrasonic energy, which is sound that is inaudible to humans. The microphone listens for the echo of the soundwave returning to the rangefinder, and then the computer controlling the rangefinder measures the time it takes to receive the echo. By dividing the time of flight by the speed of sound, the computer can tell how far away the nearest object is. Our simulator can mimic this part and give you experience programming for it.


Preparing Your Robot

The first step in this lab is to prepare your robot by adding the rangefinder part. The robot should appear as shown. Name the rangefinder "range" and place it near the front of the robot. The code which triggers the ultrasound pulses happens automatically in our simulation. All you need to do to access the distance is look at the value in:

       range.distance

This is updated by the system approximately ten times per second. The number you will find in this variable is the number of meters between the sensor and the nearest object. This is why it is important that you put your sensor toward the front of the robot.


Preparing the Simulation Environment

In the simulate tab, add a wall object and move it into the path of your robot. The end result will look like the following:

Lab 5: Battle Bots


Turtle Graphics Examples

Clone this wiki locally